1. function Main ()
  2. {
  3. stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
  4. }
  5.  
  6. var destinationX:int = 150;
  7. var destinationY:int = 150;
  8. var dX:int = 0;
  9. var dY:int = 0;
  10. var vX:int = 0;
  11. var vY:int = 0;
  12. var moveSpeedMax:Number = 1000;
  13. var rotateSpeedMax:Number = 15;
  14. var trueRotation:Number = 0;
  15. var decay:Number = 0.98;
  16.  
  17. function enterFrameHandler(event:Event):void
  18. {
  19. updatePosition();
  20. updateRotation();
  21. }
  22.  
  23. function updatePosition():void
  24. {
  25. destinationX = stage.mouseX;
  26. destinationY = stage.mouseY;
  27. vX += (destinationX - water_drop.x) / moveSpeedMax;
  28. vY += (destinationY - water_drop.y) / moveSpeedMax;
  29.  
  30. vX *= decay;
  31. vY *= decay;
  32.  
  33. water_drop.x += vX;
  34. water_drop.y += vY;
  35. }
  36.  
  37. function updateRotation():void
  38. {
  39. dX = water_drop.x - destinationX;
  40. dY = water_drop.y - destinationY;
  41.  
  42. var rotateTo:Number = getDegrees(getRadians(dX, dY));
  43.  
  44. if (rotateTo > water_drop.rotation + 180) rotateTo -= 360;
  45. if (rotateTo < water_drop.rotation - 180) rotateTo += 360;
  46.  
  47. trueRotation = (rotateTo - water_drop.rotation) / rotateSpeedMax;
  48. water_drop.rotation += trueRotation;
  49. }
  50.  
  51. function getRadians(delta_x:Number, delta_y:Number):Number
  52. {
  53. var r:Number = Math.atan2(delta_y, delta_x);
  54. if (delta_y < 0)
  55. {
  56. r += (2 * Math.PI);
  57. }
  58. return r;
  59. }
  60.  
  61. function getDegrees(radians:Number):Number
  62. {
  63. return Math.floor(radians/(Math.PI/180));
  64. }