Game Development Reference
In-Depth Information
Any given Sprite is measured from the centerpoint of its Stage
Rectangle to determine the grid space in which is resides.
As I mentioned earlier, enemies are capable of moving
between grid squares, so they need the ability to update the Grid-
Reference objects to which they are linked. This is where the
updateGridReference method comes in handy
it handles remov-
ing an enemy from one reference and into another with a single
command.
Thefinal,andperhapsmostimportant,helpermethodis get-
CollisionReference . This method assembles an entirely new GridRe-
ference object concatenated from the eight grid squares surrounding
aSprite,plusthesquareinwhichtheSpritecurrentlyexists.Thisis
important because it ensures that we only test for collisions in
nearby grid references. There is no need to test the player against
another Sprite on the other side of the level. This ensures that there
will be no more and no less than nine checks per cycle, which
means that the level size can scale almost indefinitely without a
performance drop. This method will be called at the onset of every
collision detection check.
//BEGIN INPUT MANAGEMENT
protected function onKeyDown(e:KeyboardEvent):void {
switch (e.keyCode) {
case _config.keyLeft: _keyLeftPressed = true;
break;
case _config.keyRight: _keyRightPressed = true;
break;
case _config.keyJump: playerJump();
break;
case _config.keyUse: checkPortals();
break;
}
}
protected function onKeyUp(e:KeyboardEvent):void {
switch (e.keyCode) {
case _config.keyLeft: _keyLeftPressed = false;
break;
case _config.keyRight: _keyRightPressed = false;
break;
}
}
//END INPUT MANAGEMENT
The key input for this platformer is very simple. The left and
right keys (regardless of the actual key they
re assigned to in the
Config class) act as toggles, while the jump and use keys (Up and
Down arrows, by default), perform one-time actions.
'
Search Nedrilad ::




Custom Search