Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import net.flashpunk.Entity;
- public class Actor extends Entity
- {
- private var hCounter:Number = 0;
- private var vCounter:Number = 0;
- public function Actor(x:Number = 0, y:Number = 0)
- {
- super(x, y);
- type = "Actor";
- }
- public function moveExactH(amount:int, onCollide:Function = null):void
- {
- var sign:int = amount > 0 ? 1 : -1;
- while (amount != 0)
- {
- if (collide("Solid", x + sign, y) != null)
- {
- if (onCollide != null)
- onCollide();
- return;
- }
- x += sign;
- amount -= sign;
- }
- }
- public function moveExactV(amount:int, onCollide:Function = null):void
- {
- var sign:int = amount > 0 ? 1 : -1;
- while (amount != 0)
- {
- if (collide("Solid", x, y + sign) != null)
- {
- if (onCollide != null)
- onCollide();
- return;
- }
- y += sign;
- amount -= sign;
- }
- }
- public function moveH(amount:Number, onCollide:Function = null):void
- {
- hCounter += amount;
- var move:int = Math.round(hCounter);
- if (move != 0)
- {
- hCounter -= move;
- moveExactH(move, onCollide);
- }
- }
- public function moveV(amount:Number, onCollide:Function = null):void
- {
- vCounter += amount;
- var move:int = Math.round(vCounter);
- if (move != 0)
- {
- vCounter -= move;
- moveExactV(move, onCollide);
- }
- }
- public function snapH():void { hCounter = 0; }
- public function snapV():void { vCounter = 0; }
- public function get actualX():Number { return x + hCounter; }
- public function get actualY():Number { return y + vCounter; }
- public function set left(to:Number):void { x = to + originX; }
- public function set right(to:Number):void { x = to + originX - width; }
- public function set top(to:Number):void { y = to + originY; }
- public function set bottom(to:Number):void { y = to + originY - height; }
- /*
- * Called when a solid pushes this actor into another solid.
- * This would be a good time to remove the actor from the world,
- * because it will now be inside of a solid.
- */
- public function squish():void
- {
- //Override me!
- }
- /*
- * Called when an upward-moving solid "catches" the actor as it moves up.
- * This is usually when you set the actor's vertical speed to zero
- * if she is moving upward, to avoid jitter.
- */
- public function platformCatch():void
- {
- //Override me!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement