diff --git a/dev/lib/game/entities/ball.js b/dev/lib/game/entities/ball.js index e3bf015..a9ce80c 100644 --- a/dev/lib/game/entities/ball.js +++ b/dev/lib/game/entities/ball.js @@ -5,57 +5,48 @@ ig.module( 'impact.entity' ) .defines(function(){ + EntityBall = ig.Entity.extend({ + name: 'ball', + size: {x: 24, y: 24}, + collides: ig.Entity.COLLIDES.ACTIVE, + type: ig.Entity.TYPE.B, + animSheet: new ig.AnimationSheet( 'media/ball.png', 24, 24 ), + bounciness: 1, + maxVel: {x: 1000, y: 1000}, -EntityBall = ig.Entity.extend({ + init: function( x, y, settings ) { + this.parent( x, y, settings ); + this.addAnim( 'idle', 1, [0] ); + this.randomVel(); + }, - name: 'ball', + ready: function() { + this.startPos = {x: this.pos.x, y: this.pos.y}; + }, - size: {x: 24, y: 24}, - collides: ig.Entity.COLLIDES.ACTIVE, - type: ig.Entity.TYPE.B, + collideWith: function( other, axis ) { + if (other.name == 'paddle') { + // the horizontal speed of the ball multiplied + // every time it hits a paddle + this.vel.x *= 1.15; - animSheet: new ig.AnimationSheet( 'media/ball.png', 24, 24 ), + // the paddles y movement is added to the ball, + // so that players can give the ball a spin + this.vel.y += other.vel.y/2; + } + }, - bounciness: 1, - maxVel: {x: 1000, y: 1000}, - - init: function( x, y, settings ) { - this.parent( x, y, settings ); - - this.addAnim( 'idle', 1, [0] ); - - this.randomVel(); - }, - - ready: function() { - this.startPos = {x: this.pos.x, y: this.pos.y}; - }, - - collideWith: function( other, axis ) { - if(other.name == 'paddle') { - // the horizontal speed of the ball multiplied - // every time it hits a paddle - this.vel.x *= 1.15; - - // the paddles y movement is added to the ball, - // so that players can give the ball a spin - this.vel.y += other.vel.y/2; - } - }, - - reset: function() { - this.randomVel(); - - this.pos.x = this.startPos.x; - this.pos.y = this.startPos.y; - }, - - randomVel: function() { - this.vel.x = (Math.random()*(100)) + 100; - if(Math.random() > .5) this.vel.x *= -1; - this.vel.y = (Math.random()*20) + 50; - } + reset: function() { + this.randomVel(); + this.pos.x = this.startPos.x; + this.pos.y = this.startPos.y; + }, + randomVel: function() { + this.vel.x = Math.random()*100+100; + if (Math.random() > .5) this.vel.x *= -1; + this.vel.y = Math.random()*20+50; + } + }); }); -}); diff --git a/dev/lib/game/entities/goal.js b/dev/lib/game/entities/goal.js index d2e6b3e..f80a89b 100644 --- a/dev/lib/game/entities/goal.js +++ b/dev/lib/game/entities/goal.js @@ -22,7 +22,6 @@ EntityGoal = ig.Entity.extend({ other.reset(); } } - }); }); diff --git a/dev/lib/game/main.js b/dev/lib/game/main.js index 9c6fbd6..4bdf146 100755 --- a/dev/lib/game/main.js +++ b/dev/lib/game/main.js @@ -1,5 +1,5 @@ -ig.module( - 'game.main' +ig.module( + 'game.main' ) .requires( 'impact.game', @@ -12,35 +12,52 @@ ig.module( 'game.levels.level1' ) .defines(function(){ + RunningGame = ig.Game.extend({ + font: new ig.Font( 'media/04b03.font.png' ), -MyGame = ig.Game.extend({ - - // Load a font - font: new ig.Font( 'media/04b03.font.png' ), - - - init: function() { - ig.input.bind( ig.KEY.UP_ARROW, 'up' ); - ig.input.bind( ig.KEY.DOWN_ARROW, 'down' ); + 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'); - this.loadLevel( LevelLevel1 ); - }, - - update: function() { - // Update all entities and backgroundMaps - this.parent(); - - // Add your own, additional update code here - }, - - draw: function() { - // Draw all entities and backgroundMaps - this.parent(); - } + // Load the level + this.loadLevel( LevelLevel1 ); + }, + + update: function() { + if (ig.input.pressed('mainmenu')) ig.system.setGame(StartScreen); + this.parent(); // Update entries and background + }, + + draw: function() { + this.parent(); // Draw entries and background + } + }); + + 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 ); }); -// Start the Game with 60fps, a resolution of 640x400 (16:10), scaled -// up by a factor of 2 -ig.main( '#canvas', MyGame, 60, 640, 400, 1 ); - -}); diff --git a/dev/media/main_screen.png b/dev/media/main_screen.png new file mode 100644 index 0000000..15fe5f4 Binary files /dev/null and b/dev/media/main_screen.png differ