Game Development Reference
In-Depth Information
thekey combination entered.
return false;
}
At every tick of the main game timer, which we can make faster or slower based on
the difficulty that the player has selected, we call our main game loop, which per-
forms some basic tasks. First we move each player, then check if any of them has
reached the end of their track. This is done by calling each player's isFinished()
function, defined by the Player class. If that is the case, then we know that the
game is over. If that is so, we unregister the keyboard event we had bound to the
body element, so that we no longer inspect any keyboard input from the user. After
we've determined that the game is over, we determine if the user has actually won
or lost the game. If they have won, we record their victory. If they have lost, we tell
them so, and allow them to play a new game. If the game is not yet over, we simply
wait for the game loop to run again.
function tick() {
hero.move();
enemy.move();
if (isGameOver()) {
document.body.removeEventListener("keydown",
handleKeyPress);
if (hero.isFinished()) {
gamesWon++;
showWinPanel();
} else if (enemy.isFinished()) {
showLosePanel();
}
} else {
setTimeout(tick, tickPeriod);
}
}
Search WWH ::




Custom Search