diff --git a/dev/lib/game/entities/ball.js b/dev/lib/game/entities/ball.js index 6cb8676..4a7d55c 100644 --- a/dev/lib/game/entities/ball.js +++ b/dev/lib/game/entities/ball.js @@ -8,20 +8,52 @@ ig.module( EntityBall = ig.Entity.extend({ + name: 'ball', + size: {x:48, y:48}, collides: ig.Entity.COLLIDES.ACTIVE, + type: ig.Entity.TYPE.B, animSheet: new ig.AnimationSheet( 'media/ball.png', 48, 48 ), bounciness: 1, + maxVel: {x: 1000, y: 1000}, init: function( x, y, settings ) { this.parent( x, y, settings ); this.addAnim( 'idle', 1, [0] ); - this.vel.x = -400; - this.vel.y = 200; + 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; } }); diff --git a/dev/lib/game/entities/goal.js b/dev/lib/game/entities/goal.js new file mode 100644 index 0000000..5cd714e --- /dev/null +++ b/dev/lib/game/entities/goal.js @@ -0,0 +1,28 @@ +ig.module( + 'game.entities.goal' +) +.requires( + 'impact.entity' +) +.defines(function(){ + + EntityGoal = ig.Entity.extend({ + + height: 90, + + size: {x:48, y:48}, + checkAgainst: ig.Entity.TYPE.B, + + _wmScalable: true, + _wmDrawBox: true, + _wmBoxColor: '#00ff00', + + check: function( other ) { + if(other.name == 'ball') { + other.reset(); + } + } + + }); + +}); \ No newline at end of file diff --git a/dev/lib/game/entities/paddle-player.js b/dev/lib/game/entities/paddle-player.js index 8d61def..032e318 100644 --- a/dev/lib/game/entities/paddle-player.js +++ b/dev/lib/game/entities/paddle-player.js @@ -21,16 +21,6 @@ ig.module( this.vel.y = 0; } - if( ig.input.state('left') ) { - this.vel.x = -400; - } - else if( ig.input.state('right') ) { - this.vel.x = 400; - } - else { - this.vel.x = 0; - } - this.parent(); } diff --git a/dev/lib/game/entities/paddle.js b/dev/lib/game/entities/paddle.js index 3b51bdb..4d3936a 100644 --- a/dev/lib/game/entities/paddle.js +++ b/dev/lib/game/entities/paddle.js @@ -8,12 +8,15 @@ ig.module( EntityPaddle = ig.Entity.extend({ + name: 'paddle', + size: {x:64, y:128}, collides: ig.Entity.COLLIDES.FIXED, + type: ig.Entity.TYPE.A, animSheet: new ig.AnimationSheet( 'media/paddle.png', 64, 128 ), - maxVel: {x: 400, y: 400}, + maxVel: {x: 0, y: 400}, init: function( x, y, settings ) { this.parent( x, y, settings ); diff --git a/dev/lib/game/levels/level1.js b/dev/lib/game/levels/level1.js index 3b9a26f..c1f0d43 100644 --- a/dev/lib/game/levels/level1.js +++ b/dev/lib/game/levels/level1.js @@ -1,6 +1,6 @@ ig.module( 'game.levels.level1' ) -.requires( 'impact.image','game.entities.paddle-enemy','game.entities.paddle-player','game.entities.ball' ) +.requires( 'impact.image','game.entities.paddle-enemy','game.entities.paddle-player','game.entities.ball','game.entities.goal' ) .defines(function(){ -LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":8,"y":152},{"type":"EntityPaddlePlayer","x":548,"y":112},{"type":"EntityBall","x":288,"y":144}],"layer":[{"name":"bg","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/tileset.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,1,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,1,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[1,1,1,1,1,1,1,1,1,1,1,1,1]]},{"name":"collision","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,1,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1]]}]}/*]JSON*/; +LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":48,"y":128},{"type":"EntityPaddlePlayer","x":512,"y":128},{"type":"EntityBall","x":288,"y":192},{"type":"EntityGoal","x":604,"y":48,"settings":{"size":{"x":20,"y":288}}},{"type":"EntityGoal","x":0,"y":48,"settings":{"size":{"x":20,"y":288}}}],"layer":[{"name":"bg","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/tileset.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[1,1,1,1,1,1,1,1,1,1,1,1,1]]},{"name":"collision","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1]]}]}/*]JSON*/; LevelLevel1Resources=[new ig.Image('media/tileset.png')]; }); \ No newline at end of file diff --git a/dev/lib/game/main.js b/dev/lib/game/main.js index 4e1248b..aa100fa 100755 --- a/dev/lib/game/main.js +++ b/dev/lib/game/main.js @@ -22,8 +22,6 @@ MyGame = ig.Game.extend({ init: function() { ig.input.bind( ig.KEY.UP_ARROW, 'up' ); ig.input.bind( ig.KEY.DOWN_ARROW, 'down' ); - ig.input.bind( ig.KEY.LEFT_ARROW, 'left' ); - ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' ); this.loadLevel( LevelLevel1 ); }, diff --git a/dev/lib/impact/entity.js b/dev/lib/impact/entity.js index 3fa961c..c733085 100755 --- a/dev/lib/impact/entity.js +++ b/dev/lib/impact/entity.js @@ -64,7 +64,7 @@ ig.Entity = ig.Class.extend({ this.last.x = this.pos.x; this.last.y = this.pos.y; this.vel.y += ig.game.gravity * ig.system.tick * this.gravityFactor; - + this.vel.x = this.getNewVelocity( this.vel.x, this.accel.x, this.friction.x, this.maxVel.x ); this.vel.y = this.getNewVelocity( this.vel.y, this.accel.y, this.friction.y, this.maxVel.y );