Advertisement
Jhynjhiruu

Untitled

May 4th, 2019
2,464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package com.nitrome.badicecream
  3. {
  4.    public class ChaserEnemy extends Enemy
  5.    {
  6.      
  7.       public static var chasingPlayerIndex:int;
  8.        
  9.      
  10.       public var chasingPlayer:Player = null;
  11.      
  12.       public var popupAnimation:Boolean = false;
  13.      
  14.       public var retractAnimation:Boolean = false;
  15.      
  16.       public var timer:Number = 0;
  17.      
  18.       public var followP2Next:Boolean;
  19.      
  20.       public var chasingPlayerIdx:int;
  21.      
  22.       public function ChaserEnemy()
  23.       {
  24.       }
  25.      
  26.       override public function create(param1:Number, param2:Number) : void
  27.       {
  28.          super.create(param1,param2);
  29.          this.chasingPlayerIdx = 0;
  30.       }
  31.      
  32.       private function colour(param1:Player) : Number
  33.       {
  34.          if(param1)
  35.          {
  36.             return param1.colour;
  37.          }
  38.          return 0;
  39.       }
  40.      
  41.       override public function update() : void
  42.       {
  43.          var _loc1_:* = undefined;
  44.          true.moveSpeed = Number(5.5);
  45.          §§push();
  46.          if(++this.timer > 3 * 60)
  47.          {
  48.             this.timer = 0;
  49.             if(this.chasingPlayer)
  50.             {
  51.                this.retractAnimation = true;
  52.             }
  53.             else
  54.             {
  55.                this.followP2Next.followP2Next = true;
  56.                this.chasingPlayerIdx++;
  57.                §§push(this);
  58.                if(this.chasingPlayerIdx >= Controller.level.playerList().length)
  59.                {
  60.                   this.chasingPlayerIdx = 0;
  61.                }
  62.                this.chasingPlayer = Controller.level.playerList()[this.chasingPlayerIdx];
  63.                _loc1_ = this.chasingPlayerIdx;
  64.                if(this.chasingPlayer.isDead())
  65.                {
  66.                   this.chasingPlayerIdx++;
  67.                   §§push(true);
  68.                }
  69.                chasingPlayerIndex = this.chasingPlayerIdx;
  70.                this.popupAnimation = true;
  71.             }
  72.             NitromeGame.sound_manager.playSound("change_flower");
  73.          }
  74.          randomWalk = !this.chasingPlayer;
  75.          if(!this.popupAnimation && !this.retractAnimation)
  76.          {
  77.             movement();
  78.             if(!this.chasingPlayer)
  79.             {
  80.                randomWalkUpdate();
  81.             }
  82.          }
  83.          this.frameControl();
  84.       }
  85.      
  86.       public function endAnimation() : void
  87.       {
  88.          if(this.retractAnimation)
  89.          {
  90.             this.chasingPlayer = null;
  91.          }
  92.          this.popupAnimation = false;
  93.          this.retractAnimation = false;
  94.       }
  95.      
  96.       override protected function stepped() : void
  97.       {
  98.          var _loc1_:Number = 0;
  99.          _loc1_ = this.bestChaseDirection();
  100.          if(_loc1_ && this.chasingPlayer)
  101.          {
  102.             randomWalk = false;
  103.             walk(_loc1_);
  104.          }
  105.          else
  106.          {
  107.             randomWalk = true;
  108.             moveDirection = 0;
  109.             randomWalkUpdate();
  110.          }
  111.       }
  112.      
  113.       protected function bestChaseDirection() : Number
  114.       {
  115.          var _loc3_:Number = NaN;
  116.          var _loc4_:* = NaN;
  117.          var _loc1_:Number = Infinity;
  118.          var _loc2_:Number = 0;
  119.          for each(_loc3_ in [LEFT,RIGHT,UP,DOWN])
  120.          {
  121.             if(checkWalkable(_loc3_))
  122.             {
  123.                _loc4_ = §§dup(Number(getRelativeTile(_loc3_).targetPlayerPathNum[chasingPlayerIndex]));
  124.                if(Number(getRelativeTile(_loc3_).targetPlayerPathNum[chasingPlayerIndex]) < _loc1_)
  125.                {
  126.                   _loc1_ = _loc4_;
  127.                   _loc2_ = _loc3_;
  128.                }
  129.             }
  130.          }
  131.          return _loc2_;
  132.       }
  133.      
  134.       override public function frameControl() : void
  135.       {
  136.          var _loc1_:Number = this.colour(this.chasingPlayer);
  137.          if(this.popupAnimation)
  138.          {
  139.             frameAction = "Popup" + _loc1_;
  140.          }
  141.          else if(this.retractAnimation)
  142.          {
  143.             frameAction = "Retract" + _loc1_;
  144.          }
  145.          else
  146.          {
  147.             frameAction = "Walk" + _loc1_;
  148.          }
  149.          if(moveDirection == LEFT)
  150.          {
  151.             frameAction = frameAction + "Left";
  152.          }
  153.          if(moveDirection == RIGHT)
  154.          {
  155.             frameAction = frameAction + "Right";
  156.          }
  157.          if(moveDirection == UP)
  158.          {
  159.             frameAction = frameAction + "Up";
  160.          }
  161.          if(moveDirection == DOWN)
  162.          {
  163.             frameAction = frameAction + "Down";
  164.          }
  165.          if(currentLabel != frameAction)
  166.          {
  167.             gotoAndStop(frameAction);
  168.          }
  169.       }
  170.    }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement