The snake itself

placeSnake function has to place the snake in a random place of the field, facing a random direction. Add this function to Main.as file:

private function placeSnake():void { addChild(snakeContainer); var col:uint=Math.floor(Math.random()*(FIELD_WIDTH-10))+5; var row:uint=Math.floor(Math.random()*(FIELD_HEIGHT-10))+5; snakeDirection=Math.floor(Math.random()*4); the_snake=new the_snake_mc(col*TILE_SIZE,row*TILE_SIZE,snakeDirection+1); snakeContainer.addChild(the_snake); switch (snakeDirection) { case 0 : // facing left trace("left"); the_snake = new the_snake_mc((col+1)*TILE_SIZE,row*TILE_SIZE,6); snakeContainer.addChild(the_snake); the_snake = new the_snake_mc((col+2)*TILE_SIZE,row*TILE_SIZE,6); snakeContainer.addChild(the_snake); ...

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.