Game Development Reference
In-Depth Information
In this case, when the ball is within 10 pixels of the endpoint, it is
considered a win and endLevel is called, which we looked pre-
viously. In just under 200 lines of code, we
ve laid out the core
functionality behind this game. While we
re far from done, most of
the heavy lifting is out of the way.
This class is never meant to be used directly. It is the base for every
level that will be created in the IDE. It establishes all of the necessary
criteria for a level and provides the ability to validate itself. As I men-
tioned before, this differs from the other components of the engine in
that all of the levels inherit from it instead of implementing an inter-
face. This is because we need more rigidity in how the levels are built,
whereas we need not be so particular about the ball, walls, or hazards.
public class LabyrinthLevel extends Sprite
static public const ERROR_NO_START_POINT:String =
Invalid: No start point specified - place a DisplayObject
named \ " startPointClip\ " in the level. " ;
static public const ERROR_NO_END_POINT:String = " Level
Invalid: No end point specified - place a DisplayObject
named \ " endPointClip\ " in the level. " ;
static public const ERROR_NO_WALLS:String = " Level Invalid:
Level requires at least one DisplayObject that implements
IWall. " ;
private var _hazards:Vector. < IHazard > ;
private var _endPoint:Point;
private var _startPoint:Point;
private var _walls:Vector. < IWall > ;
A level in Marble Runner is defined as a set of walls and
hazards, as well as a starting point and endpoint. When the level
validates itself, it may throw errors stating which required compo-
nents are missing. There are constants provided for missing starting
and ending points, as well as when the level cannot find any walls.
public function LabyrinthLevel()
_hazards = new Vector.
_walls = new Vector.
for (var i:int = 0; i < numChildren; i++)
var child:DisplayObject = getChildAt(i);
if (child is IHazard)
Search Nedrilad ::

Custom Search