2012-06-24 14:30:33 +02:00
|
|
|
ig.module(
|
|
|
|
'game.main'
|
2012-06-21 10:13:21 +02:00
|
|
|
)
|
|
|
|
.requires(
|
2012-06-24 23:03:05 +02:00
|
|
|
'impact.debug.menu',
|
2012-06-21 10:13:21 +02:00
|
|
|
'impact.game',
|
2012-06-22 18:20:41 +02:00
|
|
|
'impact.font',
|
|
|
|
|
|
|
|
'game.entities.ball',
|
|
|
|
'game.entities.paddle-enemy',
|
|
|
|
'game.entities.paddle-player',
|
|
|
|
|
|
|
|
'game.levels.level1'
|
2012-06-21 10:13:21 +02:00
|
|
|
)
|
|
|
|
.defines(function(){
|
2012-06-24 14:30:33 +02:00
|
|
|
RunningGame = ig.Game.extend({
|
|
|
|
font: new ig.Font( 'media/04b03.font.png' ),
|
2012-07-03 22:26:28 +02:00
|
|
|
statsBackground: new ig.Image('media/stats_screen.png'),
|
|
|
|
score: {'ai': 1, 'human': 1},
|
|
|
|
showStats: false,
|
2012-06-21 10:13:21 +02:00
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
init: function() {
|
|
|
|
ig.input.bind(ig.KEY.ESC, 'mainmenu');
|
|
|
|
ig.input.bind(ig.KEY.UP_ARROW, 'up');
|
|
|
|
ig.input.bind(ig.KEY.DOWN_ARROW, 'down');
|
2012-07-06 17:09:07 +02:00
|
|
|
ig.input.bind(ig.KEY.T, 'force-top');
|
|
|
|
ig.input.bind(ig.KEY.B, 'force-bottom');
|
2012-06-24 14:30:33 +02:00
|
|
|
// vim goodness
|
|
|
|
ig.input.bind(ig.KEY.K, 'up');
|
|
|
|
ig.input.bind(ig.KEY.J, 'down');
|
|
|
|
|
2012-07-03 22:26:28 +02:00
|
|
|
ig.input.bind(ig.KEY.SPACE, 'endgame');
|
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
// Load the level
|
2012-07-03 22:26:28 +02:00
|
|
|
this.loadLevel(LevelLevel1);
|
2012-06-24 14:30:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function() {
|
2012-07-03 22:26:28 +02:00
|
|
|
// The user is in the game stats menu, next stop: main menu
|
|
|
|
if (this.showStats) {
|
|
|
|
if (ig.input.state('endgame')) {
|
|
|
|
this.showStats = false;
|
2012-06-24 23:03:05 +02:00
|
|
|
ig.system.setGame(StartScreen);
|
2012-07-03 22:26:28 +02:00
|
|
|
//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
|
|
|
|
}
|
2012-06-24 14:30:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
draw: function() {
|
|
|
|
this.parent(); // Draw entries and background
|
2012-06-24 23:03:05 +02:00
|
|
|
this.font.draw(this.score.ai, 270, 25, ig.Font.ALIGN.CENTER);
|
|
|
|
this.font.draw(this.score.human, 350, 25, ig.Font.ALIGN.CENTER);
|
2012-07-03 22:26:28 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2012-06-24 14:30:33 +02:00
|
|
|
}
|
|
|
|
});
|
2012-06-21 10:13:21 +02:00
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
StartScreen = ig.Game.extend({
|
|
|
|
background: new ig.Image('media/main_screen.png'),
|
2012-06-21 10:13:21 +02:00
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
init: function() {
|
|
|
|
ig.input.bind(ig.KEY.ENTER, 'start');
|
2012-07-03 22:26:28 +02:00
|
|
|
//ig.input.bind(ig.KEY.SPACE, 'start'); // FIXME: collides with the stats screen
|
2012-06-24 14:30:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function() {
|
|
|
|
if (ig.input.pressed('start')) ig.system.setGame(RunningGame);
|
|
|
|
this.parent();
|
|
|
|
},
|
|
|
|
|
|
|
|
draw: function() {
|
|
|
|
this.parent();
|
|
|
|
this.background.draw(0, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start the Game with 60fps, a resolution of 640x400 (16:10), scaled
|
|
|
|
// up by a factor of 2
|
|
|
|
ig.main( '#canvas', StartScreen, 60, 624, 384, 1 );
|
2012-06-21 10:13:21 +02:00
|
|
|
});
|
2012-06-24 14:30:33 +02:00
|
|
|
|