Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Monster extends MovieClip
- {
- //class fields
- //delta movement value - how many pixels the object will move per frame - change this into a CONSTANT later on
- var dX:int = 0
- var dY:int = 0
- var nextX, nextY:int;
- //var diffX, diffY:int;
- /*
- * constructor will start the monster at frame 100 which is 100% health
- * The constructor also adds event listners
- */
- public function Monster()
- {
- this.gotoAndStop(100);
- this.addEventListener(Event.ENTER_FRAME, enterFrameEventHandler);
- }//end constructor
- /*
- * This function does something
- */
- function handleKeyboardEvents(e:KeyboardEvent) {
- if (e.keyCode == 37 || e.keyCode == 100){ //left
- dY = -10;
- dX = 0;
- }
- if (e.keyCode == 38 || e.keyCode == 104){ //up
- dY = 0;
- dX = 10;
- }
- if (e.keyCode == 39 || e.keyCode == 102){ //right
- dY = 10;
- dX = 0;
- }
- if (e.keyCode == 40 || e.keyCode == 98){ //down
- dY = -10;
- dX = 0;
- }
- }
- /*
- * This function is called on every frame
- */
- function enterFrameEventHandler(event:Event):void {
- trace("I have entered a frame. my x is " + this.x + " and my y is " + this.y);
- nextX = this.x + dX;
- nextY = this.y + dY;
- //diffX = (destX - this.x); //the distance to move
- //this.x += diffX * .15;// move slowly towards the mouse
- this.x = nextX;
- this.y = nextY;
- nextX = 0;
- nextY = 0;
- }
- }
Add Comment
Please, Sign In to add comment