Advertisement
Guest User

shark class

a guest
Nov 15th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2. Shark class
  3.  
  4. package
  5. {
  6. import flash.display.*;
  7. import flash.events.*;
  8. public class Shark extends MovieClip
  9. {
  10. var CharacterX:Number = 0;
  11. var CharacterY:Number = 0;
  12. static var targetX:int;
  13. static var targetY:int
  14. public function Shark()
  15. {
  16.  
  17. this.x = 300;
  18. this.y = 200;
  19. addEventListener(Event.ENTER_FRAME,playGame);
  20. }
  21.  
  22. public function set CX(characterx:Number){
  23. this.CharacterX = characterx - this.x;
  24.  
  25. }
  26. public function set CY(charactery:Number){
  27. this.CharacterY = charactery - this.y;
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. function playGame(event:Event):void
  36. {
  37. var ease:int = 20;
  38. var speed:int = 10;
  39. targetX = root.CharacterX - this.x;
  40. targetY = root.CharacterY - this.y;
  41. var rotation = Math.atan2(targetY,targetX) * 180 / Math.PI;
  42. if (Math.abs((rotation - this.rotation)) > 180)
  43. {
  44. if (((rotation > 0) && this.rotation < 0))
  45. {
  46. this.rotation -= (((360 - rotation) + this.rotation) / ease);
  47. }
  48. else if (this.rotation > 0 && rotation < 0)
  49. {
  50. this.rotation += (((360 - rotation) + this.rotation) / ease);
  51. }
  52. }
  53. else if ((rotation < this.rotation))
  54. {
  55. this.rotation -= Math.abs(this.rotation - rotation) / ease;
  56. }
  57. else
  58. {
  59. this.rotation += Math.abs((rotation - this.rotation)) / ease;
  60. }
  61.  
  62.  
  63.  
  64.  
  65. var vx:Number = speed * (90 - Math.abs(this.rotation)) / 90;
  66. var vy:Number;//Velocity in y is the difference of speed and vx.
  67. if (this.rotation < 0)
  68. {
  69. vy = - speed + Math.abs(vx);//Going upwards.
  70. }
  71. else
  72. {
  73. vy = speed - Math.abs(vx);//Going downwards.
  74. }
  75. this.x += vx;
  76. this.y += vy;
  77. }
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement