home *** CD-ROM | disk | FTP | other *** search
/ Ice Age Fan CD 1 / CD1_Scrat.iso / flash / data / game.swf / scripts / asCode / itemBubbleCodeClass.as < prev    next >
Encoding:
Text File  |  2012-07-04  |  8.7 KB  |  288 lines

  1. package asCode
  2. {
  3.    import flash.display.*;
  4.    import flash.events.*;
  5.    import flash.filters.*;
  6.    import flash.geom.*;
  7.    
  8.    public class itemBubbleCodeClass
  9.    {
  10.       private static var BUBBLE_TYPE_PLAYER:int = 0;
  11.       
  12.       private static var BUBBLE_TYPE_ACORN:int = 5;
  13.       
  14.       private static var BUBBLE_TYPE_HEALTH_POWERUP:int = 10;
  15.       
  16.       private static var BUBBLE_TYPE_INVINCIBLE:int = 15;
  17.       
  18.       private var collected:Boolean;
  19.       
  20.       private var life:int;
  21.       
  22.       private var bubbleSize:Number;
  23.       
  24.       private var bubble:MovieClip;
  25.       
  26.       private var scaleFactor:Number;
  27.       
  28.       private var currentDistort:Number = 0;
  29.       
  30.       private var drawNodes:Boolean;
  31.       
  32.       private var i:int;
  33.       
  34.       private var centerPoint:Point;
  35.       
  36.       private var _point:Point;
  37.       
  38.       private var _point2:Point;
  39.       
  40.       private var firstPoint:Boolean;
  41.       
  42.       private var bubbleShape:Shape;
  43.       
  44.       private var bubbleShape2:Shape;
  45.       
  46.       private var bubbleRadius:Number = 60;
  47.       
  48.       private var bubbleSteps:Number = 12;
  49.       
  50.       private var bubbleStepRotationNumber:Number;
  51.       
  52.       private var radians:Number;
  53.       
  54.       private var n:int;
  55.       
  56.       private var bubbleType:int;
  57.       
  58.       private var nodeArray:Array;
  59.       
  60.       private var _bubbleNodeRef:bubbleNode;
  61.       
  62.       private var _destination:Point;
  63.       
  64.       private var xVelocity:Number;
  65.       
  66.       private var yVelocity:Number;
  67.       
  68.       private var dx:Number;
  69.       
  70.       private var dy:Number;
  71.       
  72.       private var dist:Number;
  73.       
  74.       private var _pointb:Point;
  75.       
  76.       private var bRad:Number;
  77.       
  78.       private var bubbleCycle:Number = 0;
  79.       
  80.       private var bubbleCycleCount:Number = 0;
  81.       
  82.       public function itemBubbleCodeClass(param1:MovieClip, param2:Number, param3:int, param4:Boolean)
  83.       {
  84.          var _loc8_:Number = NaN;
  85.          centerPoint = new Point(160,120);
  86.          _point = new Point();
  87.          _point2 = new Point();
  88.          super();
  89.          collected = false;
  90.          bubbleType = param3;
  91.          _pointb = new Point();
  92.          _point = new Point();
  93.          _point2 = new Point();
  94.          bubbleRadius = param2;
  95.          bubbleShape = new Shape();
  96.          bubble = param1;
  97.          bubbleShape2 = new Shape();
  98.          bubble.addChild(bubbleShape);
  99.          bubble.addChild(bubbleShape2);
  100.          var _loc5_:GlowFilter = new GlowFilter(13421823,0.25,20,20,2,1,true,true);
  101.          var _loc6_:Array = new Array(_loc5_);
  102.          bubbleShape.filters = _loc6_;
  103.          bubbleStepRotationNumber = 360 / bubbleSteps;
  104.          nodeArray = new Array();
  105.          var _loc7_:int = 0;
  106.          while(_loc7_ < bubbleSteps + 1)
  107.          {
  108.             _loc8_ = _loc7_ * bubbleStepRotationNumber;
  109.             radians = _loc8_ / 180 * Math.PI;
  110.             _point.x = Math.cos(radians) * bubbleRadius;
  111.             _point.y = Math.sin(radians) * bubbleRadius;
  112.             _bubbleNodeRef = new bubbleNode(_point);
  113.             nodeArray[_loc7_] = _bubbleNodeRef;
  114.             _loc7_++;
  115.          }
  116.          xVelocity = 0;
  117.          yVelocity = 0;
  118.          drawNodes = param4;
  119.          _destination = new Point();
  120.          bubbleCycle = Math.random() * 360;
  121.          bubble.bubbleSheen.width = bubble.bubbleSheen.height = param2 * 0.7;
  122.          life = 250;
  123.       }
  124.       
  125.       public function getBubbleRadius() : Number
  126.       {
  127.          return bubbleRadius;
  128.       }
  129.       
  130.       public function getClip() : MovieClip
  131.       {
  132.          return bubble;
  133.       }
  134.       
  135.       public function getCollected() : Boolean
  136.       {
  137.          return collected;
  138.       }
  139.       
  140.       public function setCollected() : void
  141.       {
  142.          collected = true;
  143.       }
  144.       
  145.       public function dispose() : void
  146.       {
  147.       }
  148.       
  149.       private function findDist(param1:Point, param2:Point) : Number
  150.       {
  151.          dx = param1.x - param2.x;
  152.          dy = param1.y - param2.y;
  153.          dist = Math.floor(Math.sqrt(dx * dx + dy * dy));
  154.          return dist;
  155.       }
  156.       
  157.       private function findAngle(param1:Point, param2:Point) : Number
  158.       {
  159.          dx = param1.x - param2.x;
  160.          dy = param1.y - param2.y;
  161.          radians = Math.atan2(dy,dx);
  162.          return radians;
  163.       }
  164.       
  165.       public function setLoc(param1:Point) : void
  166.       {
  167.          centerPoint.x = param1.x;
  168.          centerPoint.y = param1.y;
  169.       }
  170.       
  171.       public function get getLife() : int
  172.       {
  173.          return life;
  174.       }
  175.       
  176.       public function setLife(param1:int) : void
  177.       {
  178.          life = param1;
  179.       }
  180.       
  181.       public function getLoc() : Point
  182.       {
  183.          return centerPoint;
  184.       }
  185.       
  186.       public function drawBubble(param1:Point) : *
  187.       {
  188.          var _loc10_:Number = NaN;
  189.          var _loc11_:Number = NaN;
  190.          var _loc12_:Number = NaN;
  191.          var _loc13_:Number = NaN;
  192.          var _loc14_:* = undefined;
  193.          var _loc15_:* = undefined;
  194.          bubbleCycleCount += 5;
  195.          if(bubbleCycleCount > 360)
  196.          {
  197.             bubbleCycleCount -= 360;
  198.          }
  199.          bRad = bubbleCycleCount / 180 * Math.PI;
  200.          _destination.x = param1.x;
  201.          _destination.y = param1.y;
  202.          var _loc2_:Number = findAngle(_destination,centerPoint);
  203.          var _loc3_:Number = Math.cos(_loc2_) * bubbleRadius;
  204.          var _loc4_:Number = Math.sin(_loc2_) * bubbleRadius;
  205.          _point = new Point(param1.x,param1.y);
  206.          dist = findDist(_point,centerPoint);
  207.          dist *= 0.4;
  208.          xVelocity = Math.cos(_loc2_) * dist;
  209.          yVelocity = Math.sin(_loc2_) * dist;
  210.          firstPoint = true;
  211.          centerPoint.x += xVelocity;
  212.          centerPoint.y += yVelocity;
  213.          bubble.x = centerPoint.x + Math.cos(bRad) * 5;
  214.          bubble.y = centerPoint.y + Math.sin(bRad) * 5;
  215.          var _loc5_:Array = [];
  216.          var _loc6_:Array = [];
  217.          currentDistort += 0.05;
  218.          var _loc7_:Number = currentDistort / bubbleSteps * 360;
  219.          var _loc8_:Number = _loc7_ / 180 * Math.PI;
  220.          var _loc9_:int = 0;
  221.          while(_loc9_ < bubbleSteps)
  222.          {
  223.             _bubbleNodeRef = nodeArray[_loc9_];
  224.             _point = _bubbleNodeRef.getLoc();
  225.             _pointb = new Point(_destination.x - centerPoint.x,_destination.y - centerPoint.y);
  226.             _loc10_ = findDist(_point,_pointb);
  227.             _bubbleNodeRef = nodeArray[_loc9_ + 1];
  228.             _point2 = _bubbleNodeRef.getLoc();
  229.             _loc11_ = (_loc9_ + currentDistort) / (bubbleSteps * 2) * 360 / 180 * Math.PI;
  230.             _loc12_ = Math.cos(_loc8_) * 3 * Math.cos(_loc11_);
  231.             _loc13_ = Math.sin(_loc8_) * 3 * Math.sin(_loc11_);
  232.             xVelocity = Math.cos(_loc2_) * _loc10_ + _loc12_;
  233.             yVelocity = Math.sin(_loc2_) * _loc10_ + _loc13_;
  234.             _point.x -= xVelocity - _loc3_;
  235.             _point2.x -= xVelocity - _loc3_;
  236.             _point.y -= yVelocity - _loc4_;
  237.             _point2.y -= yVelocity - _loc4_;
  238.             _loc14_ = (_point.x + _point2.x) / 2;
  239.             _loc15_ = (_point.y + _point2.y) / 2;
  240.             _loc5_.push(_point);
  241.             _loc6_.push(new Point(_loc14_,_loc15_));
  242.             _loc9_++;
  243.          }
  244.          bubbleShape.graphics.clear();
  245.          bubbleShape2.graphics.clear();
  246.          bubbleShape2.graphics.lineStyle(1,0);
  247.          bubbleShape.graphics.lineStyle(1,0);
  248.          bubbleShape.graphics.beginFill(255);
  249.          _point = _loc6_[0];
  250.          bubbleShape.graphics.moveTo(_point.x,_point.y);
  251.          _loc9_ = 1;
  252.          while(_loc9_ < bubbleSteps)
  253.          {
  254.             _point = _loc5_[_loc9_];
  255.             _point2 = _loc6_[_loc9_];
  256.             bubbleShape.graphics.curveTo(_point.x,_point.y,_point2.x,_point2.y);
  257.             if(drawNodes)
  258.             {
  259.                drawNode(_point,_point2);
  260.             }
  261.             _loc9_++;
  262.          }
  263.          _point = _loc5_[0];
  264.          _point2 = _loc6_[0];
  265.          bubbleShape.graphics.curveTo(_point.x,_point.y,_point2.x,_point2.y);
  266.          bubbleShape.graphics.endFill();
  267.          if(drawNodes)
  268.          {
  269.             drawNode(_point,_point2);
  270.          }
  271.       }
  272.       
  273.       private function drawNode(param1:Point, param2:Point) : void
  274.       {
  275.          bubbleShape2.graphics.beginFill(16776960,0.5);
  276.          bubbleShape2.graphics.drawCircle(param1.x,param1.y,5);
  277.          bubbleShape2.graphics.beginFill(16711680,0.5);
  278.          bubbleShape2.graphics.drawCircle(param2.x,param2.y,2);
  279.       }
  280.       
  281.       public function get getBubbleType() : int
  282.       {
  283.          return bubbleType;
  284.       }
  285.    }
  286. }
  287.  
  288.