home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / smashout.swf / scripts / __Packages / Game / Players / ComputerPlayer.as next >
Encoding:
Text File  |  2005-11-09  |  3.4 KB  |  133 lines

  1. class Game.Players.ComputerPlayer extends Engine.PongPlayer
  2. {
  3.    var __paddle;
  4.    var __ball;
  5.    var __goal;
  6.    var side;
  7.    var __handicap = Game.PongLevels.DEFAULT_COMPUTER_HANDICAP;
  8.    var __waitTime = 0;
  9.    var className = "ComputerPlayer";
  10.    function ComputerPlayer(myWorld, myPaddle, myBall, myGoal, mySide)
  11.    {
  12.       super(myWorld,myPaddle,myBall,myGoal,mySide);
  13.       this.__speed = Engine.PongPlayer.SPEED - this.__handicap;
  14.    }
  15.    function onUpdate(elapsed)
  16.    {
  17.       var _loc5_ = elapsed * this.__speed;
  18.       var _loc4_ = this.__paddle.bounds;
  19.       var _loc6_ = this.__paddle.y;
  20.       var _loc2_ = undefined;
  21.       if(!this.__holdingBall)
  22.       {
  23.          _loc2_ = this.__ball.y;
  24.          if(this.ballOnOtherSide())
  25.          {
  26.             _loc2_ = this.__ball.y;
  27.             if(_loc2_ < this.__goal.top)
  28.             {
  29.                _loc2_ = this.__goal.top;
  30.             }
  31.             else if(_loc2_ > this.__goal.bottom)
  32.             {
  33.                _loc2_ = this.__goal.bottom;
  34.             }
  35.          }
  36.          else if(this.ballBehindPaddle())
  37.          {
  38.             _loc2_ = _loc4_.vCenter;
  39.          }
  40.          else if(this.ballAbovePaddle())
  41.          {
  42.             if(this.ballInHitArea())
  43.             {
  44.                _loc2_ = _loc4_.yMin + this.__paddle.width / 2 + this.__ball.radius * 3;
  45.             }
  46.             else if(this.__ball.direction.y > 0)
  47.             {
  48.             }
  49.          }
  50.          else if(this.ballBelowPaddle())
  51.          {
  52.             if(this.ballInHitArea())
  53.             {
  54.                _loc2_ = _loc4_.yMax - this.__paddle.width / 2 - this.__ball.radius * 3;
  55.             }
  56.             else if(this.__ball.direction.y < 0)
  57.             {
  58.             }
  59.          }
  60.       }
  61.       else
  62.       {
  63.          _loc2_ = _loc4_.vCenter;
  64.       }
  65.       var _loc3_ = _loc2_ - _loc6_;
  66.       if(this.__holdingBall)
  67.       {
  68.          this.__waitTime += elapsed;
  69.          if(Math.abs(_loc3_) <= 10 && this.__waitTime >= Engine.PongPlayer.FRAME_TIME * 5)
  70.          {
  71.             this.__paddle.releaseBall();
  72.             delete this.__waitTime;
  73.          }
  74.       }
  75.       if(_loc3_ < 0)
  76.       {
  77.          _loc3_ = - Math.min(- _loc3_,_loc5_);
  78.       }
  79.       else
  80.       {
  81.          _loc3_ = Math.min(_loc3_,_loc5_);
  82.       }
  83.       this.__paddle.moveByPlayer(_loc3_,this.__ball);
  84.    }
  85.    function onHoldBall(eventObj)
  86.    {
  87.       this.__waitTime = 0;
  88.       this.__holdingBall = true;
  89.    }
  90.    function ballInHitArea()
  91.    {
  92.       return this.__paddle.ballInHitArea(this.__ball);
  93.    }
  94.    function ballAbovePaddle()
  95.    {
  96.       return this.__paddle.ballAbovePaddle(this.__ball);
  97.    }
  98.    function ballBelowPaddle()
  99.    {
  100.       return this.__paddle.ballBelowPaddle(this.__ball);
  101.    }
  102.    function ballBehindPaddle()
  103.    {
  104.       if(this.side == Engine.PongObject.RIGHT_DIR)
  105.       {
  106.          if(this.__paddle.right < this.__ball.left)
  107.          {
  108.             return true;
  109.          }
  110.       }
  111.       else if(this.__ball.right < this.__paddle.left)
  112.       {
  113.          return true;
  114.       }
  115.       return false;
  116.    }
  117.    function ballOnOtherSide()
  118.    {
  119.       if(this.side == Engine.PongObject.RIGHT_DIR)
  120.       {
  121.          if(this.__ball.right < this.__paddle.bounds.hCenter)
  122.          {
  123.             return true;
  124.          }
  125.       }
  126.       else if(this.__paddle.bounds.hCenter < this.__ball.left)
  127.       {
  128.          return true;
  129.       }
  130.       return false;
  131.    }
  132. }
  133.