60b6af8e63
If the AI or the human player looses 10 games, the game is over and goes back into the main screen. A score is displayed on top of the game for each side.
68 lines
1.7 KiB
JavaScript
Executable file
68 lines
1.7 KiB
JavaScript
Executable file
ig.module(
|
|
'game.main'
|
|
)
|
|
.requires(
|
|
'impact.debug.menu',
|
|
'impact.game',
|
|
'impact.font',
|
|
|
|
'game.entities.ball',
|
|
'game.entities.paddle-enemy',
|
|
'game.entities.paddle-player',
|
|
|
|
'game.levels.level1'
|
|
)
|
|
.defines(function(){
|
|
RunningGame = ig.Game.extend({
|
|
font: new ig.Font( 'media/04b03.font.png' ),
|
|
score: {'ai': 10, 'human': 10},
|
|
|
|
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');
|
|
// vim goodness
|
|
ig.input.bind(ig.KEY.K, 'up');
|
|
ig.input.bind(ig.KEY.J, 'down');
|
|
|
|
// Load the level
|
|
this.loadLevel( LevelLevel1 );
|
|
},
|
|
|
|
update: function() {
|
|
if (this.score.ai == 0 || this.score.human == 0 || ig.input.pressed('mainmenu'))
|
|
ig.system.setGame(StartScreen);
|
|
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);
|
|
}
|
|
});
|
|
|
|
StartScreen = ig.Game.extend({
|
|
background: new ig.Image('media/main_screen.png'),
|
|
|
|
init: function() {
|
|
ig.input.bind(ig.KEY.ENTER, 'start');
|
|
ig.input.bind(ig.KEY.SPACE, 'start');
|
|
},
|
|
|
|
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 );
|
|
});
|
|
|