/************************************************/ /* Written by Felix Reidl (2005) */ /* feel free to use this, just don't claim */ /* you wrote it. */ /************************************************/ class Player extends MovieClip { private var action:Function; // referrer to the current action-function private var dir:Boolean; // true: faces right, false: faces left private var animation:String; // the frame label of the animation that should be played function Player() { // init variables action = stand; animation = "stand"; dir = true; } function update() { action = action(); // set direction (mirror movieclip if player faces to the left) _xscale = (dir && _xscale < 0) || (!dir && _xscale > 0) ? -_xscale : _xscale; } function stand() { // if the animation is something different we know // that the movieclip is not playing it yet. if (animation != "stand") { animation = "stand"; gotoAndPlay(animation); } // if either key is pressed the play runs if (Key.isDown(Key.RIGHT)) { dir = true; return run; } else if (Key.isDown(Key.LEFT)) { dir = false; return run; } return stand; } function run() { // if the animation is something different we know // that the movieclip is not playing it yet. if (animation != "run") { animation = "run"; gotoAndPlay(animation); } if (Key.isDown(Key.RIGHT)) { dir = true; _x += 10; return run; } else if (Key.isDown(Key.LEFT)) { dir = false; _x -= 10; return run; } // no key pressed, player stands return stand; } }