Game Development Reference
In-Depth Information
As you can see, we only want to run the checkInput function when playerStarted is set to true .
This way, we don't evaluate keypresses for the player during level transitions and other time
when we don't want the player to move on the screen.
Updating the checkInput function
The checkInput function is the heart of the code that sets, evaluates, and puts into motion
changes to the rotation and currentDirection attributes of the player. Here is the code listing.
We will point out the major concepts after you have examined (and hopefully typed in) all of this
code. Note that some of the code is commented out; you should add these lines but leave them
commented out for now. This code will be implemented later to play sounds and fire player
missiles. Some trace statements are commented out also. They can be useful for debugging. We
will be removing the comment designations as we progress through the iterations.
private function checkInput():void {
//var playSound:Boolean = false;
var lastDirection:int = player.currentDirection;
if (keyPressList[38] && player.inTunnel==false) {
if (checkTile(MOVE_UP, player )) {
if (player.currentDirection == MOVE_UP || player.currentDirection
== MOVE_DOWN || player.currentDirection == MOVE_STOP ) {
switchMovement(MOVE_UP, player );
//playSound = true;
}else if (checkCenterTile( player)) {
switchMovement(MOVE_UP, player );
//playSound = true;
}
}else{
//trace("can't move up");
}
}
if (keyPressList[40] && player.inTunnel == false) {
if (checkTile(MOVE_DOWN, player )) {
if (player.currentDirection == MOVE_DOWN || player.currentDirection
== MOVE_UP || player.currentDirection == MOVE_STOP) {
switchMovement(MOVE_DOWN, player );
//playSound = true;
}else if (checkCenterTile(player)) {
switchMovement(MOVE_DOWN, player );
//playSound = true;
}
}else {
//trace("can't move down");
}
}
Search WWH ::




Custom Search