home *** CD-ROM | disk | FTP | other *** search
- class Game.Objects.Brick extends Game.Objects.CollisionObject
- {
- var gridIndex;
- var __type;
- var __destroyTimer;
- var target;
- var depthShift = 1000;
- var className = "Brick";
- static var SOLID = Game.PongLevels.S;
- static var DESTRUCTIBLE = Game.PongLevels.D;
- var pointValue = 10;
- var solidId = "BrickSolid";
- var destructibleId = "BrickDestructible";
- var __displayDelay = 0;
- var __waitedTime = 0;
- var __visible = true;
- function Brick(myType, myData)
- {
- super();
- if(myType == undefined)
- {
- this.type = Game.Objects.Brick.DESTRUCTIBLE;
- }
- if(myType != Game.Objects.Brick.SOLID && myType != Game.Objects.Brick.DESTRUCTIBLE)
- {
- this.type = Game.Objects.Brick.DESTRUCTIBLE;
- }
- this.type = myType;
- if(myData.gridIndex != undefined)
- {
- this.gridIndex = myData.gridIndex;
- }
- if(myData.displayDelay != undefined)
- {
- this.__displayDelay = myData.displayDelay;
- if(this.__displayDelay > 0)
- {
- this.__visible = false;
- }
- }
- }
- function set type(newType)
- {
- if(newType == undefined)
- {
- return;
- }
- if(newType == this.__type)
- {
- return;
- }
- if(newType != Game.Objects.Brick.SOLID && newType != Game.Objects.Brick.DESTRUCTIBLE)
- {
- return;
- }
- this.__type = newType;
- if(newType == Game.Objects.Brick.SOLID)
- {
- this.setAssetID(this.solidId);
- }
- else
- {
- this.setAssetID(this.destructibleId);
- }
- }
- function get type()
- {
- return this.__type;
- }
- function destroySelf(instant)
- {
- if(instant)
- {
- this.cancelUpdates();
- this.removeFromWorld();
- return undefined;
- }
- this.__destroyTimer = 0;
- Engine.PongSFX.playBreakBrick();
- this.target.nextFrame();
- this.getUpdates();
- this.queueForDisplay();
- }
- function onAddToScene()
- {
- this.target._visible = this.__visible;
- if(!this.__visible)
- {
- this.getUpdates();
- }
- this.left = this.x;
- this.right = this.x + this.target._width;
- this.top = this.y;
- this.bottom = this.y + this.target._height;
- if(this.gridIndex != undefined)
- {
- this.target.swapDepths(this.depthShift * 61440 + this.gridIndex);
- }
- var _loc5_ = new _types_.ShapeVertex(0,0);
- var _loc4_ = new _types_.ShapeVertex(this.target._width,0);
- var _loc2_ = new _types_.ShapeVertex(this.target._width,this.target._height);
- var _loc3_ = new _types_.ShapeVertex(0,this.target._height);
- this.createEdges(_loc5_,_loc4_,_loc2_,_loc3_);
- }
- function onDisplay()
- {
- this.left = this.x;
- this.right = this.x + this.target._width;
- this.top = this.y;
- this.bottom = this.y + this.target._height;
- this.target._visible = this.__visible;
- }
- function update(elapsed)
- {
- if(this.__destroyTimer != undefined)
- {
- this.__destroyTimer += elapsed;
- if(this.__destroyTimer < Engine.PongObject.FRAME_TIME)
- {
- return undefined;
- }
- this.target.nextFrame();
- if(this.target._currentframe < this.target._totalframes)
- {
- this.queueForDisplay();
- this.__destroyTimer -= Engine.PongObject.FRAME_TIME;
- }
- else
- {
- this.cancelUpdates();
- this.removeFromWorld();
- }
- return undefined;
- }
- this.__waitedTime += elapsed;
- if(this.__waitedTime >= this.__displayDelay)
- {
- this.__visible = true;
- this.target._visible = true;
- delete this.__waitedTime;
- delete this.__displayDelay;
- this.cancelUpdates();
- }
- }
- }
-