Extract the scoreboard

This commit is contained in:
Aaron Mueller 2013-04-11 21:49:31 +02:00
parent 9f3c7a1252
commit f163e34a70
4 changed files with 34 additions and 28 deletions

View File

@ -17,7 +17,7 @@ ig.module(
check: function(other) {
if (other.name == 'ball') {
ig.game.score[this.owner] -= 1;
ig.global.score[this.owner] -= 1;
other.reset();
this.looseSound.play();
}

View File

@ -15,15 +15,13 @@
.defines(function(){
RunningGame = ig.Game.extend({
font: new ig.Font( 'media/04b03.font.png' ),
statsBackground: new ig.Image('media/stats_screen.png'),
pauseDialog: new ig.Image('media/pause_dialog.png'),
score: {'ai': 1, 'human': 1},
showStats: false,
showPause: false,
clearColor: null,
init: function() {
ig.input.unbindAll();
ig.global.score = {'ai': 1, 'human': 1};
// Menu navigation
ig.input.bind(ig.KEY.ESC, 'escape');
@ -48,31 +46,22 @@
},
update: function() {
// The user is in the game stats menu, next stop: main menu
if (this.showStats) {
if (ig.input.pressed('enter')) {
this.showStats = false;
ig.system.setGame(StartScreen);
}
return;
}
// User is in the pause menu
if (this.showPause) {
if (ig.input.pressed('enter')) {
if (ig.input.pressed('escape')) {
ig.system.setGame(StartScreen);
return;
}
if (ig.input.pressed('escape')) {
if (ig.input.pressed('enter')) {
this.showPause = false;
return;
}
}
// One player has won the game
if (this.score.ai == 0 || this.score.human == 0) {
this.showStats = true;
if (ig.global.score.ai == 0 || ig.global.score.human == 0) {
ig.system.setGame(ScoreboardScreen);
}
// The User want back to the main menu inside a running game
@ -81,22 +70,14 @@
}
// The game is running
if (!this.showStats && !this.showPause) {
this.parent(); // Update entries and background
}
if (!this.showPause) this.parent();
},
draw: function() {
ig.system.context.clearRect( 0 ,0, ig.system.realWidth, ig.system.realHeight );
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 [ENTER] to move to the main menu', 200, 100, ig.Font.ALIGN.CENTER);
}
this.font.draw(ig.global.score.ai, 270, 25, ig.Font.ALIGN.CENTER);
this.font.draw(ig.global.score.human, 350, 25, ig.Font.ALIGN.CENTER);
if (this.showPause) {
this.pauseDialog.draw(150, 100);
@ -104,6 +85,28 @@
}
});
ScoreboardScreen = ig.Game.extend({
font: new ig.Font( 'media/04b03.font.png' ),
background: new ig.Image('media/stats_screen.png'),
init: function() {
ig.input.bind(ig.KEY.ENTER, 'main-menu');
},
update: function() {
if (ig.input.pressed('main-menu')) {
ig.system.setGame(StartScreen);
}
this.parent();
},
draw: function() {
this.parent();
this.background.draw(0, 0);
this.font.draw('You ' + (ig.global.score.ai == 0 ? 'won!' : 'loose!'), 200, 50, ig.Font.ALIGN.CENTER);
this.font.draw('Press [ENTER] to move to the main menu', 200, 100, ig.Font.ALIGN.CENTER);
}
});
StartScreen = ig.Game.extend({
background: new ig.Image('media/main_screen.png'),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -14,6 +14,9 @@ Initial release
* Display the Highscore in the game
* An special effect on ball hit (sprite/glor/whatever) (http://clokwork.net/2012/03/07/particle-generation-in-impactjs/)
* Highscore-Script (http://www.holoville.com/blog/?p=948, http://www.scoreoid.net/)
* username: arg
* email: mail@aaron-mueller.de
* passwort: iYon4OIgSy9
* Put the Player (with name) on the highscore
## Nice to have