Start implementing a pause screen

This commit is contained in:
Aaron Mueller 2013-04-03 21:51:11 +02:00
parent 717b06e612
commit 187dde1b50
2 changed files with 31 additions and 6 deletions

View file

@ -16,19 +16,28 @@
RunningGame = ig.Game.extend({ RunningGame = ig.Game.extend({
font: new ig.Font( 'media/04b03.font.png' ), font: new ig.Font( 'media/04b03.font.png' ),
statsBackground: new ig.Image('media/stats_screen.png'), statsBackground: new ig.Image('media/stats_screen.png'),
pauseDialog: new ig.Image('media/pause_dialog.png'),
score: {'ai': 1, 'human': 1}, score: {'ai': 1, 'human': 1},
showStats: false, showStats: false,
pause: false,
init: function() { init: function() {
ig.input.bind(ig.KEY.ESC, 'mainmenu'); ig.input.unbindAll();
ig.input.bind(ig.KEY.ESC, 'escape');
ig.input.bind(ig.KEY.ENTER, 'enter');
ig.input.bind(ig.KEY.UP_ARROW, 'up'); ig.input.bind(ig.KEY.UP_ARROW, 'up');
ig.input.bind(ig.KEY.DOWN_ARROW, 'down'); ig.input.bind(ig.KEY.DOWN_ARROW, 'down');
ig.input.bind(ig.KEY.T, 'force-top'); ig.input.bind(ig.KEY.T, 'force-top');
ig.input.bind(ig.KEY.B, 'force-bottom'); ig.input.bind(ig.KEY.B, 'force-bottom');
// vim goodness // vim goodness
ig.input.bind(ig.KEY.K, 'up'); ig.input.bind(ig.KEY.K, 'up');
ig.input.bind(ig.KEY.J, 'down'); ig.input.bind(ig.KEY.J, 'down');
// Gamer style
ig.input.bind(ig.KEY.W, 'up');
ig.input.bind(ig.KEY.S, 'down');
ig.input.bind(ig.KEY.SPACE, 'endgame'); ig.input.bind(ig.KEY.SPACE, 'endgame');
// Load the level // Load the level
@ -46,18 +55,30 @@
return; return;
} }
// User is in the pause menu
// TODO: Hier gehts weiter .... irgend was stimmt mit dem input state nicht ...
if (this.pause) {
if (ig.input.state('enter')) {
ig.system.setGame(StartScreen);
}
if (ig.input.state('escape')) {
this.pause = false;
}
}
// One player has won the game // One player has won the game
if (this.score.ai == 0 || this.score.human == 0) { if (this.score.ai == 0 || this.score.human == 0) {
this.showStats = true; this.showStats = true;
} }
// The User want back to the main menu inside a running game // The User want back to the main menu inside a running game
if (ig.input.pressed('mainmenu')) { if (ig.input.pressed('escape')) {
ig.system.setGame(StartScreen); this.pause = true;
} }
// The game is running // The game is running
if (!this.showStats) { if (!this.showStats && !this.pause) {
this.parent(); // Update entries and background this.parent(); // Update entries and background
} }
}, },
@ -72,6 +93,10 @@
this.font.draw('You ' + (this.score.ai == 0 ? 'won!' : 'loose!'), 200, 50, ig.Font.ALIGN.CENTER); this.font.draw('You ' + (this.score.ai == 0 ? 'won!' : 'loose!'), 200, 50, ig.Font.ALIGN.CENTER);
this.font.draw('Press [SPACE] to move to the main menu', 200, 100, ig.Font.ALIGN.CENTER); this.font.draw('Press [SPACE] to move to the main menu', 200, 100, ig.Font.ALIGN.CENTER);
} }
if (this.pause) {
this.pauseDialog.draw(150, 100);
}
} }
}); });
@ -79,12 +104,12 @@
background: new ig.Image('media/main_screen.png'), background: new ig.Image('media/main_screen.png'),
init: function() { init: function() {
ig.input.bind(ig.KEY.ENTER, 'start'); ig.input.bind(ig.KEY.ENTER, 'start-game');
//ig.input.bind(ig.KEY.SPACE, 'start'); // FIXME: collides with the stats screen //ig.input.bind(ig.KEY.SPACE, 'start'); // FIXME: collides with the stats screen
}, },
update: function() { update: function() {
if (ig.input.pressed('start')) ig.system.setGame(RunningGame); if (ig.input.pressed('start-game')) ig.system.setGame(RunningGame);
this.parent(); this.parent();
}, },

BIN
dev/media/pause_dialog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB