Skip to content

Instantly share code, notes, and snippets.

@hoorayimhelping
Forked from anonymous/Game1
Last active September 23, 2015 13:15
Show Gist options
  • Save hoorayimhelping/ed2d012cf3ea620fb75c to your computer and use it in GitHub Desktop.
Save hoorayimhelping/ed2d012cf3ea620fb75c to your computer and use it in GitHub Desktop.
PS.keyDown = function (key, shift, ctrl, options) {
"use strict";
// p was pressed - pause the game
if (key === 112) {
GAME.paused = !GAME.paused // flip the state, if it was paused, it's unpaused after this
PS.debug("Game is now paused: " + GAME.paused);
// not sure how PS works. I suspect you don't want to stop the timer here, but instead want to do that in code that is higher up
// i would iamgine the game controller would have access to the timer properties
}
// r was pressed, restart the game
if (key === 114) {
GAME.ending = true;
// again, I prefer not to call game-engine related functions down here. let the thing controlling the game know that the user
// wants to restart the game, and then let it figure out how to do that
}
}
// then, elswhere, in your rendering code:
// I don't know the interface, this is just a pseudocode-like example
GAME.renderingCode = function() {
// the order you hit these conditionals about game state matters - keep that in mind
if (GAME.restarting) {
GameSetup();
return;
}
if (GAME.paused) {
PS.timerStop(sTimerID);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment