Placing fruits

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:

  1. A fruit cannot be placed in a tile occupied by the snake
  2. 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; ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.