Game Development Reference
In-Depth Information
protected function createPortals():void {
_portals = new Array();
var portals:XMLList = _currentLevel.portals.children();
for (var i:int = 0; i < portals.length(); i++) {
var portalClass:Class = getAssetClass(portals[i].
@spriteClass);
var portalSprite:IPortal = new portalClass();
portalSprite.x = Number(portals[i].@x) * Number
(_currentLevel.@gridSquareSize);
portalSprite.y = Number(portals[i].@y) * Number
(_currentLevel.@gridSquareSize);
portalSprite.destination = portals[i].
@destination;
for each (var requirement:XML in portals[i].
requirement) {
portalSprite.require,ments.push(new
PortalRequirement(requirement.@type,
requirement.@name));
}
_portals.push(portalSprite);
var gridReference:GridReference = _collisionGrid.
getGridReference(Number(portals[i].@x),
Number(portals[i].@y));
gridReference.portals.push(portalSprite);
addChild(portalSprite as DisplayObject);
}
}
//END LEVEL CREATION
ve bolded the
most significant areas. Each of the types of Sprites adds itself to the
appropriate GridReference object, and each enemy Sprite stores a
reference to its respective GridReference. In createPortals , each por-
tal defines a new PortalRequirement object for every requirement
necessary to use that portal. Every type of Sprite is added both to
an engine-level list, as well as a grid reference, and then added to
the Stage at its specified position from the XML.
The level has now been created and is in the display list. From this
point forward, startGame and stopGame can be called on the engine,
and the player Sprite is ready to receive input. However, we
Because there is so much code to digest here, I
'
'
re going
to jump slightly out of order in the file for a moment to outline the
helper methods before we dive into the main game loop. Then, we
'
ll
examine the keyboard input handlers the game uses as well.
//BEGIN UTILITY
protected function getGridPosition(sprite:ISprite):Point {
var spriteRect:Rectangle = sprite.getRect(this);
Search Nedrilad ::




Custom Search