home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / bobsleddin.swf / scripts / __Packages / CourseSector.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  15.9 KB  |  381 lines

  1. class CourseSector extends BB
  2. {
  3.    var objects;
  4.    var world;
  5.    var depthRatio;
  6.    var target;
  7.    var screenX;
  8.    var screenY;
  9.    var screenRadius;
  10.    var arcLeft;
  11.    var arcRight;
  12.    var arcTop;
  13.    var arcBottom;
  14.    var outerLeftY;
  15.    var outerRightY;
  16.    var color;
  17.    var outsideColor;
  18.    var previous;
  19.    var next;
  20.    var index;
  21.    var targetTint;
  22.    var hasObjects = false;
  23.    var flipped = false;
  24.    var x = 0;
  25.    var y = 0;
  26.    var z = 0;
  27.    var radius = 200;
  28.    var arcClosed = false;
  29.    var arcClosedFace = false;
  30.    var outsideSlope = 0.4;
  31.    var inScene = false;
  32.    var assetName = "Default Ring";
  33.    var outsideClutter = "CourseHouse";
  34.    var useTint = true;
  35.    var style = 0;
  36.    var xScale = 1;
  37.    var yScale = 1;
  38.    var targetTintTrans = {};
  39.    function CourseSector(world, x, y, z, radius)
  40.    {
  41.       super();
  42.       this.objects = [];
  43.       this.x = x;
  44.       this.y = y;
  45.       this.z = z;
  46.       this.world = world;
  47.       this.radius = radius;
  48.    }
  49.    function setDisplay(x, y, depthRatio, frontDepthRatio, fogRatio)
  50.    {
  51.       this.depthRatio = depthRatio;
  52.       if(!this.target)
  53.       {
  54.          this.addToScene();
  55.       }
  56.       this.target.sprite._x = this.screenX = x * depthRatio;
  57.       this.target.sprite._y = this.screenY = y * depthRatio;
  58.       this.target.sprite._xscale = this.target.sprite._yscale = (this.screenRadius = depthRatio * this.radius) * 2;
  59.       var _loc2_ = this.target.drawClip;
  60.       _loc2_.clear();
  61.       this.arcLeft = this.screenX - this.screenRadius * this.xScale;
  62.       this.arcRight = this.screenX + this.screenRadius * this.xScale;
  63.       this.arcTop = this.screenY - this.screenRadius * this.yScale;
  64.       this.arcBottom = this.screenY + this.screenRadius * this.yScale;
  65.       this.outerLeftY = this.screenY - Math.abs(this.world.halfWidth + this.arcLeft) * this.outsideSlope;
  66.       this.outerRightY = this.screenY - Math.abs(this.world.halfWidth - this.arcRight) * this.outsideSlope;
  67.       var _loc4_ = new RGB(this.color.r + (this.world.fogColor.r - this.color.r) * fogRatio,this.color.g + (this.world.fogColor.g - this.color.g) * fogRatio,this.color.b + (this.world.fogColor.b - this.color.b) * fogRatio);
  68.       var _loc3_ = _loc4_.valueOf();
  69.       var _loc8_ = new RGB(this.outsideColor.r + (this.world.outsideFogColor.r - this.outsideColor.r) * fogRatio,this.outsideColor.g + (this.world.outsideFogColor.g - this.outsideColor.g) * fogRatio,this.outsideColor.b + (this.world.outsideFogColor.b - this.outsideColor.b) * fogRatio);
  70.       var _loc7_ = new RGB(_loc4_.r * 0.9,_loc4_.g * 0.9,_loc4_.b);
  71.       if(this.arcClosedFace)
  72.       {
  73.          var _loc6_ = this.world.camera.depthFocus / (this.z + 1000 - this.world.camera.z);
  74.          var _loc10_ = this.world.camera.depthFocus / (this.z + 750 - this.world.camera.z);
  75.          _loc2_ = this.target;
  76.          _loc2_.clear();
  77.          _loc2_.beginFill(_loc8_);
  78.          _loc2_.moveTo(this.arcLeft,this.screenY);
  79.          _loc2_.curveTo(this.arcLeft,this.arcTop,this.screenX,this.arcTop);
  80.          _loc2_.curveTo(this.arcRight,this.arcTop,this.arcRight,this.screenY);
  81.          _loc2_.lineTo(this.world.halfWidth,this.screenY);
  82.          _loc2_.lineTo(this.world.halfWidth,(this.y - 800 - this.world.camera.y) * _loc6_);
  83.          _loc2_.curveTo((this.x - this.world.camera.x) * _loc10_,(this.y - this.radius - 1600 - this.world.camera.y) * _loc10_,- this.world.halfWidth,(this.y - 800 - this.world.camera.y) * _loc6_);
  84.          _loc2_.lineTo(- this.world.halfWidth,this.screenY);
  85.          _loc2_.endFill();
  86.       }
  87.       if(this.arcClosed && this.previous.arcClosed)
  88.       {
  89.          this.drawClosedPipe(_loc2_,_loc7_,_loc3_,_loc3_,_loc3_,_loc3_);
  90.       }
  91.       else
  92.       {
  93.          this.drawOpenPipe(_loc2_,_loc7_,_loc3_,_loc3_,_loc8_);
  94.       }
  95.    }
  96.    function drawClosedPipe(drawClip, lineColor, topLeftColor, topRightColor, bottomRightColor, bottomLeftColor)
  97.    {
  98.       var _loc5_ = this.world.camera;
  99.       var _loc19_ = !this.previous.target;
  100.       if(!_loc19_)
  101.       {
  102.          var _loc7_ = this.previous.radius;
  103.          var _loc3_ = this.previous.screenX;
  104.          var _loc4_ = this.previous.screenY;
  105.          var _loc11_ = this.previous.arcLeft;
  106.          var _loc12_ = this.previous.arcTop;
  107.          var _loc8_ = this.previous.arcRight;
  108.          var _loc10_ = this.previous.arcBottom;
  109.          if(!this.next.inScene)
  110.          {
  111.             drawClip.beginFill(topLeftColor);
  112.             drawClip.moveTo(_loc11_,_loc4_);
  113.             drawClip.curveTo(_loc11_,_loc12_,_loc3_,_loc12_);
  114.             drawClip.lineTo(this.screenX,this.screenY);
  115.             drawClip.endFill();
  116.             drawClip.beginFill(topRightColor);
  117.             drawClip.moveTo(_loc8_,_loc4_);
  118.             drawClip.curveTo(_loc8_,_loc12_,_loc3_,_loc12_);
  119.             drawClip.lineTo(this.screenX,this.screenY);
  120.             drawClip.endFill();
  121.             drawClip.beginFill(bottomLeftColor);
  122.             drawClip.moveTo(_loc11_,_loc4_);
  123.             drawClip.curveTo(_loc11_,_loc10_,_loc3_,_loc10_);
  124.             drawClip.lineTo(this.screenX,this.screenY);
  125.             drawClip.endFill();
  126.             drawClip.beginFill(bottomRightColor);
  127.             drawClip.moveTo(_loc8_,_loc4_);
  128.             drawClip.curveTo(_loc8_,_loc10_,_loc3_,_loc10_);
  129.             drawClip.lineTo(this.screenX,this.screenY);
  130.             drawClip.endFill();
  131.          }
  132.          else
  133.          {
  134.             drawClip.beginFill(topLeftColor);
  135.             drawClip.moveTo(this.arcLeft,this.screenY);
  136.             drawClip.curveTo(this.arcLeft,this.arcTop,this.screenX,this.arcTop);
  137.             drawClip.lineTo(_loc3_,_loc12_);
  138.             drawClip.curveTo(_loc11_,_loc12_,_loc11_,_loc4_);
  139.             drawClip.endFill();
  140.             drawClip.beginFill(topRightColor);
  141.             drawClip.moveTo(this.arcRight,this.screenY);
  142.             drawClip.curveTo(this.arcRight,this.arcTop,this.screenX,this.arcTop);
  143.             drawClip.lineTo(_loc3_,_loc12_);
  144.             drawClip.curveTo(_loc8_,_loc12_,_loc8_,_loc4_);
  145.             drawClip.endFill();
  146.             drawClip.beginFill(bottomLeftColor);
  147.             drawClip.moveTo(this.arcLeft,this.screenY);
  148.             drawClip.curveTo(this.arcLeft,this.arcBottom,this.screenX,this.arcBottom);
  149.             drawClip.lineTo(_loc3_,_loc10_);
  150.             drawClip.curveTo(_loc11_,_loc10_,_loc11_,_loc4_);
  151.             drawClip.endFill();
  152.             drawClip.beginFill(bottomRightColor);
  153.             drawClip.moveTo(this.arcRight,this.screenY);
  154.             drawClip.curveTo(this.arcRight,this.arcBottom,this.screenX,this.arcBottom);
  155.             drawClip.lineTo(_loc3_,_loc10_);
  156.             drawClip.curveTo(_loc8_,_loc10_,_loc8_,_loc4_);
  157.             drawClip.endFill();
  158.          }
  159.       }
  160.       else
  161.       {
  162.          var _loc6_ = (this.z - _loc5_.z - _loc5_.hither) / (this.z - this.previous.z);
  163.          var _loc9_ = _loc5_.depthFocus / _loc5_.hither;
  164.          var _loc13_ = this.xScale - (this.xScale - this.previous.xScale) * _loc6_;
  165.          var _loc14_ = this.yScale - (this.yScale - this.previous.yScale) * _loc6_;
  166.          _loc7_ = (this.radius - (this.radius - this.previous.radius) * _loc6_) * _loc9_;
  167.          _loc3_ = (this.x - (this.x - this.previous.x) * _loc6_ - _loc5_.x) * _loc9_;
  168.          _loc4_ = (this.y - (this.y - this.previous.y) * _loc6_ - _loc5_.y) * _loc9_;
  169.          _loc11_ = _loc3_ - _loc7_ * _loc13_;
  170.          _loc12_ = _loc4_ - _loc7_ * _loc14_;
  171.          _loc8_ = _loc3_ + _loc7_ * _loc13_;
  172.          _loc10_ = _loc4_ + _loc7_ * _loc14_;
  173.          drawClip.beginFill(topLeftColor);
  174.          drawClip.moveTo(this.arcLeft,this.screenY);
  175.          drawClip.curveTo(this.arcLeft,this.arcTop,this.screenX,this.arcTop);
  176.          drawClip.lineTo(_loc3_,_loc12_);
  177.          drawClip.lineTo(_loc3_,- this.world.halfHeight);
  178.          drawClip.lineTo(- this.world.halfWidth,- this.world.halfHeight);
  179.          drawClip.lineTo(- this.world.halfWidth,_loc4_);
  180.          drawClip.lineTo(_loc11_,_loc4_);
  181.          drawClip.endFill();
  182.          drawClip.beginFill(topRightColor);
  183.          drawClip.moveTo(this.arcRight,this.screenY);
  184.          drawClip.curveTo(this.arcRight,this.arcTop,this.screenX,this.arcTop);
  185.          drawClip.lineTo(_loc3_,_loc12_);
  186.          drawClip.lineTo(_loc3_,- this.world.halfHeight);
  187.          drawClip.lineTo(this.world.halfWidth,- this.world.halfHeight);
  188.          drawClip.lineTo(this.world.halfWidth,_loc4_);
  189.          drawClip.lineTo(_loc8_,_loc4_);
  190.          drawClip.endFill();
  191.          drawClip.beginFill(bottomLeftColor);
  192.          drawClip.moveTo(this.arcLeft,this.screenY);
  193.          drawClip.curveTo(this.arcLeft,this.arcBottom,this.screenX,this.arcBottom);
  194.          drawClip.lineTo(_loc3_,_loc10_);
  195.          drawClip.lineTo(_loc3_,this.world.halfHeight);
  196.          drawClip.lineTo(- this.world.halfWidth,this.world.halfHeight);
  197.          drawClip.lineTo(- this.world.halfWidth,_loc4_);
  198.          drawClip.lineTo(_loc11_,_loc4_);
  199.          drawClip.endFill();
  200.          drawClip.beginFill(bottomRightColor);
  201.          drawClip.moveTo(this.arcRight,this.screenY);
  202.          drawClip.curveTo(this.arcRight,this.arcBottom,this.screenX,this.arcBottom);
  203.          drawClip.lineTo(_loc3_,_loc10_);
  204.          drawClip.lineTo(_loc3_,this.world.halfHeight);
  205.          drawClip.lineTo(this.world.halfWidth,this.world.halfHeight);
  206.          drawClip.lineTo(this.world.halfWidth,_loc4_);
  207.          drawClip.lineTo(_loc8_,_loc4_);
  208.          drawClip.endFill();
  209.       }
  210.       drawClip.lineStyle(0,lineColor);
  211.       drawClip.moveTo(_loc3_,_loc12_);
  212.       drawClip.lineTo(this.screenX,this.arcTop);
  213.       drawClip.moveTo(_loc3_,_loc10_);
  214.       drawClip.lineTo(this.screenX,this.arcBottom);
  215.       drawClip.moveTo(_loc11_,_loc4_);
  216.       drawClip.lineTo(this.arcLeft,this.screenY);
  217.       drawClip.moveTo(_loc8_,_loc4_);
  218.       drawClip.lineTo(this.arcRight,this.screenY);
  219.    }
  220.    function drawOpenPipe(drawClip, lineColor, leftSurfaceColor, rightSurfaceColor, outsideColor)
  221.    {
  222.       var _loc15_ = !this.previous.target;
  223.       if(!_loc15_)
  224.       {
  225.          var _loc9_ = this.previous.radius;
  226.          var _loc4_ = this.previous.screenX;
  227.          var _loc3_ = this.previous.screenY;
  228.          var _loc8_ = this.previous.arcLeft;
  229.          var _loc19_ = this.previous.arcTop;
  230.          var _loc7_ = this.previous.arcRight;
  231.          var _loc11_ = this.previous.arcBottom;
  232.          var _loc14_ = this.previous.outerLeftY;
  233.          var _loc13_ = this.previous.outerRightY;
  234.          drawClip.beginFill(leftSurfaceColor);
  235.          drawClip.moveTo(this.arcLeft,this.screenY);
  236.          drawClip.curveTo(this.arcLeft,this.arcBottom,this.screenX,this.arcBottom);
  237.          drawClip.lineTo(_loc4_,_loc11_);
  238.          drawClip.curveTo(_loc8_,_loc11_,_loc8_,_loc3_);
  239.          drawClip.endFill();
  240.          drawClip.beginFill(rightSurfaceColor);
  241.          drawClip.moveTo(this.arcRight,this.screenY);
  242.          drawClip.curveTo(this.arcRight,this.arcBottom,this.screenX,this.arcBottom);
  243.          drawClip.lineTo(_loc4_,_loc11_);
  244.          drawClip.curveTo(_loc7_,_loc11_,_loc7_,_loc3_);
  245.          drawClip.endFill();
  246.       }
  247.       else
  248.       {
  249.          var _loc5_ = this.world.camera;
  250.          var _loc6_ = (this.z - _loc5_.z - _loc5_.hither) / (this.z - this.previous.z);
  251.          var _loc10_ = _loc5_.depthFocus / _loc5_.hither;
  252.          var _loc12_ = this.xScale - (this.xScale - this.previous.xScale) * _loc6_;
  253.          var _loc16_ = this.yScale - (this.yScale - this.previous.yScale) * _loc6_;
  254.          _loc9_ = (this.radius - (this.radius - this.previous.radius) * _loc6_) * _loc10_;
  255.          _loc4_ = (this.x - (this.x - this.previous.x) * _loc6_ - _loc5_.x) * _loc10_;
  256.          _loc3_ = (this.y - (this.y - this.previous.y) * _loc6_ - _loc5_.y) * _loc10_;
  257.          _loc14_ = _loc3_;
  258.          _loc13_ = _loc3_;
  259.          _loc8_ = _loc4_ - _loc9_ * _loc12_;
  260.          _loc7_ = _loc4_ + _loc9_ * _loc12_;
  261.          _loc11_ = _loc3_ + _loc9_ * _loc16_;
  262.          drawClip.beginFill(leftSurfaceColor);
  263.          drawClip.moveTo(this.arcLeft,this.screenY);
  264.          drawClip.curveTo(this.arcLeft,this.arcBottom,this.screenX,this.arcBottom);
  265.          drawClip.lineTo(_loc4_,_loc11_);
  266.          drawClip.lineTo(_loc4_,this.world.halfHeight);
  267.          drawClip.lineTo(- this.world.halfWidth,this.world.halfHeight);
  268.          drawClip.lineTo(- this.world.halfWidth,_loc3_);
  269.          drawClip.lineTo(_loc8_,_loc3_);
  270.          drawClip.endFill();
  271.          drawClip.beginFill(rightSurfaceColor);
  272.          drawClip.moveTo(this.arcRight,this.screenY);
  273.          drawClip.curveTo(this.arcRight,this.arcBottom,this.screenX,this.arcBottom);
  274.          drawClip.lineTo(_loc4_,_loc11_);
  275.          drawClip.lineTo(_loc4_,this.world.halfHeight);
  276.          drawClip.lineTo(this.world.halfWidth,this.world.halfHeight);
  277.          drawClip.lineTo(this.world.halfWidth,_loc3_);
  278.          drawClip.lineTo(_loc7_,_loc3_);
  279.          drawClip.endFill();
  280.       }
  281.       drawClip.beginFill(outsideColor);
  282.       if(_loc3_ + Math.abs((_loc7_ - this.arcRight) * this.outsideSlope) > this.screenY)
  283.       {
  284.          drawClip.moveTo(this.arcRight,this.screenY);
  285.          drawClip.lineTo(_loc7_,_loc3_);
  286.          drawClip.lineTo(this.world.halfWidth,_loc13_);
  287.          drawClip.lineTo(this.world.halfWidth,this.outerRightY);
  288.       }
  289.       if(_loc3_ + Math.abs((this.arcLeft - _loc8_) * this.outsideSlope) > this.screenY)
  290.       {
  291.          drawClip.moveTo(this.arcLeft,this.screenY);
  292.          drawClip.lineTo(_loc8_,_loc3_);
  293.          drawClip.lineTo(- this.world.halfWidth,_loc14_);
  294.          drawClip.lineTo(- this.world.halfWidth,this.outerLeftY);
  295.       }
  296.       drawClip.endFill();
  297.       drawClip.lineStyle(0,lineColor);
  298.       drawClip.moveTo(_loc4_,_loc11_);
  299.       drawClip.lineTo(this.screenX,this.arcBottom);
  300.       drawClip.moveTo(_loc8_,_loc3_);
  301.       drawClip.lineTo(this.arcLeft,this.screenY);
  302.       drawClip.moveTo(_loc7_,_loc3_);
  303.       drawClip.lineTo(this.arcRight,this.screenY);
  304.    }
  305.    function addObject(object)
  306.    {
  307.       if(!object.trackInSectorGrid)
  308.       {
  309.          return undefined;
  310.       }
  311.       this.hasObjects = true;
  312.       this.objects.push(object);
  313.    }
  314.    function removeObject(object)
  315.    {
  316.       var _loc2_ = this.objects.length - 1;
  317.       while(_loc2_ > -1)
  318.       {
  319.          if(this.objects[_loc2_] == object)
  320.          {
  321.             this.objects.splice(_loc2_,1);
  322.             break;
  323.          }
  324.          _loc2_ = _loc2_ - 1;
  325.       }
  326.       this.hasObjects = this.objects.length > 0;
  327.    }
  328.    function addToScene()
  329.    {
  330.       this.target = this.world.display.attachMovie(this.assetName,"X" + this.index,BB.calculateDepth(this.z,0,0));
  331.       this.inScene = true;
  332.       var _loc2_ = this.objects.length - 1;
  333.       while(_loc2_ > -1)
  334.       {
  335.          this.objects[_loc2_].addToScene();
  336.          _loc2_ = _loc2_ - 1;
  337.       }
  338.       this.onAddToScene();
  339.    }
  340.    function onAddToScene()
  341.    {
  342.       if(this.arcClosedFace)
  343.       {
  344.          this.targetTint = new Color(this.target.sprite.bottom);
  345.       }
  346.       else
  347.       {
  348.          this.targetTint = new Color(this.target.sprite);
  349.          this.target.sprite.cover.swapDepths(255);
  350.          this.target.sprite.cover.removeMovieClip();
  351.       }
  352.       this.target.createEmptyMovieClip("drawClip",10);
  353.       if(!this.arcClosed && random(2) == 0)
  354.       {
  355.          var _loc2_ = this.target.sprite.attachMovie(this.outsideClutter,"house",1000);
  356.          var _loc3_ = Math.random() * 2000;
  357.          _loc2_._x = (!random(2) ? 1 : -1) * (_loc3_ + this.radius);
  358.          _loc2_._y = (- (_loc3_ + 125)) * this.outsideSlope;
  359.          _loc2_._xscale = _loc2_._x <= 0 ? 100 : -100;
  360.       }
  361.       this.target.sprite.top._visible = this.arcClosed;
  362.    }
  363.    function removeFromScene()
  364.    {
  365.       this.target.swapDepths(255);
  366.       this.target.removeMovieClip();
  367.       this.inScene = false;
  368.       var _loc2_ = this.objects.length - 1;
  369.       while(_loc2_ > -1)
  370.       {
  371.          this.objects[_loc2_].removeFromScene();
  372.          _loc2_ = _loc2_ - 1;
  373.       }
  374.       delete this.target;
  375.    }
  376.    function toString()
  377.    {
  378.       return "Course Sector " + this.index;
  379.    }
  380. }
  381.