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

  1. class Game.Objects.BonusItem extends Engine.PongObject
  2. {
  3.    var itemIndex;
  4.    var __assetFrame;
  5.    var __direction;
  6.    var __speed;
  7.    var currentPos;
  8.    var target;
  9.    var __viewTimer;
  10.    var lastPos;
  11.    var motionVec;
  12.    var motionDist;
  13.    var motionDir;
  14.    var motionLeft;
  15.    var motionRight;
  16.    var motionTop;
  17.    var motionBottom;
  18.    var world;
  19.    var className = "BonusItem";
  20.    var assetID = "Item";
  21.    var depthShift = 3000;
  22.    static var itemID = 0;
  23.    var __fading = false;
  24.    function BonusItem(myIndex, myDirection, mySpeed)
  25.    {
  26.       super();
  27.       Game.Objects.BonusItem.itemID = Game.Objects.BonusItem.itemID + 1;
  28.       if(Game.Objects.BonusItem.itemID > 256)
  29.       {
  30.          Game.Objects.BonusItem.itemID = 0;
  31.       }
  32.       this.itemIndex = myIndex;
  33.       this.__assetFrame = myIndex + 1;
  34.       this.__direction = myDirection;
  35.       this.__speed = mySpeed;
  36.    }
  37.    function onAddToScene()
  38.    {
  39.       this.currentPos = new Vector(this.x,this.y,0);
  40.       this.width = this.target._width;
  41.       this.height = this.target._height;
  42.       this.target.gotoAndStop(this.__assetFrame);
  43.       this.target.swapDepths(this.depthShift * 61440 + Game.Objects.BonusItem.itemID);
  44.       this.getUpdates();
  45.    }
  46.    function onDisplay()
  47.    {
  48.       this.left = this.x;
  49.       this.right = this.x + this.width;
  50.       this.top = this.y;
  51.       this.bottom = this.y + this.height;
  52.    }
  53.    function update(elapsed)
  54.    {
  55.       this.calcNewPosBy(this.__direction.x * this.__speed * elapsed,this.__direction.y * this.__speed * elapsed);
  56.       if(this.__fading)
  57.       {
  58.          this.__viewTimer += elapsed;
  59.          if(this.__viewTimer < Engine.PongObject.FRAME_TIME)
  60.          {
  61.             return undefined;
  62.          }
  63.          this.__viewTimer = 0;
  64.          this.target._alpha -= 30;
  65.          if(this.target._alpha < 20)
  66.          {
  67.             this.target._visible = false;
  68.             this.cancelUpdates();
  69.             this.removeFromWorld();
  70.             return undefined;
  71.          }
  72.       }
  73.       else if(this.checkPaddles() || this.checkBounds())
  74.       {
  75.          this.__fading = true;
  76.          this.__viewTimer = 0;
  77.          this.target._alpha -= 30;
  78.       }
  79.       this.moveTo(this.currentPos.x,this.currentPos.y,0);
  80.    }
  81.    function calcNewPosTo(newX, newY, keepLastPos)
  82.    {
  83.       if(!keepLastPos)
  84.       {
  85.          this.lastPos = this.currentPos;
  86.       }
  87.       this.currentPos = new Vector(newX,newY,0);
  88.       this.calcNewMotionProps();
  89.    }
  90.    function calcNewPosBy(dx, dy, keepLastPos)
  91.    {
  92.       if(!keepLastPos)
  93.       {
  94.          this.lastPos = this.currentPos;
  95.       }
  96.       this.currentPos = new Vector(this.lastPos.x + dx,this.lastPos.y + dy,0);
  97.       this.calcNewMotionProps();
  98.    }
  99.    function calcNewMotionProps()
  100.    {
  101.       this.motionVec = new Vector(this.currentPos.x - this.lastPos.x,this.currentPos.y - this.lastPos.y,0);
  102.       this.motionDist = this.motionVec.length;
  103.       this.motionDir = this.motionVec.getNormalized();
  104.       this.motionLeft = Math.min(this.currentPos.x,this.lastPos.x);
  105.       this.motionRight = Math.max(this.currentPos.x,this.lastPos.x) + this.width;
  106.       this.motionTop = Math.min(this.currentPos.y,this.lastPos.y);
  107.       this.motionBottom = Math.max(this.currentPos.y,this.lastPos.y) + this.height;
  108.    }
  109.    function checkPaddles()
  110.    {
  111.       return this.world.checkPaddles(this);
  112.    }
  113.    function checkBounds()
  114.    {
  115.       return this.world.checkBounds(this);
  116.    }
  117. }
  118.