Implement the win/loose screen, see #6

This commit is contained in:
Aaron Mueller 2012-07-03 22:26:28 +02:00
parent a40f9d600a
commit cd3e2720c6
2 changed files with 36 additions and 5 deletions

View file

@ -15,7 +15,9 @@ ig.module(
.defines(function(){
RunningGame = ig.Game.extend({
font: new ig.Font( 'media/04b03.font.png' ),
score: {'ai': 10, 'human': 10},
statsBackground: new ig.Image('media/stats_screen.png'),
score: {'ai': 1, 'human': 1},
showStats: false,
init: function() {
ig.input.bind(ig.KEY.ESC, 'mainmenu');
@ -25,20 +27,49 @@ ig.module(
ig.input.bind(ig.KEY.K, 'up');
ig.input.bind(ig.KEY.J, 'down');
ig.input.bind(ig.KEY.SPACE, 'endgame');
// Load the level
this.loadLevel(LevelLevel1);
},
update: function() {
if (this.score.ai == 0 || this.score.human == 0 || ig.input.pressed('mainmenu'))
// The user is in the game stats menu, next stop: main menu
if (this.showStats) {
if (ig.input.state('endgame')) {
this.showStats = false;
ig.system.setGame(StartScreen);
//this.parent();
}
return;
}
// One player has won the game
if (this.score.ai == 0 || this.score.human == 0) {
this.showStats = true;
}
// The User want back to the main menu inside a running game
if (ig.input.pressed('mainmenu')) {
ig.system.setGame(StartScreen);
}
// The game is running
if (!this.showStats) {
this.parent(); // Update entries and background
}
},
draw: function() {
this.parent(); // Draw entries and background
this.font.draw(this.score.ai, 270, 25, ig.Font.ALIGN.CENTER);
this.font.draw(this.score.human, 350, 25, ig.Font.ALIGN.CENTER);
if (this.showStats) {
this.statsBackground.draw(0, 0);
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);
}
}
});
@ -47,7 +78,7 @@ ig.module(
init: function() {
ig.input.bind(ig.KEY.ENTER, 'start');
ig.input.bind(ig.KEY.SPACE, 'start');
//ig.input.bind(ig.KEY.SPACE, 'start'); // FIXME: collides with the stats screen
},
update: function() {

BIN
dev/media/stats_screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB