file cleanup

This commit is contained in:
Ruben Müller 2012-06-24 10:50:26 +02:00
parent e4a1a8b44d
commit 9f314ec95c
6 changed files with 96 additions and 97 deletions

View file

@ -6,56 +6,56 @@ ig.module(
) )
.defines(function(){ .defines(function(){
EntityBall = ig.Entity.extend({ EntityBall = ig.Entity.extend({
name: 'ball', name: 'ball',
size: {x:48, y:48}, size: {x:48, y:48},
collides: ig.Entity.COLLIDES.ACTIVE, collides: ig.Entity.COLLIDES.ACTIVE,
type: ig.Entity.TYPE.B, 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, bounciness: 1,
maxVel: {x: 1000, y: 1000}, maxVel: {x: 1000, y: 1000},
init: function( x, y, settings ) { init: function( x, y, settings ) {
this.parent( x, y, settings ); this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] ); this.addAnim( 'idle', 1, [0] );
this.randomVel(); this.randomVel();
}, },
ready: function() { ready: function() {
this.startPos = {x: this.pos.x, y: this.pos.y}; this.startPos = {x: this.pos.x, y: this.pos.y};
}, },
collideWith: function( other, axis ) { collideWith: function( other, axis ) {
if(other.name == 'paddle') { if(other.name == 'paddle') {
// the horizontal speed of the ball multiplied // the horizontal speed of the ball multiplied
// every time it hits a paddle // every time it hits a paddle
this.vel.x *= 1.15; this.vel.x *= 1.15;
// the paddles y movement is added to the ball, // the paddles y movement is added to the ball,
// so that players can give the ball a spin // so that players can give the ball a spin
this.vel.y += other.vel.y/2; 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;
}
});
});

View file

@ -6,23 +6,23 @@ ig.module(
) )
.defines(function(){ .defines(function(){
EntityGoal = ig.Entity.extend({ EntityGoal = ig.Entity.extend({
height: 90, height: 90,
size: {x:48, y:48}, size: {x:48, y:48},
checkAgainst: ig.Entity.TYPE.B, checkAgainst: ig.Entity.TYPE.B,
_wmScalable: true, _wmScalable: true,
_wmDrawBox: true, _wmDrawBox: true,
_wmBoxColor: '#00ff00', _wmBoxColor: '#00ff00',
check: function( other ) { check: function( other ) {
if(other.name == 'ball') { if(other.name == 'ball') {
other.reset(); other.reset();
}
} }
}
}); });
}); });

View file

@ -7,20 +7,20 @@ ig.module(
) )
.defines(function(){ .defines(function(){
EntityPaddleEnemy = EntityPaddle.extend({ EntityPaddleEnemy = EntityPaddle.extend({
update: function(){ update: function(){
var ball = ig.game.getEntitiesByType( EntityBall )[0]; var ball = ig.game.getEntitiesByType( EntityBall )[0];
if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) { if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) {
this.vel.y = 100; this.vel.y = 100;
} else { } else {
this.vel.y = -100; this.vel.y = -100;
}
this.parent();
} }
}); this.parent();
}
}); });
});

View file

@ -6,24 +6,24 @@ ig.module(
) )
.defines(function(){ .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(){ update: function(){
if( ig.input.state('up') ) { if( ig.input.state('up') ) {
this.vel.y = -400; this.vel.y = -400;
} }
else if( ig.input.state('down') ) { else if( ig.input.state('down') ) {
this.vel.y = 400; this.vel.y = 400;
} }
else { else {
this.vel.y = 0; this.vel.y = 0;
}
this.parent();
} }
}); this.parent();
}
}); });
});

View file

@ -6,24 +6,24 @@ ig.module(
) )
.defines(function(){ .defines(function(){
EntityPaddle = ig.Entity.extend({ EntityPaddle = ig.Entity.extend({
name: 'paddle', name: 'paddle',
size: {x:64, y:128}, size: {x:64, y:128},
collides: ig.Entity.COLLIDES.FIXED, collides: ig.Entity.COLLIDES.FIXED,
type: ig.Entity.TYPE.A, 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 ) { init: function( x, y, settings ) {
this.parent( x, y, settings ); this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] ); this.addAnim( 'idle', 1, [0] );
} }
}); });
}); });

View file

@ -39,7 +39,6 @@ MyGame = ig.Game.extend({
} }
}); });
// Start the Game with 60fps, a resolution of 640x400 (16:10), scaled // Start the Game with 60fps, a resolution of 640x400 (16:10), scaled
// up by a factor of 2 // up by a factor of 2
ig.main( '#canvas', MyGame, 60, 640, 400, 1 ); ig.main( '#canvas', MyGame, 60, 640, 400, 1 );