package com.arc.dh.entities { import com.arc.dh.state.HorizontalMode; import com.arc.dh.state.TadpoleMode; import com.arc.dh.util.Config; import com.arc.dh.util.Data; import com.arc.dh.util.Sound; import com.arc.dh.util.SoundSystem; import com.arc.flixel.ArcParticleSystem; import com.arc.flixel.ArcSprite; import com.arc.flixel.ArcU; import org.flixel.FlxG; import org.flixel.FlxSprite; public class Player extends Entity { public static const sprite:Class = Player_sprite; public static const shieldSprite:Class = Player_shieldSprite; private static const gunRightSprite:Class = Player_gunRightSprite; private static const gunUpSprite:Class = Player_gunUpSprite; private static const gunDownSprite:Class = Player_gunDownSprite; private static const dotSprite:Class = Player_dotSprite; private static const elevatorSprite:Class = Player_elevatorSprite; private static const JUMP_HOLD:Number = 0.2; private static const DOUBLE_JUMP_HOLD:Number = 0.03; private static const TRIPLE_JUMP_HOLD:Number = 0.03; private static const HIT_TIME:Number = 0.4; private static const BASE_MOVE_SPEED:Number = 80; private var JUMP_TIME:Array = [0.2,0.03,0.03]; private var _jump:Array = [0,0,0]; private var _jumping:Boolean = false; private var _doubleJumping:Boolean = false; private var _jumpTimer:Number = 0.2; private var _doubleJump:Number = 0.03; private var dots:Array = new Array(); private var dot:FlxSprite; private var _startheight:int = 0; private var _maxheight:int = 0; public var invulnerable:Number = 0; public var dashing:Number = 0; private var _canDash:Boolean = true; public var gun:String; private var _inWater:Number = 0; public var radians:Number; public var lastHitLava:Boolean = false; public var inHidden:int = 0; private var _lastRight:Number = 0; private var _lastLeft:Number = 0; private var hitTimer:Number = 0; private var gunDown:ArcSprite; private var gunRight:ArcSprite; private var gunUp:ArcSprite; private var _shieldSprite:ArcSprite; private var _shield:Number = 0; private var _shieldParticle:Number = 0.3; private var _shieldBlinkTimer:Number = 0; private var _xray:ArcSprite; private var i:int; private var j:int; public var hasGun:Boolean = true; public var elevator:ArcSprite; public var controllable:Boolean = true; public function Player(param1:Number, param2:Number) { this.gun = Data.gun; super(param1,param2); loadGraphic(sprite,true,true,16,24); offset.y = 10; height = 12; offset.x = 5; width = 6; drag.x = 400; acceleration.y = 600; var _loc3_:int = 0; while(_loc3_ < 50) { this.dot = new FlxSprite(0,0,dotSprite); this.dot.alpha = 0.8 - _loc3_ * 0.016; this.dots[_loc3_] = this.dot; _loc3_++; } addAnimation("walk",[0,1,2,3,4],7,true); addAnimation("stand",[6,7],4,true); addAnimation("jump",[5]); this.gunRight = new ArcSprite(); this.gunRight.loadGraphic(gunRightSprite,true,true,16,24); this.gunRight.offset.y = 10; this.gunRight.height = 12; this.gunRight.offset.x = 5; this.gunRight.width = 6; this.gunUp = new ArcSprite(); this.gunUp.loadGraphic(gunUpSprite,true,true,16,24); this.gunUp.offset.y = 10; this.gunUp.height = 12; this.gunUp.offset.x = 5; this.gunUp.width = 6; this.gunDown = new ArcSprite(); this.gunDown.loadGraphic(gunDownSprite,true,true,16,24); this.gunDown.offset.y = 10; this.gunDown.height = 12; this.gunDown.offset.x = 5; this.gunDown.width = 6; this._startheight = this._maxheight = y; new Date().getTime(); this._shieldSprite = new ArcSprite(0,0,shieldSprite); play("stand"); } public function get moveSpeed() : Number { return (BASE_MOVE_SPEED + Data.agility * 5) * (this._inWater > 0 ? 0.5 : 1); } public function get maxHeight() : int { return (this._maxheight - this._startheight) / -9; } private function pressedJump() : Boolean { return FlxG.keys.justPressed("W") && Data.control != Data.CONTROL_KEYBOARDI || FlxG.keys.justPressed("SPACE") || FlxG.keys.justPressed("Z") || FlxG.keys.justPressed("UP") && Data.control != Data.CONTROL_KEYBOARD; } private function pressingJump() : Boolean { return FlxG.keys.pressed("W") && Data.control != Data.CONTROL_KEYBOARDI || FlxG.keys.pressed("SPACE") || FlxG.keys.pressed("Z") || FlxG.keys.pressed("UP") && Data.control != Data.CONTROL_KEYBOARD; } override public function update() : void { var _loc1_:Array = null; var _loc2_:Number = NaN; var _loc3_:Number = NaN; var _loc4_:Number = NaN; if(Data.state.over) { alpha -= FlxG.elapsed; super.update(); return; } if(y < this._maxheight) { this._maxheight = y; } if(this._shield > 0) { this._shield -= FlxG.elapsed; this._shieldParticle -= FlxG.elapsed; if(this._shieldParticle <= 0) { ArcParticleSystem.emit(Data.state.particles,"rebound",getMidpoint().x,getMidpoint().y,1,1,0.5,0,-30,30,-30,30); this._shieldParticle = 0.1; } if(this._shield < 2) { this._shieldBlinkTimer -= FlxG.elapsed; if(this._shieldBlinkTimer <= 0) { this._shieldBlinkTimer = 0.1; if(this._shieldSprite.alpha == 1) { this._shieldSprite.alpha = 0.2; } else { this._shieldSprite.alpha = 1; } } } } if(Data.control == Data.CONTROL_MOUSE) { if(x < FlxG.mouse.x) { facing = RIGHT; } else { facing = LEFT; } } else if(Data.control == Data.CONTROL_KEYBOARD) { if(FlxG.keys.LEFT) { facing = LEFT; } else if(FlxG.keys.RIGHT) { facing = RIGHT; } else if(FlxG.keys.A) { facing = LEFT; } else if(FlxG.keys.D) { facing = RIGHT; } } else if(Data.control == Data.CONTROL_KEYBOARDI) { if(FlxG.keys.A) { facing = LEFT; } else if(FlxG.keys.D) { facing = RIGHT; } else if(FlxG.keys.LEFT) { facing = LEFT; } else if(FlxG.keys.RIGHT) { facing = RIGHT; } } if(this.hitTimer <= 0 && this.dashing <= 0 && this.controllable && !Data.state.xraying) { if(Data.state.controlCharacter) { if(FlxG.keys.D || FlxG.keys.RIGHT && Data.control == Data.CONTROL_MOUSE) { velocity.x = this.moveSpeed; } else if(FlxG.keys.A || FlxG.keys.LEFT && Data.control == Data.CONTROL_MOUSE) { velocity.x = -this.moveSpeed; } else { velocity.x = 0; } if(Data.control == Data.CONTROL_MOUSE) { if(FlxG.keys.D || FlxG.keys.RIGHT) { velocity.x = this.moveSpeed; } else if(FlxG.keys.A || FlxG.keys.LEFT) { velocity.x = -this.moveSpeed; } else { velocity.x = 0; } } else if(Data.control == Data.CONTROL_KEYBOARD) { if(FlxG.keys.D) { velocity.x = this.moveSpeed; } else if(FlxG.keys.A) { velocity.x = -this.moveSpeed; } else { velocity.x = 0; } } else if(Data.control == Data.CONTROL_KEYBOARDI) { if(FlxG.keys.RIGHT) { velocity.x = this.moveSpeed; } else if(FlxG.keys.LEFT) { velocity.x = -this.moveSpeed; } else { velocity.x = 0; } } } acceleration.y = 700; _loc1_ = [true,Data.skyboots == 1,Data.moonboots == 1]; this.i = 0; while(this.i < this._jump.length) { if(_loc1_[this.i]) { _loc2_ = Number(this._jump[this.i]); if(_loc2_ > 0) { if(this.pressedJump()) { this._jumping = true; SoundSystem.play(Sound["JUMP" + this.i],0.6); } if(this.pressingJump() && this._jumping) { this._jump[this.i] -= FlxG.elapsed; if(this._jump[this.i] <= 0 || isTouching(UP)) { this._jumping = false; } velocity.y = this._inWater > 0 ? -150 : -200; } else if(this._jumping) { this._jumping = false; _loc3_ = 1 - this._jump[this.i] / (this.JUMP_TIME[this.i] + Data.jump * 0.015); _loc4_ = _loc3_ * -100; if(_loc4_ > -50) { _loc4_ = -50; } if(velocity.y < _loc4_) { velocity.y = _loc4_; } this._jump[this.i] = 0; } else if(this._jump[this.i] != this.JUMP_TIME[this.i] + Data.jump * 0.01) { this._jump[this.i] = 0; } break; } } ++this.i; } if(!isTouching(DOWN) && !this.pressingJump()) { this._jump[0] = 0; } if(isTouching(DOWN)) { this.i = 0; while(this.i < this._jump.length) { this._jump[this.i] = this.JUMP_TIME[this.i] + Data.jump * 0.01; ++this.i; } } } else if(this.hitTimer > 0) { this.hitTimer -= FlxG.elapsed; } if(velocity.y != 0) { play("jump"); } else if(velocity.x != 0) { play("walk"); } else { play("stand"); } if(this._inWater > 0) { --this._inWater; drag.x = 600; acceleration.y = 100; if(velocity.y < 0) { maxVelocity.y = 400; } else { maxVelocity.y = 50; } } else { drag.x = 400; maxVelocity.y = 400; } --this.inHidden; super.update(); if(!(Data.state is HorizontalMode)) { if(x + width > FlxG.width) { x = FlxG.width - width; } } if(x < 0) { x = 0; } if(Data.hp > 0) { if(this.invulnerable > 0) { this.invulnerable -= FlxG.elapsed; alpha = 0.65; } else { alpha = 1; } } if(getScreenXY().y > Config.HEIGHT + height) { Data.hp = 0; Data.state.die(); } } override public function draw() : void { var _loc3_:ArcSprite = null; var _loc4_:Number = NaN; var _loc5_:Number = NaN; var _loc6_:int = 0; var _loc1_:Number = x + width / 2; var _loc2_:Number = y + height / 2; if(!this.controllable || Data.state.isComplete() || Data.state.inMenu) { this.radians = facing == LEFT ? (Number(this.radians = Math.PI)) : 0; } else if(Data.control == Data.CONTROL_MOUSE) { this.radians = Math.atan2(FlxG.mouse.y - _loc2_,FlxG.mouse.x - _loc1_); } else if(Data.control == Data.CONTROL_KEYBOARD) { if(FlxG.keys.LEFT && FlxG.keys.UP) { this.radians = 5 * Math.PI / 4; } else if(FlxG.keys.LEFT && FlxG.keys.DOWN) { this.radians = 3 * Math.PI / 4; } else if(FlxG.keys.LEFT) { this.radians = 4 * Math.PI / 4; } else if(FlxG.keys.RIGHT && FlxG.keys.UP) { this.radians = 7 * Math.PI / 4; } else if(FlxG.keys.RIGHT && FlxG.keys.DOWN) { this.radians = 1 * Math.PI / 4; } else if(FlxG.keys.RIGHT) { this.radians = 0; } else if(FlxG.keys.DOWN) { this.radians = 2 * Math.PI / 4; } else if(FlxG.keys.UP) { this.radians = 6 * Math.PI / 4; } else if(facing == LEFT) { this.radians = 4 * Math.PI / 4; } else if(facing == RIGHT) { this.radians = 0; } } else if(Data.control == Data.CONTROL_KEYBOARDI) { if(FlxG.keys.A && FlxG.keys.W) { this.radians = 5 * Math.PI / 4; } else if(FlxG.keys.A && FlxG.keys.S) { this.radians = 3 * Math.PI / 4; } else if(FlxG.keys.A) { this.radians = 4 * Math.PI / 4; } else if(FlxG.keys.D && FlxG.keys.W) { this.radians = 7 * Math.PI / 4; } else if(FlxG.keys.D && FlxG.keys.S) { this.radians = 1 * Math.PI / 4; } else if(FlxG.keys.D) { this.radians = 0; } else if(FlxG.keys.S) { this.radians = 2 * Math.PI / 4; } else if(FlxG.keys.W) { this.radians = 6 * Math.PI / 4; } else if(facing == LEFT) { this.radians = 4 * Math.PI / 4; } else if(facing == RIGHT) { this.radians = 0; } } if(!Data.state.inMenu && Data.lasersight == 1 && Data.hp > 0 && this.controllable && Data.control == Data.CONTROL_MOUSE && !Data.state.isComplete()) { _loc4_ = 8 * Math.cos(this.radians); _loc5_ = 8 * Math.sin(this.radians); _loc6_ = 0; while(_loc6_ < 50) { this.dots[_loc6_].x = x + width / 2 + _loc4_ * _loc6_; this.dots[_loc6_].y = y + height / 2 + _loc5_ * _loc6_; this.dots[_loc6_].draw(); _loc6_++; } } super.draw(); if(this.radians <= -0.4 && this.radians > -2.74 || this.radians > 3.9) { _loc3_ = this.gunUp; } else if(this.radians >= 0.4 && this.radians < 2.74) { _loc3_ = this.gunDown; } else { _loc3_ = this.gunRight; } _loc3_.x = x; _loc3_.y = y; _loc3_.frame = frame; _loc3_.facing = facing; _loc3_.alpha = alpha; if(Boolean(Data.prime) && this.hasGun) { _loc3_.draw(); } if(this.shielded && Data.hp > 0) { this._shieldSprite.x = x - 7; this._shieldSprite.y = y - 7; this._shieldSprite.draw(); } if(this.elevator != null) { this.elevator.x = getMidpoint().x - 30; this.elevator.y = y + height; this.elevator.draw(); } if(Data.state.xraying) { Data.state.xray.x = x + 3; Data.state.xray.y = y + 6; Data.state.xray.angle = this.radians * 180 / Math.PI; } } public function hit(param1:int, param2:Boolean = false, param3:Boolean = true, param4:Boolean = true, param5:Boolean = false) : Boolean { var _loc6_:int = 0; if(this.invulnerable > 0 && !param2 || Data.hp <= 0) { return false; } this.lastHitLava = param5; if(param4) { this.hitTimer = HIT_TIME - Data.recover * 0.05; } this.invulnerable = 1 + 0.15 * Data.aegis; if(param3) { _loc6_ = ArcU.clamp(Math.min(1 + Math.floor(param1 / 6),param5 ? 16 : 12) - Data.defense,1,19); if(param1 > 50) { _loc6_ = ArcU.clamp(_loc6_ - 2,1,19); } else if(param1 > 40) { _loc6_ = ArcU.clamp(_loc6_ - 1,1,19); } Data.hp -= _loc6_; SoundSystem.play(Sound.HURT); } if(Data.hp <= 0) { this.kill(); } return true; } override public function kill() : void { Data.hp = 0; Data.state.die(); SoundSystem.play(Sound.PLAYER_DIE); } public function get isHit() : Boolean { return this.hitTimer > 0; } public function shield(param1:Number) : void { this._shield = Data.state is TadpoleMode ? 5 : param1; this._shieldSprite.alpha = 1; } public function get shielded() : Boolean { return this._shield > 0; } public function inWater() : void { this._inWater = 3; } public function inLava() : void { this.hit(10); } override public function reset(param1:Number, param2:Number) : void { super.reset(param1,param2); this.hitTimer = 0; this._shield = 0; this._inWater = 0; this.invulnerable = 0; alpha = 1; } public function showElevator() : void { this.elevator = new ArcSprite(0,0,elevatorSprite); } public function drawShield(param1:Number, param2:Number) : void { this._shieldSprite.x = param1 + 2; this._shieldSprite.y = param2 + 3; this._shieldSprite.draw(); } } }