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

  1. class Game.Objects.BonusPointsItem extends Engine.PongObject
  2. {
  3.    var itemIndex;
  4.    var __assetFrame;
  5.    var __direction;
  6.    var __points;
  7.    var currentPos;
  8.    var target;
  9.    var __viewTimer;
  10.    var lastPos;
  11.    var className = "BonusPointItem";
  12.    var assetID = "Item";
  13.    var __speed = 30;
  14.    var depthShift = 4000;
  15.    static var itemID = 0;
  16.    var __fading = false;
  17.    var __waitFrame = 0;
  18.    function BonusPointsItem(myIndex, myDirection, myPoints)
  19.    {
  20.       super();
  21.       Game.Objects.BonusPointsItem.itemID = Game.Objects.BonusPointsItem.itemID + 1;
  22.       if(Game.Objects.BonusPointsItem.itemID > 256)
  23.       {
  24.          Game.Objects.BonusPointsItem.itemID = 0;
  25.       }
  26.       this.itemIndex = myIndex;
  27.       this.__assetFrame = myIndex + 1;
  28.       this.__direction = myDirection;
  29.       this.__points = myPoints;
  30.    }
  31.    function onAddToScene()
  32.    {
  33.       this.currentPos = new Vector(0,0,0);
  34.       this.width = this.target._width;
  35.       this.height = this.target._height;
  36.       this.target.gotoAndStop(this.__assetFrame);
  37.       this.target.swapDepths(this.depthShift * 61440 + Game.Objects.BonusPointsItem.itemID);
  38.       var _loc6_ = undefined;
  39.       var _loc2_ = this.target.points_mc;
  40.       if(this.__points < 0)
  41.       {
  42.          _loc2_.gotoAndStop(1);
  43.          _loc2_.points_txt.text = - this.__points;
  44.       }
  45.       else
  46.       {
  47.          _loc2_.gotoAndStop(3);
  48.          _loc2_.points_txt.text = this.__points;
  49.       }
  50.       var _loc3_ = _loc2_.points_txt;
  51.       _loc3_.autoSize = "left";
  52.       var _loc5_ = Math.ceil(_loc3_._width);
  53.       var _loc4_ = Math.ceil(_loc3_.textWidth);
  54.       _loc2_.fill_mc._width = _loc4_;
  55.       _loc2_.frame_mc._width = _loc4_ + 2;
  56.       this.getUpdates();
  57.    }
  58.    function onDisplay()
  59.    {
  60.       this.left = this.x;
  61.       this.right = this.x + this.width;
  62.       this.top = this.y;
  63.       this.bottom = this.y + this.height;
  64.    }
  65.    function update(elapsed)
  66.    {
  67.       this.calcNewPosBy(this.__direction.x * this.__speed * elapsed,this.__direction.y * this.__speed * elapsed);
  68.       this.target.points_mc._y = this.currentPos.y;
  69.       this.__viewTimer += elapsed;
  70.       if(this.__viewTimer < Engine.PongObject.FRAME_TIME)
  71.       {
  72.          return undefined;
  73.       }
  74.       this.__viewTimer = 0;
  75.       this.__waitFrame = this.__waitFrame + 1;
  76.       if(this.__fading)
  77.       {
  78.          this.target._alpha -= 20;
  79.          if(this.target._alpha < 10)
  80.          {
  81.             this.target._visible = false;
  82.             this.target._xscale = this.target._yscale = 1;
  83.             this.target._alpha = 10;
  84.             this.cancelUpdates();
  85.             this.removeFromWorld();
  86.             return undefined;
  87.          }
  88.       }
  89.       else if(this.__waitFrame > 4)
  90.       {
  91.          this.__fading = true;
  92.          this.target._alpha -= 30;
  93.       }
  94.    }
  95.    function calcNewPosBy(dx, dy, keepLastPos)
  96.    {
  97.       if(!keepLastPos)
  98.       {
  99.          this.lastPos = this.currentPos;
  100.       }
  101.       this.currentPos = new Vector(this.lastPos.x + dx,this.lastPos.y + dy,0);
  102.    }
  103. }
  104.