Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement