Guest User

Untitled

a guest
Aug 17th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public class Monster extends MovieClip
  2. {
  3.  
  4.  
  5. //class fields
  6. //delta movement value - how many pixels the object will move per frame - change this into a CONSTANT later on
  7. var dX:int = 0
  8. var dY:int = 0
  9. var nextX, nextY:int;
  10. //var diffX, diffY:int;
  11.  
  12.  
  13.  
  14. /*
  15. * constructor will start the monster at frame 100 which is 100% health
  16. * The constructor also adds event listners
  17. */
  18. public function Monster()
  19. {
  20. this.gotoAndStop(100);
  21. this.addEventListener(Event.ENTER_FRAME, enterFrameEventHandler);
  22. }//end constructor
  23.  
  24.  
  25.  
  26. /*
  27. * This function does something
  28. */
  29. function handleKeyboardEvents(e:KeyboardEvent) {
  30. if (e.keyCode == 37 || e.keyCode == 100){ //left
  31. dY = -10;
  32. dX = 0;
  33. }
  34. if (e.keyCode == 38 || e.keyCode == 104){ //up
  35. dY = 0;
  36. dX = 10;
  37. }
  38. if (e.keyCode == 39 || e.keyCode == 102){ //right
  39. dY = 10;
  40. dX = 0;
  41. }
  42. if (e.keyCode == 40 || e.keyCode == 98){ //down
  43. dY = -10;
  44. dX = 0;
  45. }
  46. }
  47.  
  48.  
  49. /*
  50. * This function is called on every frame
  51. */
  52. function enterFrameEventHandler(event:Event):void {
  53. trace("I have entered a frame. my x is " + this.x + " and my y is " + this.y);
  54.  
  55.  
  56. nextX = this.x + dX;
  57. nextY = this.y + dY;
  58.  
  59. //diffX = (destX - this.x); //the distance to move
  60. //this.x += diffX * .15;// move slowly towards the mouse
  61.  
  62. this.x = nextX;
  63. this.y = nextY;
  64.  
  65. nextX = 0;
  66. nextY = 0;
  67.  
  68. }
  69. }
Add Comment
Please, Sign In to add comment