Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lib.shoot.entity
- {
- import flash.display.MovieClip;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- import flash.ui.Keyboard;
- import flash.events.Event;
- import fl.motion.Color;
- import lib.shoot.InputManager;
- import lib.shoot.MathHelper;
- import lib.shoot.Quadrilateral;
- import lib.shoot.entity.states.PlayerStateGround;
- import lib.shoot.entity.states.PlayerStateDead;
- import lib.shoot.entity.states.PlayerStateDodge;
- public class EntityPlayer extends Entity
- {
- private var invulnTimer:Timer;
- private var dodgeTimer:Timer;
- private var canDodge:Boolean;
- public function EntityPlayer()
- {
- this.healthMax = 3;
- this.health = 3;
- this.canDodge = true;
- this.abilities.push(Ability.STOMP);
- this.abilities.push(Ability.BOUNCEBACK);
- this.setState(new PlayerStateGround());
- }
- public override function update():void
- {
- // Noclip movement
- if(!this.physicsEnabled && !this.isDead)
- {
- if(InputManager.isKeyDown(Keyboard.LEFT))
- {
- this.posX -= 3;
- }
- if(InputManager.isKeyDown(Keyboard.RIGHT))
- {
- this.posX += 3;
- }
- if(InputManager.isKeyDown(Keyboard.UP))
- {
- this.posY -= 3;
- }
- if(InputManager.isKeyDown(Keyboard.DOWN))
- {
- this.posY += 3;
- }
- }
- super.update();
- }
- public override function getBoundingBox():Quadrilateral
- {
- return this.boundingBox.fromPositionAndSize(this.posX - (this.direction == -1 ? 38 : 0), this.posY, 38, 50);
- }
- public override function getBoundingBoxPrev():Quadrilateral
- {
- return this.boundingBoxPrev.fromPositionAndSize(this.posXPrev - (this.direction == -1 ? 38 : 0), this.posYPrev, 38, 50);
- }
- public override function onAttacked(attacker:Entity):void
- {
- if(!this.isInvulnerable)
- {
- this.health--;
- this.setState(new PlayerStateDodge());
- }
- if(this.health <= 0)
- {
- this.setState(new PlayerStateDead());
- }
- }
- public override function setInvulnverable(invulnerable:Boolean):void
- {
- if(!this.isInvulnerable)
- {
- this.isInvulnerable = invulnerable;
- var invulnTimeSeconds:Number = 1;
- var invlinTicksPerSecond:Number = 64;
- this.invulnTimer = new Timer((invulnTimeSeconds / invlinTicksPerSecond) * 1000, invulnTimeSeconds * invlinTicksPerSecond);
- this.invulnTimer.addEventListener(TimerEvent.TIMER, onInvulnTimerTick);
- this.invulnTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onInvulnTimerEnd);
- this.onInvulnTimerTick(null);
- this.invulnTimer.start();
- }
- }
- private function onInvulnTimerTick(evt:TimerEvent):void
- {
- if(this.invulnTimer.running)
- {
- if(this.alpha < 1)
- {
- this.alpha = 1;
- }
- else
- {
- this.alpha = 0.25;
- }
- }
- }
- private function onInvulnTimerEnd(evt:TimerEvent):void
- {
- this.isInvulnerable = false;
- this.transform.colorTransform.alphaMultiplier = 1;
- }
- public function onDodge():void
- {
- if(!this.onGround)
- {
- this.canDodge = false;
- var dodgeTimeSeconds:Number = 1;
- var dodgeTicksPerSecond:Number = 1;
- this.dodgeTimer = new Timer((dodgeTimeSeconds / dodgeTicksPerSecond) * 1000, dodgeTimeSeconds * dodgeTicksPerSecond);
- this.dodgeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onDodgeTimerEnd);
- this.dodgeTimer.start();
- }
- }
- private function onDodgeTimerEnd(evt:TimerEvent):void
- {
- this.canDodge = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement