Placing fruits is the hardest part of the making of this game, because you will learn some new concepts and techniques.
The idea: Placing a fruit in a random spot is not just a matter of picking a couple of random coordinates and adding the fruit.
Fruits will be placed on the game according to these two principles:
- A fruit cannot be placed in a tile occupied by the snake
- A fruit cannot be placed too close to the snake's head. It would be too easy, both playing and programming the game
The development: Let's divide things into steps: first, we have to define the variable to handle
fruit_mc Movie Clip. Add this new class level variable:
private const FIELD_WIDTH:uint=16; private const FIELD_HEIGHT:uint=12; private const TILE_SIZE:uint=40; ...