From cd3e2720c61be20fb0a79460355f68e5dea9cf8d Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Tue, 3 Jul 2012 22:26:28 +0200 Subject: [PATCH] Implement the win/loose screen, see #6 --- dev/lib/game/main.js | 41 ++++++++++++++++++++++++++++++++----- dev/media/stats_screen.png | Bin 0 -> 1616 bytes 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 dev/media/stats_screen.png diff --git a/dev/lib/game/main.js b/dev/lib/game/main.js index a627109..47a0c4d 100755 --- a/dev/lib/game/main.js +++ b/dev/lib/game/main.js @@ -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 ); + 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(); // Update entries and background + //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() { diff --git a/dev/media/stats_screen.png b/dev/media/stats_screen.png new file mode 100644 index 0000000000000000000000000000000000000000..98e375e3c5cea2bae2d029b82994703671e8ca46 GIT binary patch literal 1616 zcmeAS@N?(olHy`uVBq!ia0y~yU@Bl>U~J%E1B&Qo#;XG<#^NA%Cx&(BWL^R}Y)Rhk zE)4%caKYZ?lYt_f1s;*b3=DFIK$tP_La7~4kiEpy*OmPaJF^I*d|RWD5Ca421y2{p zkcwMxuQ>`bFmN2+&{*#u;mjVRv~YdcBu)l~^erqv)A<+}nAsT`8krdkfbNj6U|`^p z0do%=U}Q*m0OrC}fw(YLP)#6JP)#6JFijv;*o`Jm705j>vw-e_nMIldK<*;fnWQ;@ z2H}Lm0rZO~WC!4mPGnVNM-);@Avryf?Ep~HAT2#1ITMx(h|4R)siI0!oim!JaTYzK hC6&RJr#~EL@_Np^|3KogKfvOi!PC{xWt~$(69Cb78|451 literal 0 HcmV?d00001