improved the ball movement; added the goal for the ball that resets the ball position
This commit is contained in:
parent
6159963b32
commit
e4a1a8b44d
7 changed files with 69 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
28
dev/lib/game/entities/goal.js
Normal file
28
dev/lib/game/entities/goal.js
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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')];
|
||||
});
|
|
@ -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 );
|
||||
},
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue