
Untitled
By: a guest on
Apr 24th, 2012 | syntax:
None | size: 1.62 KB | hits: 25 | expires: Never
package
{
import flash.geom.Point;
/**
* ...
* @author RTLShadow
*/
public class AIPaddle extends Paddle
{
private var estY:Number;
public function AIPaddle(gameScreen:GameScreen)
{
super(gameScreen)
}
override public function eFrame():Boolean
{
//AI Algorithm
if (g.xDir > 0)
{
if (estY <= this.y - this.height / 3)
{
if (this.y - this.height / 2 > 0)
{
if (this.y - estY > g.paddleSpeed)
{
this.y -= g.paddleSpeed;
}
else
{
this.y -= this.y - estY
}
}
}
else if (estY > this.y + this.height / 3)
{
if (this.y + this.height / 2 < stage.stageHeight)
{
if (estY - this.y > g.paddleSpeed)
{
this.y += g.paddleSpeed;
}
else
{
this.y -= estY - this.y;
}
}
}
}
else
{
if (this.y != 300)
{
if (this.y < 300)
{
if (this.y + g.paddleSpeed > 300)
{
this.y += 300 - this.y
}
else
{
this.y += g.paddleSpeed;
}
this.y += g.paddleSpeed
}
else if (this.y > 300)
{
if (this.y - g.paddleSpeed < 300)
{
this.y -= this.y - 300;
}
else
{
this.y -= g.paddleSpeed;
}
}
}
}
// If the ball is not moving towards the AI.
return super.eFrame();
}
public function estimateEnd(ballPos:Point, xDir:Number, yDir:Number):void
{
var eY:Number;
eY = ballPos.y + yDir * (this.x - ballPos.x) / xDir;
estY = eY;
}
}
}