Guest User

Untitled

a guest
Jun 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package com.asgamer.directionalmovement
  2. {
  3.  
  4. import flash.display.MovieClip;
  5. import flash.display.Stage;
  6. import flash.events.Event;
  7. import com.senocular.utils.KeyObject;
  8. import flash.ui.Keyboard;
  9.  
  10. public class bg extends MovieClip
  11. {
  12.  
  13. private var key:KeyObject;
  14. private var speed:Number = 0.3;
  15. private var rotateSpeed:Number = 5;
  16. private var vx:Number = 0;
  17. private var vy:Number = 0;
  18. private var friction:Number = 0.95;
  19. private var dedrotation:Number = 0;
  20.  
  21. public function bg () : void
  22. {
  23. key = new KeyObject(stage);
  24. addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
  25. }
  26.  
  27. public function loop(e:Event) : void
  28. {
  29.  
  30. if (key.isDown(Keyboard.UP))
  31. {
  32. vy += Math.sin(degreesToRadians(dedrotation)) * speed;
  33. vx += Math.cos(degreesToRadians(dedrotation)) * speed;
  34. } else {
  35. vy *= friction;
  36. vx *= friction;
  37. }
  38.  
  39. if (key.isDown(Keyboard.RIGHT))
  40. dedrotation += rotateSpeed;
  41. else if (key.isDown(Keyboard.LEFT))
  42. dedrotation -= rotateSpeed;
  43.  
  44. y -= vy;
  45. x -= vx;
  46.  
  47.  
  48. }
  49.  
  50. public function degreesToRadians(degrees:Number) : Number
  51. {
  52. return degrees * Math.PI / 180;
  53. }
  54.  
  55. }
  56.  
  57.  
  58. }
Add Comment
Please, Sign In to add comment