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' ), 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, init: function() { ig.input.unbindAll(); // Menu navigation ig.input.bind(ig.KEY.ESC, 'escape'); ig.input.bind(ig.KEY.ENTER, 'enter'); // Game navigation ig.input.bind(ig.KEY.UP_ARROW, 'up'); ig.input.bind(ig.KEY.DOWN_ARROW, 'down'); ig.input.bind(ig.KEY.T, 'force-top'); ig.input.bind(ig.KEY.B, 'force-bottom'); // vim goodness ig.input.bind(ig.KEY.K, 'up'); ig.input.bind(ig.KEY.J, 'down'); // Gamer style ig.input.bind(ig.KEY.W, 'up'); ig.input.bind(ig.KEY.S, 'down'); // Load the level this.loadLevel(LevelLevel1); }, 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')) { ig.system.setGame(StartScreen); return; } if (ig.input.pressed('escape')) { this.showPause = false; 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('escape')) { this.showPause = true; } // The game is running if (!this.showStats && !this.showPause) { 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 [ENTER] to move to the main menu', 200, 100, ig.Font.ALIGN.CENTER); } if (this.showPause) { this.pauseDialog.draw(150, 100); } } }); StartScreen = ig.Game.extend({ background: new ig.Image('media/main_screen.png'), init: function() { ig.input.bind(ig.KEY.ENTER, 'start-game'); }, update: function() { if (ig.input.pressed('start-game')) { 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 ); });