Placing walls

To make the game a little more challenging, we need to add some walls as the snake grows.

The idea: Every time a fruit is placed, a wall is added to the stage too, with the same criteria: in an empty cell, and never within a given distance. I'll refer walls as "obstacles" since they look more like square blocks rather than walls.

The development: There's not that much to explain here, as it's exactly the same concept you used to place fruits. Anyway, let's add a new class level variable called obstacle of obstacle_mc type.

private const FIELD_WIDTH:uint=16; private const FIELD_HEIGHT:uint=12; private const TILE_SIZE:uint=40; private var the_snake:the_snake_mc; private var snakeDirection:uint; private var snakeContainer:Sprite= new ...

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.