home *** CD-ROM | disk | FTP | other *** search
- class Game.Objects.Goal extends Engine.PongObject
- {
- var __assetFrame;
- var __width;
- var __halfWidth;
- var target;
- static var sizes = [50,100,200];
- static var GOAL_SIZE_DEFAULT = 1;
- static var GOAL_SIZE_WIDE = 2;
- static var GOAL_SIZE_SMALL = 0;
- static var assetLeftID = "GoalLeft";
- static var assetRightID = "GoalRight";
- var assetID = Game.Objects.Goal.assetRightID;
- var className = "Goal";
- var __orientation = "right";
- var __orientationChanged = false;
- var __widthChanged = false;
- function Goal(myOrientation, myWidth, myClr)
- {
- super();
- if(myWidth != undefined)
- {
- this.width = myWidth;
- }
- this.orientation = myOrientation;
- }
- function set width(newWidth)
- {
- newWidth = Math.max(0,newWidth);
- newWidth = Math.min(Game.Objects.Goal.sizes.length - 1,newWidth);
- this.__assetFrame = newWidth + 1;
- this.__width = Game.Objects.Goal.sizes[newWidth];
- this.__halfWidth = Math.floor(this.__width / 2);
- this.__widthChanged = true;
- this.queueForDisplay();
- }
- function get width()
- {
- return this.__width;
- }
- function set orientation(newDir)
- {
- if(newDir == undefined)
- {
- return;
- }
- newDir = newDir.toLowerCase();
- if(newDir == this.__orientation)
- {
- return;
- }
- if(newDir != Engine.PongObject.LEFT_DIR && newDir != Engine.PongObject.RIGHT_DIR)
- {
- return;
- }
- if(newDir == Engine.PongObject.LEFT_DIR)
- {
- this.setAssetID(Game.Objects.Goal.assetLeftID);
- }
- else
- {
- this.setAssetID(Game.Objects.Goal.assetRightID);
- }
- this.__orientation = newDir;
- this.__orientationChanged = true;
- this.queueForDisplay();
- }
- function get orientation()
- {
- return this.__orientation;
- }
- function activateItem(item)
- {
- if(item == Game.PongLevels.GOAL_WIDE)
- {
- this.width = Game.Objects.Goal.GOAL_SIZE_WIDE;
- }
- else if(item == Game.PongLevels.GOAL_SMALL)
- {
- this.width = Game.Objects.Goal.GOAL_SIZE_SMALL;
- }
- }
- function deactivateItem()
- {
- this.width = Game.Objects.Goal.GOAL_SIZE_DEFAULT;
- }
- function onDisplay()
- {
- if(this.__widthChanged)
- {
- this.target.gotoAndStop(this.__assetFrame);
- this.__widthChanged = false;
- }
- this.top = this.y - this.__halfWidth;
- this.bottom = this.y + this.__halfWidth;
- if(this.__orientationChanged)
- {
- this.__orientationChanged = false;
- }
- }
- function onAddToScene()
- {
- this.target.gotoAndStop(this.__assetFrame);
- this.__widthChanged = false;
- this.top = this.y - this.__halfWidth;
- this.bottom = this.y + this.__halfWidth;
- this.__orientationChanged = false;
- }
- }
-