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

  1. class Game.Objects.Goal extends Engine.PongObject
  2. {
  3.    var __assetFrame;
  4.    var __width;
  5.    var __halfWidth;
  6.    var target;
  7.    static var sizes = [50,100,200];
  8.    static var GOAL_SIZE_DEFAULT = 1;
  9.    static var GOAL_SIZE_WIDE = 2;
  10.    static var GOAL_SIZE_SMALL = 0;
  11.    static var assetLeftID = "GoalLeft";
  12.    static var assetRightID = "GoalRight";
  13.    var assetID = Game.Objects.Goal.assetRightID;
  14.    var className = "Goal";
  15.    var __orientation = "right";
  16.    var __orientationChanged = false;
  17.    var __widthChanged = false;
  18.    function Goal(myOrientation, myWidth, myClr)
  19.    {
  20.       super();
  21.       if(myWidth != undefined)
  22.       {
  23.          this.width = myWidth;
  24.       }
  25.       this.orientation = myOrientation;
  26.    }
  27.    function set width(newWidth)
  28.    {
  29.       newWidth = Math.max(0,newWidth);
  30.       newWidth = Math.min(Game.Objects.Goal.sizes.length - 1,newWidth);
  31.       this.__assetFrame = newWidth + 1;
  32.       this.__width = Game.Objects.Goal.sizes[newWidth];
  33.       this.__halfWidth = Math.floor(this.__width / 2);
  34.       this.__widthChanged = true;
  35.       this.queueForDisplay();
  36.    }
  37.    function get width()
  38.    {
  39.       return this.__width;
  40.    }
  41.    function set orientation(newDir)
  42.    {
  43.       if(newDir == undefined)
  44.       {
  45.          return;
  46.       }
  47.       newDir = newDir.toLowerCase();
  48.       if(newDir == this.__orientation)
  49.       {
  50.          return;
  51.       }
  52.       if(newDir != Engine.PongObject.LEFT_DIR && newDir != Engine.PongObject.RIGHT_DIR)
  53.       {
  54.          return;
  55.       }
  56.       if(newDir == Engine.PongObject.LEFT_DIR)
  57.       {
  58.          this.setAssetID(Game.Objects.Goal.assetLeftID);
  59.       }
  60.       else
  61.       {
  62.          this.setAssetID(Game.Objects.Goal.assetRightID);
  63.       }
  64.       this.__orientation = newDir;
  65.       this.__orientationChanged = true;
  66.       this.queueForDisplay();
  67.    }
  68.    function get orientation()
  69.    {
  70.       return this.__orientation;
  71.    }
  72.    function activateItem(item)
  73.    {
  74.       if(item == Game.PongLevels.GOAL_WIDE)
  75.       {
  76.          this.width = Game.Objects.Goal.GOAL_SIZE_WIDE;
  77.       }
  78.       else if(item == Game.PongLevels.GOAL_SMALL)
  79.       {
  80.          this.width = Game.Objects.Goal.GOAL_SIZE_SMALL;
  81.       }
  82.    }
  83.    function deactivateItem()
  84.    {
  85.       this.width = Game.Objects.Goal.GOAL_SIZE_DEFAULT;
  86.    }
  87.    function onDisplay()
  88.    {
  89.       if(this.__widthChanged)
  90.       {
  91.          this.target.gotoAndStop(this.__assetFrame);
  92.          this.__widthChanged = false;
  93.       }
  94.       this.top = this.y - this.__halfWidth;
  95.       this.bottom = this.y + this.__halfWidth;
  96.       if(this.__orientationChanged)
  97.       {
  98.          this.__orientationChanged = false;
  99.       }
  100.    }
  101.    function onAddToScene()
  102.    {
  103.       this.target.gotoAndStop(this.__assetFrame);
  104.       this.__widthChanged = false;
  105.       this.top = this.y - this.__halfWidth;
  106.       this.bottom = this.y + this.__halfWidth;
  107.       this.__orientationChanged = false;
  108.    }
  109. }
  110.