Make the AI unbreakable ... almost. see #9
This commit is contained in:
parent
7b40c7adb1
commit
3879dbef65
1 changed files with 42 additions and 11 deletions
|
@ -6,21 +6,52 @@ ig.module(
|
|||
'game.entities.paddle'
|
||||
)
|
||||
.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(){
|
||||
var ball = ig.game.getEntitiesByType( EntityBall )[0];
|
||||
// TODO: Let the AI use the force feature
|
||||
|
||||
if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) {
|
||||
this.vel.y = 100;
|
||||
} else {
|
||||
this.vel.y = -100;
|
||||
}
|
||||
// Check if the ball is moving towards the enemy
|
||||
if (ball.vel.x < 0) {
|
||||
// Do we need to move the panel enyway?
|
||||
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue