file cleanup
This commit is contained in:
parent
e4a1a8b44d
commit
9f314ec95c
6 changed files with 96 additions and 97 deletions
|
@ -6,56 +6,56 @@ ig.module(
|
|||
)
|
||||
.defines(function(){
|
||||
|
||||
EntityBall = ig.Entity.extend({
|
||||
EntityBall = ig.Entity.extend({
|
||||
|
||||
name: 'ball',
|
||||
name: 'ball',
|
||||
|
||||
size: {x:48, y:48},
|
||||
collides: ig.Entity.COLLIDES.ACTIVE,
|
||||
type: ig.Entity.TYPE.B,
|
||||
size: {x:48, y:48},
|
||||
collides: ig.Entity.COLLIDES.ACTIVE,
|
||||
type: ig.Entity.TYPE.B,
|
||||
|
||||
animSheet: new ig.AnimationSheet( 'media/ball.png', 48, 48 ),
|
||||
animSheet: new ig.AnimationSheet( 'media/ball.png', 48, 48 ),
|
||||
|
||||
bounciness: 1,
|
||||
maxVel: {x: 1000, y: 1000},
|
||||
bounciness: 1,
|
||||
maxVel: {x: 1000, y: 1000},
|
||||
|
||||
init: function( x, y, settings ) {
|
||||
this.parent( x, y, settings );
|
||||
|
||||
this.addAnim( 'idle', 1, [0] );
|
||||
init: function( x, y, settings ) {
|
||||
this.parent( x, y, settings );
|
||||
|
||||
this.addAnim( 'idle', 1, [0] );
|
||||
|
||||
this.randomVel();
|
||||
},
|
||||
this.randomVel();
|
||||
},
|
||||
|
||||
ready: function() {
|
||||
this.startPos = {x: this.pos.x, y: this.pos.y};
|
||||
},
|
||||
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;
|
||||
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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,23 +6,23 @@ ig.module(
|
|||
)
|
||||
.defines(function(){
|
||||
|
||||
EntityGoal = ig.Entity.extend({
|
||||
EntityGoal = ig.Entity.extend({
|
||||
|
||||
height: 90,
|
||||
height: 90,
|
||||
|
||||
size: {x:48, y:48},
|
||||
checkAgainst: ig.Entity.TYPE.B,
|
||||
size: {x:48, y:48},
|
||||
checkAgainst: ig.Entity.TYPE.B,
|
||||
|
||||
_wmScalable: true,
|
||||
_wmDrawBox: true,
|
||||
_wmBoxColor: '#00ff00',
|
||||
_wmScalable: true,
|
||||
_wmDrawBox: true,
|
||||
_wmBoxColor: '#00ff00',
|
||||
|
||||
check: function( other ) {
|
||||
if(other.name == 'ball') {
|
||||
other.reset();
|
||||
}
|
||||
check: function( other ) {
|
||||
if(other.name == 'ball') {
|
||||
other.reset();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,20 +7,20 @@ ig.module(
|
|||
)
|
||||
.defines(function(){
|
||||
|
||||
EntityPaddleEnemy = EntityPaddle.extend({
|
||||
EntityPaddleEnemy = EntityPaddle.extend({
|
||||
|
||||
update: function(){
|
||||
var ball = ig.game.getEntitiesByType( EntityBall )[0];
|
||||
update: function(){
|
||||
var ball = ig.game.getEntitiesByType( EntityBall )[0];
|
||||
|
||||
if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) {
|
||||
this.vel.y = 100;
|
||||
} else {
|
||||
this.vel.y = -100;
|
||||
}
|
||||
|
||||
this.parent();
|
||||
if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) {
|
||||
this.vel.y = 100;
|
||||
} else {
|
||||
this.vel.y = -100;
|
||||
}
|
||||
|
||||
});
|
||||
this.parent();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,24 +6,24 @@ ig.module(
|
|||
)
|
||||
.defines(function(){
|
||||
|
||||
EntityPaddlePlayer = EntityPaddle.extend({
|
||||
EntityPaddlePlayer = EntityPaddle.extend({
|
||||
|
||||
animSheet: new ig.AnimationSheet( 'media/paddle-player.png', 64, 128 ),
|
||||
animSheet: new ig.AnimationSheet( 'media/paddle-player.png', 64, 128 ),
|
||||
|
||||
update: function(){
|
||||
if( ig.input.state('up') ) {
|
||||
this.vel.y = -400;
|
||||
}
|
||||
else if( ig.input.state('down') ) {
|
||||
this.vel.y = 400;
|
||||
}
|
||||
else {
|
||||
this.vel.y = 0;
|
||||
}
|
||||
|
||||
this.parent();
|
||||
update: function(){
|
||||
if( ig.input.state('up') ) {
|
||||
this.vel.y = -400;
|
||||
}
|
||||
else if( ig.input.state('down') ) {
|
||||
this.vel.y = 400;
|
||||
}
|
||||
else {
|
||||
this.vel.y = 0;
|
||||
}
|
||||
|
||||
});
|
||||
this.parent();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,24 +6,24 @@ ig.module(
|
|||
)
|
||||
.defines(function(){
|
||||
|
||||
EntityPaddle = ig.Entity.extend({
|
||||
EntityPaddle = ig.Entity.extend({
|
||||
|
||||
name: 'paddle',
|
||||
name: 'paddle',
|
||||
|
||||
size: {x:64, y:128},
|
||||
collides: ig.Entity.COLLIDES.FIXED,
|
||||
type: ig.Entity.TYPE.A,
|
||||
size: {x:64, y:128},
|
||||
collides: ig.Entity.COLLIDES.FIXED,
|
||||
type: ig.Entity.TYPE.A,
|
||||
|
||||
animSheet: new ig.AnimationSheet( 'media/paddle.png', 64, 128 ),
|
||||
animSheet: new ig.AnimationSheet( 'media/paddle.png', 64, 128 ),
|
||||
|
||||
maxVel: {x: 0, y: 400},
|
||||
maxVel: {x: 0, y: 400},
|
||||
|
||||
init: function( x, y, settings ) {
|
||||
this.parent( x, y, settings );
|
||||
|
||||
this.addAnim( 'idle', 1, [0] );
|
||||
}
|
||||
init: function( x, y, settings ) {
|
||||
this.parent( x, y, settings );
|
||||
|
||||
this.addAnim( 'idle', 1, [0] );
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,7 +39,6 @@ MyGame = ig.Game.extend({
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
// 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 );
|
||||
|
|
Loading…
Reference in a new issue