Make the AI unbreakable ... almost. see #9

This commit is contained in:
Aaron Mueller 2012-07-06 19:14:07 +02:00
parent 7b40c7adb1
commit 3879dbef65

View file

@ -6,21 +6,52 @@ ig.module(
'game.entities.paddle' 'game.entities.paddle'
) )
.defines(function(){ .defines(function(){
EntityPaddleEnemy = EntityPaddle.extend({
move_delay: 35,
update: function() {
var ball = ig.game.getEntitiesByType(EntityBall)[0];
EntityPaddleEnemy = EntityPaddle.extend({ if (this.move_delay > 0) this.move_delay -= 1;
update: function(){ // TODO: Let the AI use the force feature
var ball = ig.game.getEntitiesByType( EntityBall )[0];
if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) { // Check if the ball is moving towards the enemy
this.vel.y = 100; if (ball.vel.x < 0) {
} else { // Do we need to move the panel enyway?
this.vel.y = -100; if (this.move_delay == 0 && ((ball.pos.y > this.pos.y-5) && (ball.pos.y+ball.size.y < this.pos.y+this.size.y+5))) {
} console.log("delay" + ball.pos.y);
this.move_delay = 3;
if (this.vel.y < 0) {
this.vel.y = -200+((3-this.move_delay)*50)
}
if (this.vel.y > 0) {
this.vel.y = 200-((3-this.move_delay)*50)
}
} else if (this.move_delay == 0) {
// The paddle is too low
if ((ball.pos.y+ball.size.y/2) < (this.pos.y+30)) {
this.vel.y = -400;
this.parent(); // The paddle is too high
} } else {
this.vel.y = 400;
}
}
// Move to the middle
} else {
if (this.pos.y >= 130 && this.pos.y <= 180) {
this.vel.y = 0;
}
if (this.pos.y < 130) {
this.vel.y = 150;
} else if (this.pos.y > 180) {
this.vel.y = -150;
}
}
this.parent();
}
});
}); });
});