home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / smashout.swf / scripts / __Packages / Engine / PongPlayer.as < prev    next >
Encoding:
Text File  |  2005-11-09  |  3.2 KB  |  116 lines

  1. class Engine.PongPlayer
  2. {
  3.    var world;
  4.    var __paddle;
  5.    var __ball;
  6.    var __goal;
  7.    var side;
  8.    var onUpdate;
  9.    var __activeItem;
  10.    var __activeItemID;
  11.    var __itemActiveTime;
  12.    var __frameElapsedTime;
  13.    var __itemTime;
  14.    var __itemBlinkTime;
  15.    var className = "PongPlayer";
  16.    static var SPEED = Game.PongLevels.PADDLE_SPEED;
  17.    var __handicap = 0;
  18.    var __speed = Game.PongLevels.PADDLE_SPEED;
  19.    static var FRAME_TIME = Game.PongLevels.FRAME_TIME;
  20.    var __holdingBall = false;
  21.    function PongPlayer(myWorld, myPaddle, myBall, myGoal, mySide)
  22.    {
  23.       this.world = myWorld;
  24.       this.__paddle = myPaddle;
  25.       this.__paddle.addEventListener("onHoldBall",this);
  26.       this.__paddle.addEventListener("onReleaseBall",this);
  27.       this.__ball = myBall;
  28.       this.__goal = myGoal;
  29.       this.side = mySide;
  30.    }
  31.    function update(elapsed)
  32.    {
  33.       this.checkActiveItem(elapsed);
  34.       this.onUpdate(elapsed);
  35.    }
  36.    function activateItem(itemObj, itemID, time, blinkTime)
  37.    {
  38.       var _loc3_ = this.__activeItem == itemObj && this.__activeItemID == itemID;
  39.       if(_loc3_)
  40.       {
  41.          this.__itemActiveTime = 0;
  42.          this.__frameElapsedTime = 0;
  43.          return undefined;
  44.       }
  45.       this.deactivateItem();
  46.       this.__itemActiveTime = 0;
  47.       this.__frameElapsedTime = 0;
  48.       this.__activeItem = itemObj;
  49.       this.__activeItemID = itemID;
  50.       this.__itemTime = time;
  51.       this.__itemBlinkTime = blinkTime;
  52.       itemObj.activateItem(itemID);
  53.       this.world.dispatchEvent({type:"onActivateItem",itemID:this.__activeItemID,who:this.side});
  54.    }
  55.    function deactivateItem()
  56.    {
  57.       this.world.dispatchEvent({type:"onActivateItem",itemID:-1,who:this.side});
  58.       if(this.__activeItem == undefined)
  59.       {
  60.          return undefined;
  61.       }
  62.       this.__activeItem.deactivateItem();
  63.       delete this.__activeItem;
  64.       delete this.__activeItemID;
  65.       delete this.__itemTime;
  66.       delete this.__itemBlinkTime;
  67.       delete this.__itemActiveTime;
  68.       delete this.__frameElapsedTime;
  69.    }
  70.    function onHoldBall(eventObj)
  71.    {
  72.       this.__holdingBall = true;
  73.    }
  74.    function onReleaseBall(eventObj)
  75.    {
  76.       this.__holdingBall = false;
  77.       this.deactivateItem();
  78.    }
  79.    function toString()
  80.    {
  81.       return this.className;
  82.    }
  83.    function set handicap(newValue)
  84.    {
  85.       this.__handicap = newValue;
  86.       this.__speed = Engine.PongPlayer.SPEED - this.__handicap;
  87.    }
  88.    function get handicap()
  89.    {
  90.       return this.__handicap;
  91.    }
  92.    function checkActiveItem(elapsed)
  93.    {
  94.       if(this.__activeItem == null)
  95.       {
  96.          return undefined;
  97.       }
  98.       this.__itemActiveTime += elapsed;
  99.       if(this.__itemActiveTime >= this.__itemTime)
  100.       {
  101.          this.deactivateItem();
  102.          return undefined;
  103.       }
  104.       var _loc2_ = this.__itemTime - this.__itemActiveTime;
  105.       if(_loc2_ <= this.__itemBlinkTime)
  106.       {
  107.          this.__frameElapsedTime += elapsed;
  108.          if(this.__frameElapsedTime >= Engine.PongPlayer.FRAME_TIME * 2)
  109.          {
  110.             this.__frameElapsedTime = 0;
  111.             this.world.dispatchEvent({type:"onBlinkItem",who:this.side});
  112.          }
  113.       }
  114.    }
  115. }
  116.