Advertisement
Guest User

Untitled

a guest
Apr 24th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package
  2. {
  3. import flash.geom.Point;
  4.  
  5. /**
  6. * ...
  7. * @author RTLShadow
  8. */
  9. public class AIPaddle extends Paddle
  10. {
  11. private var estY:Number;
  12.  
  13. public function AIPaddle(gameScreen:GameScreen)
  14. {
  15. super(gameScreen)
  16. }
  17.  
  18. override public function eFrame():Boolean
  19. {
  20. //AI Algorithm
  21. if (g.xDir > 0)
  22. {
  23. if (estY <= this.y - this.height / 3)
  24. {
  25. if (this.y - this.height / 2 > 0)
  26. {
  27. if (this.y - estY > g.paddleSpeed)
  28. {
  29. this.y -= g.paddleSpeed;
  30. }
  31. else
  32. {
  33. this.y -= this.y - estY
  34. }
  35. }
  36. }
  37. else if (estY > this.y + this.height / 3)
  38. {
  39. if (this.y + this.height / 2 < stage.stageHeight)
  40. {
  41. if (estY - this.y > g.paddleSpeed)
  42. {
  43. this.y += g.paddleSpeed;
  44. }
  45. else
  46. {
  47. this.y -= estY - this.y;
  48. }
  49. }
  50. }
  51. }
  52. else
  53. {
  54. if (this.y != 300)
  55. {
  56. if (this.y < 300)
  57. {
  58. if (this.y + g.paddleSpeed > 300)
  59. {
  60. this.y += 300 - this.y
  61. }
  62. else
  63. {
  64. this.y += g.paddleSpeed;
  65. }
  66. this.y += g.paddleSpeed
  67. }
  68. else if (this.y > 300)
  69. {
  70. if (this.y - g.paddleSpeed < 300)
  71. {
  72. this.y -= this.y - 300;
  73. }
  74. else
  75. {
  76. this.y -= g.paddleSpeed;
  77. }
  78. }
  79. }
  80. }
  81. // If the ball is not moving towards the AI.
  82. return super.eFrame();
  83. }
  84.  
  85. public function estimateEnd(ballPos:Point, xDir:Number, yDir:Number):void
  86. {
  87. var eY:Number;
  88. eY = ballPos.y + yDir * (this.x - ballPos.x) / xDir;
  89. estY = eY;
  90. }
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement