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

  1. class Game.Objects.Brick extends Game.Objects.CollisionObject
  2. {
  3.    var gridIndex;
  4.    var __type;
  5.    var __destroyTimer;
  6.    var target;
  7.    var depthShift = 1000;
  8.    var className = "Brick";
  9.    static var SOLID = Game.PongLevels.S;
  10.    static var DESTRUCTIBLE = Game.PongLevels.D;
  11.    var pointValue = 10;
  12.    var solidId = "BrickSolid";
  13.    var destructibleId = "BrickDestructible";
  14.    var __displayDelay = 0;
  15.    var __waitedTime = 0;
  16.    var __visible = true;
  17.    function Brick(myType, myData)
  18.    {
  19.       super();
  20.       if(myType == undefined)
  21.       {
  22.          this.type = Game.Objects.Brick.DESTRUCTIBLE;
  23.       }
  24.       if(myType != Game.Objects.Brick.SOLID && myType != Game.Objects.Brick.DESTRUCTIBLE)
  25.       {
  26.          this.type = Game.Objects.Brick.DESTRUCTIBLE;
  27.       }
  28.       this.type = myType;
  29.       if(myData.gridIndex != undefined)
  30.       {
  31.          this.gridIndex = myData.gridIndex;
  32.       }
  33.       if(myData.displayDelay != undefined)
  34.       {
  35.          this.__displayDelay = myData.displayDelay;
  36.          if(this.__displayDelay > 0)
  37.          {
  38.             this.__visible = false;
  39.          }
  40.       }
  41.    }
  42.    function set type(newType)
  43.    {
  44.       if(newType == undefined)
  45.       {
  46.          return;
  47.       }
  48.       if(newType == this.__type)
  49.       {
  50.          return;
  51.       }
  52.       if(newType != Game.Objects.Brick.SOLID && newType != Game.Objects.Brick.DESTRUCTIBLE)
  53.       {
  54.          return;
  55.       }
  56.       this.__type = newType;
  57.       if(newType == Game.Objects.Brick.SOLID)
  58.       {
  59.          this.setAssetID(this.solidId);
  60.       }
  61.       else
  62.       {
  63.          this.setAssetID(this.destructibleId);
  64.       }
  65.    }
  66.    function get type()
  67.    {
  68.       return this.__type;
  69.    }
  70.    function destroySelf(instant)
  71.    {
  72.       if(instant)
  73.       {
  74.          this.cancelUpdates();
  75.          this.removeFromWorld();
  76.          return undefined;
  77.       }
  78.       this.__destroyTimer = 0;
  79.       Engine.PongSFX.playBreakBrick();
  80.       this.target.nextFrame();
  81.       this.getUpdates();
  82.       this.queueForDisplay();
  83.    }
  84.    function onAddToScene()
  85.    {
  86.       this.target._visible = this.__visible;
  87.       if(!this.__visible)
  88.       {
  89.          this.getUpdates();
  90.       }
  91.       this.left = this.x;
  92.       this.right = this.x + this.target._width;
  93.       this.top = this.y;
  94.       this.bottom = this.y + this.target._height;
  95.       if(this.gridIndex != undefined)
  96.       {
  97.          this.target.swapDepths(this.depthShift * 61440 + this.gridIndex);
  98.       }
  99.       var _loc5_ = new _types_.ShapeVertex(0,0);
  100.       var _loc4_ = new _types_.ShapeVertex(this.target._width,0);
  101.       var _loc2_ = new _types_.ShapeVertex(this.target._width,this.target._height);
  102.       var _loc3_ = new _types_.ShapeVertex(0,this.target._height);
  103.       this.createEdges(_loc5_,_loc4_,_loc2_,_loc3_);
  104.    }
  105.    function onDisplay()
  106.    {
  107.       this.left = this.x;
  108.       this.right = this.x + this.target._width;
  109.       this.top = this.y;
  110.       this.bottom = this.y + this.target._height;
  111.       this.target._visible = this.__visible;
  112.    }
  113.    function update(elapsed)
  114.    {
  115.       if(this.__destroyTimer != undefined)
  116.       {
  117.          this.__destroyTimer += elapsed;
  118.          if(this.__destroyTimer < Engine.PongObject.FRAME_TIME)
  119.          {
  120.             return undefined;
  121.          }
  122.          this.target.nextFrame();
  123.          if(this.target._currentframe < this.target._totalframes)
  124.          {
  125.             this.queueForDisplay();
  126.             this.__destroyTimer -= Engine.PongObject.FRAME_TIME;
  127.          }
  128.          else
  129.          {
  130.             this.cancelUpdates();
  131.             this.removeFromWorld();
  132.          }
  133.          return undefined;
  134.       }
  135.       this.__waitedTime += elapsed;
  136.       if(this.__waitedTime >= this.__displayDelay)
  137.       {
  138.          this.__visible = true;
  139.          this.target._visible = true;
  140.          delete this.__waitedTime;
  141.          delete this.__displayDelay;
  142.          this.cancelUpdates();
  143.       }
  144.    }
  145. }
  146.