Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nitrome.badicecream
- {
- public class ChaserEnemy extends Enemy
- {
- public static var chasingPlayerIndex:int;
- public var chasingPlayer:Player = null;
- public var popupAnimation:Boolean = false;
- public var retractAnimation:Boolean = false;
- public var timer:Number = 0;
- public var followP2Next:Boolean;
- public var chasingPlayerIdx:int;
- public function ChaserEnemy()
- {
- }
- override public function create(param1:Number, param2:Number) : void
- {
- super.create(param1,param2);
- this.chasingPlayerIdx = 0;
- }
- private function colour(param1:Player) : Number
- {
- if(param1)
- {
- return param1.colour;
- }
- return 0;
- }
- override public function update() : void
- {
- var _loc1_:* = undefined;
- true.moveSpeed = Number(5.5);
- §§push();
- if(++this.timer > 3 * 60)
- {
- this.timer = 0;
- if(this.chasingPlayer)
- {
- this.retractAnimation = true;
- }
- else
- {
- this.followP2Next.followP2Next = true;
- this.chasingPlayerIdx++;
- §§push(this);
- if(this.chasingPlayerIdx >= Controller.level.playerList().length)
- {
- this.chasingPlayerIdx = 0;
- }
- this.chasingPlayer = Controller.level.playerList()[this.chasingPlayerIdx];
- _loc1_ = this.chasingPlayerIdx;
- if(this.chasingPlayer.isDead())
- {
- this.chasingPlayerIdx++;
- §§push(true);
- }
- chasingPlayerIndex = this.chasingPlayerIdx;
- this.popupAnimation = true;
- }
- NitromeGame.sound_manager.playSound("change_flower");
- }
- randomWalk = !this.chasingPlayer;
- if(!this.popupAnimation && !this.retractAnimation)
- {
- movement();
- if(!this.chasingPlayer)
- {
- randomWalkUpdate();
- }
- }
- this.frameControl();
- }
- public function endAnimation() : void
- {
- if(this.retractAnimation)
- {
- this.chasingPlayer = null;
- }
- this.popupAnimation = false;
- this.retractAnimation = false;
- }
- override protected function stepped() : void
- {
- var _loc1_:Number = 0;
- _loc1_ = this.bestChaseDirection();
- if(_loc1_ && this.chasingPlayer)
- {
- randomWalk = false;
- walk(_loc1_);
- }
- else
- {
- randomWalk = true;
- moveDirection = 0;
- randomWalkUpdate();
- }
- }
- protected function bestChaseDirection() : Number
- {
- var _loc3_:Number = NaN;
- var _loc4_:* = NaN;
- var _loc1_:Number = Infinity;
- var _loc2_:Number = 0;
- for each(_loc3_ in [LEFT,RIGHT,UP,DOWN])
- {
- if(checkWalkable(_loc3_))
- {
- _loc4_ = §§dup(Number(getRelativeTile(_loc3_).targetPlayerPathNum[chasingPlayerIndex]));
- if(Number(getRelativeTile(_loc3_).targetPlayerPathNum[chasingPlayerIndex]) < _loc1_)
- {
- _loc1_ = _loc4_;
- _loc2_ = _loc3_;
- }
- }
- }
- return _loc2_;
- }
- override public function frameControl() : void
- {
- var _loc1_:Number = this.colour(this.chasingPlayer);
- if(this.popupAnimation)
- {
- frameAction = "Popup" + _loc1_;
- }
- else if(this.retractAnimation)
- {
- frameAction = "Retract" + _loc1_;
- }
- else
- {
- frameAction = "Walk" + _loc1_;
- }
- if(moveDirection == LEFT)
- {
- frameAction = frameAction + "Left";
- }
- if(moveDirection == RIGHT)
- {
- frameAction = frameAction + "Right";
- }
- if(moveDirection == UP)
- {
- frameAction = frameAction + "Up";
- }
- if(moveDirection == DOWN)
- {
- frameAction = frameAction + "Down";
- }
- if(currentLabel != frameAction)
- {
- gotoAndStop(frameAction);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement