ABSTRACT

Like most programming environments, Director can provide you with the programming tools to make your code well structured. Unfortunately, this flexibility can also be used to create very poorly structured code. Game development can be made very hard or very easy. Careful planning and good structure makes development so much easier. In this chapter we look at how to take an idea for a game, turn it into a well-planned project and then develop the code.We will look at using custom functions to make sure that you only have to change your code in one place to have a global effect. We look at using functions to change the value of certain variables.We look at the difference between local and global variables.But most importantly we will look at how to embed complexity into your behaviors so that they can look after themselves and better still you will have code that you can reuse.

From an idea to a plan The starting point for all games is an idea.Your idea is the basis for all subsequent development. Because we are concerned with games let us consider a game that everyone will be familiar with – ‘Tetris’. In Tetris we have a board layout that is based on square cells.Each cell can either have a tile in it or not. At its simplest that is the game. But the game play is another matter.The game revolves around a block of four tiles in a line, a square block, a T-shape or an L-shape dropping at a consistent rate from the top. When any one of the four tiles that make up the set of tiles hits the base of the play area the movement of that set of tiles stops and the set of tiles remains on the screen.At this point we need to create a new block of tiles and start this dropping. This new set of tiles and all subsequent ones stop when either the base is reached by any one of the tiles or any one of the tiles hits a parked tile.