2013-04-03 21:50:28 +02:00
|
|
|
ig.module(
|
2012-06-24 14:30:33 +02:00
|
|
|
'game.main'
|
2012-06-21 10:13:21 +02:00
|
|
|
)
|
|
|
|
.requires(
|
2013-04-03 21:50:28 +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' ),
|
2013-04-03 21:51:11 +02:00
|
|
|
pauseDialog: new ig.Image('media/pause_dialog.png'),
|
2013-04-11 21:12:27 +02:00
|
|
|
showPause: false,
|
2013-04-11 21:34:22 +02:00
|
|
|
clearColor: null,
|
2012-06-21 10:13:21 +02:00
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
init: function() {
|
2013-04-03 21:51:11 +02:00
|
|
|
ig.input.unbindAll();
|
2013-04-11 21:49:31 +02:00
|
|
|
ig.global.score = {'ai': 1, 'human': 1};
|
2013-04-11 21:12:27 +02:00
|
|
|
|
|
|
|
// Menu navigation
|
2013-04-03 21:51:11 +02:00
|
|
|
ig.input.bind(ig.KEY.ESC, 'escape');
|
|
|
|
ig.input.bind(ig.KEY.ENTER, 'enter');
|
2013-04-11 21:12:27 +02:00
|
|
|
|
|
|
|
// Game navigation
|
2012-06-24 14:30:33 +02:00
|
|
|
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');
|
2013-04-03 21:51:11 +02:00
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
// vim goodness
|
|
|
|
ig.input.bind(ig.KEY.K, 'up');
|
|
|
|
ig.input.bind(ig.KEY.J, 'down');
|
|
|
|
|
2013-04-03 21:51:11 +02:00
|
|
|
// Gamer style
|
|
|
|
ig.input.bind(ig.KEY.W, 'up');
|
|
|
|
ig.input.bind(ig.KEY.S, 'down');
|
|
|
|
|
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() {
|
2013-04-03 21:51:11 +02:00
|
|
|
// User is in the pause menu
|
2013-04-11 21:12:27 +02:00
|
|
|
if (this.showPause) {
|
2013-04-11 21:49:31 +02:00
|
|
|
if (ig.input.pressed('escape')) {
|
2013-04-03 21:51:11 +02:00
|
|
|
ig.system.setGame(StartScreen);
|
2013-04-11 21:12:27 +02:00
|
|
|
return;
|
2013-04-03 21:51:11 +02:00
|
|
|
}
|
|
|
|
|
2013-04-11 21:49:31 +02:00
|
|
|
if (ig.input.pressed('enter')) {
|
2013-04-11 21:12:27 +02:00
|
|
|
this.showPause = false;
|
|
|
|
return;
|
2013-04-03 21:51:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 22:26:28 +02:00
|
|
|
// One player has won the game
|
2013-04-11 21:49:31 +02:00
|
|
|
if (ig.global.score.ai == 0 || ig.global.score.human == 0) {
|
|
|
|
ig.system.setGame(ScoreboardScreen);
|
2012-07-03 22:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The User want back to the main menu inside a running game
|
2013-04-03 21:51:11 +02:00
|
|
|
if (ig.input.pressed('escape')) {
|
2013-04-11 21:12:27 +02:00
|
|
|
this.showPause = true;
|
2012-07-03 22:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The game is running
|
2013-04-11 21:49:31 +02:00
|
|
|
if (!this.showPause) this.parent();
|
2012-06-24 14:30:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
draw: function() {
|
2013-04-11 21:34:22 +02:00
|
|
|
ig.system.context.clearRect( 0 ,0, ig.system.realWidth, ig.system.realHeight );
|
2012-06-24 14:30:33 +02:00
|
|
|
this.parent(); // Draw entries and background
|
2013-04-11 21:49:31 +02:00
|
|
|
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);
|
2013-04-03 21:51:11 +02:00
|
|
|
|
2013-04-11 21:12:27 +02:00
|
|
|
if (this.showPause) {
|
2013-04-03 21:51:11 +02:00
|
|
|
this.pauseDialog.draw(150, 100);
|
|
|
|
}
|
2012-06-24 14:30:33 +02:00
|
|
|
}
|
|
|
|
});
|
2012-06-21 10:13:21 +02:00
|
|
|
|
2013-04-11 21:49:31 +02:00
|
|
|
ScoreboardScreen = ig.Game.extend({
|
2013-04-11 22:20:03 +02:00
|
|
|
scoreoid: {
|
|
|
|
api_key: 'd1011f8f6776a10f7a5d87eaa86c43c8d2ffb9dc',
|
|
|
|
game_id: '642fc6c1e8',
|
|
|
|
response: 'json'
|
|
|
|
},
|
2013-04-11 21:49:31 +02:00
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
2013-04-11 22:20:03 +02:00
|
|
|
loadScores: function() {
|
|
|
|
$.post('https://www.scoreoid.com/api/getScores', this.scoreoid, function(data) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
saveScore: function(username, score) {
|
|
|
|
},
|
|
|
|
|
2013-04-11 21:49:31 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
StartScreen = ig.Game.extend({
|
|
|
|
background: new ig.Image('media/main_screen.png'),
|
2013-04-11 21:59:42 +02:00
|
|
|
clearColor: null,
|
2012-06-21 10:13:21 +02:00
|
|
|
|
2012-06-24 14:30:33 +02:00
|
|
|
init: function() {
|
2013-04-03 21:51:11 +02:00
|
|
|
ig.input.bind(ig.KEY.ENTER, 'start-game');
|
2012-06-24 14:30:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function() {
|
2013-04-11 21:12:27 +02:00
|
|
|
if (ig.input.pressed('start-game')) {
|
|
|
|
ig.system.setGame(RunningGame);
|
|
|
|
}
|
2012-06-24 14:30:33 +02:00
|
|
|
this.parent();
|
|
|
|
},
|
|
|
|
|
|
|
|
draw: function() {
|
2013-04-11 21:59:42 +02:00
|
|
|
ig.system.context.clearRect( 0 ,0, ig.system.realWidth, ig.system.realHeight );
|
2012-06-24 14:30:33 +02:00
|
|
|
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
|
|
|
|