Letting the snake move

Snake is a simple yet fast paced game because you can't stop the snake. It will always be moving in its direction.

The idea: Make the snake move by a tile in the current direction at every frame.

The development: To move the snake at every frame, we need to import the class to handle ENTER_FRAME event. Add it to Main.as:

import flash.display.Sprite;
import flash.events.Event;

And in Main constructor, we need to add the listener:

public function Main() {
addChild(bg);
placeSnake();
addEventListener(Event.ENTER_FRAME,onEnterFr);
}

Now I would like to introduce four Boolean functions we are going to create, called is_up, is_down, is_left, and is_right.

These functions, given two pieces of the snake called from and to passed ...

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.