Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import net.flashpunk.Entity;
- import net.flashpunk.utils.Draw;
- public class Solid extends Entity
- {
- static private var holder:Vector.<Actor> = new Vector.<Actor>;
- private var hCounter:Number = 0;
- private var vCounter:Number = 0;
- public function Solid(x:Number, y:Number, width:Number, height:Number)
- {
- super(x, y);
- setHitbox(width, height);
- type = "Solid";
- }
- override public function render():void
- {
- super.render();
- Draw.hitbox(this, false);
- }
- public function solidMoveExactH(amount:int):void
- {
- var i:int;
- collidable = false;
- holder.length = 0;
- collideInto("Actor", x + amount, y, holder);
- if (amount > 0)
- {
- for (i = 0; i < holder.length; i++)
- holder[i].moveExactH(amount - (holder[i].left - right), holder[i].squish);
- }
- else if (amount < 0)
- {
- for (i = 0; i < holder.length; i++)
- holder[i].moveExactH(amount - (holder[i].right - left), holder[i].squish);
- }
- holder.length = 0;
- collideInto("Actor", x, y - 1, holder);
- for (i = 0; i < holder.length; i++)
- holder[i].moveExactH(amount);
- collidable = true;
- x += amount;
- }
- public function solidMoveExactV(amount:int):void
- {
- var i:int;
- collidable = false;
- holder.length = 0;
- collideInto("Actor", x, y + amount, holder);
- if (amount > 0)
- {
- for (i = 0; i < holder.length; i++)
- holder[i].moveExactV(amount - (holder[i].top - bottom), holder[i].squish);
- holder.length = 0;
- collideInto("Actor", x, y - 1, holder);
- for (i = 0; i < holder.length; i++)
- holder[i].moveExactV(amount);
- }
- else if (amount < 0)
- {
- for (i = 0; i < holder.length; i++)
- {
- if (holder[i].bottom < top)
- holder[i].platformCatch();
- holder[i].moveExactV(amount - (holder[i].bottom - top), holder[i].squish);
- }
- }
- collidable = true;
- y += amount;
- }
- public function solidMove(h:Number, v:Number):void
- {
- hCounter += h;
- var move:int = Math.round(hCounter);
- if (move != 0)
- {
- hCounter -= move;
- solidMoveExactH(move);
- }
- vCounter += v;
- move = Math.round(vCounter);
- if (move != 0)
- {
- vCounter -= move;
- solidMoveExactV(move);
- }
- }
- public function solidMoveTo(toX:Number, toY:Number):void
- {
- solidMove(toX - (x + hCounter), toY - (y + vCounter));
- }
- public function get actualX():Number { return x + hCounter; }
- public function get actualY():Number { return y + vCounter; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement