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

  1. package asCode
  2. {
  3.    import flash.display.*;
  4.    import flash.geom.*;
  5.    
  6.    internal class itemManager
  7.    {
  8.       private static var MEDAL_PERFECT_RUN:int = 0;
  9.       
  10.       private static var MEDAL_LOW_HEALTH:int = 1;
  11.       
  12.       private static var MEDAL_WINNING_STREAK:int = 2;
  13.       
  14.       private static var MEDAL_10_IN_A_ROW:int = 3;
  15.       
  16.       private static var MEDAL_25_IN_A_ROW:int = 4;
  17.       
  18.       private static var MEDAL_ALL_ACORNS:int = 5;
  19.       
  20.       private static var MEDAL_25_PLAYS:int = 6;
  21.       
  22.       private static var MEDAL_GAME_COMPLETED:int = 7;
  23.       
  24.       private static var PARTICLE_EFFECT_ENEMY_DEATH:int = 0;
  25.       
  26.       private static var PARTICLE_HIT_OBJECT:int = 1;
  27.       
  28.       private static var PARTICLE_COLLECT_ITEM:int = 2;
  29.       
  30.       private static var PARTICLE_EFFECT_CHIP_PLACED:int = 3;
  31.       
  32.       private static var PARTICLE_EFFECT_ELECTRICAL_CHARGE:int = 4;
  33.       
  34.       private static var PARTICLE_EFFECT_METEOR:int = 5;
  35.       
  36.       private static var PARTICLE_EFFECT_FLICKER:int = 6;
  37.       
  38.       private static var BUBBLE_TYPE_PLAYER:int = 0;
  39.       
  40.       private static var BUBBLE_TYPE_ACORN:int = 5;
  41.       
  42.       private static var BUBBLE_TYPE_HEALTH_POWERUP:int = 10;
  43.       
  44.       private static var BUBBLE_TYPE_INVINCIBLE:int = 15;
  45.       
  46.       private static var BUBBLE_TYPE_SHRINK:int = 20;
  47.       
  48.       private static var BUBBLE_TYPE_REVERSE:int = 25;
  49.       
  50.       private var scrollYDist:Number;
  51.       
  52.       private var acornsCollected:int;
  53.       
  54.       public var playerScreenLoc:Point;
  55.       
  56.       private var HIT_ENEMY:int = 10;
  57.       
  58.       private var HIT_WALL:int = 20;
  59.       
  60.       private var HIT_ACORN:int = 30;
  61.       
  62.       private var hitInARow:int = 0;
  63.       
  64.       private var lastThingHit:int = 0;
  65.       
  66.       private var specialEffectsActive:Boolean = true;
  67.       
  68.       public var _trigClassRef:trigClass;
  69.       
  70.       private var itemBubbleGenCount:int = 0;
  71.       
  72.       private var activeBubbles:int = 0;
  73.       
  74.       private var screenHeight:Number;
  75.       
  76.       private var dist:Number;
  77.       
  78.       private var removeBubble:Boolean;
  79.       
  80.       private var i:int;
  81.       
  82.       private var _itemBubbleRef:itemBubbleCodeClass;
  83.       
  84.       private var MAXActiveBubbles:int = 1;
  85.       
  86.       private var _clip:MovieClip;
  87.       
  88.       private var bubblesArray:Array;
  89.       
  90.       private var _tempPoint:Point;
  91.       
  92.       private var playerBubbleRadius:Number;
  93.       
  94.       private var _gameClipClassRef:gameClipClass;
  95.       
  96.       public function itemManager(param1:gameClipClass)
  97.       {
  98.          playerScreenLoc = new Point();
  99.          _trigClassRef = new trigClass();
  100.          super();
  101.          _gameClipClassRef = param1;
  102.       }
  103.       
  104.       public function reset() : void
  105.       {
  106.          if(bubblesArray != null)
  107.          {
  108.             activeBubbles = bubblesArray.length;
  109.             i = activeBubbles;
  110.             while(i--)
  111.             {
  112.                _itemBubbleRef = bubblesArray[i];
  113.                bubblesArray.splice(i,1);
  114.             }
  115.          }
  116.          bubblesArray = new Array();
  117.          _gameClipClassRef.bubblesArray = bubblesArray;
  118.       }
  119.       
  120.       public function manageItems() : void
  121.       {
  122.          var _loc1_:Number = NaN;
  123.          var _loc2_:int = 0;
  124.          playerScreenLoc = _gameClipClassRef.playerScreenLoc;
  125.          acornsCollected = _gameClipClassRef.acornsCollected;
  126.          scrollYDist = _gameClipClassRef.scrollYDist;
  127.          playerBubbleRadius = _gameClipClassRef.playerBubbleRadius;
  128.          bubblesArray = _gameClipClassRef.bubblesArray;
  129.          screenHeight = _gameClipClassRef.screenHeight;
  130.          lastThingHit = _gameClipClassRef.lastThingHit;
  131.          if(bubblesArray != null)
  132.          {
  133.             activeBubbles = bubblesArray.length;
  134.             i = activeBubbles;
  135.             while(i--)
  136.             {
  137.                _itemBubbleRef = bubblesArray[i];
  138.                removeBubble = false;
  139.                if(!_itemBubbleRef.getCollected())
  140.                {
  141.                   _tempPoint = _itemBubbleRef.getLoc();
  142.                   _tempPoint.y += scrollYDist;
  143.                   dist = _trigClassRef.findDistance(playerScreenLoc,_tempPoint);
  144.                   _loc1_ = (_itemBubbleRef.getBubbleRadius() + playerBubbleRadius) * 0.65;
  145.                   if(dist <= _loc1_)
  146.                   {
  147.                      removeBubble = true;
  148.                      if(lastThingHit == HIT_ACORN)
  149.                      {
  150.                         ++hitInARow;
  151.                         if(hitInARow == 2)
  152.                         {
  153.                            _gameClipClassRef.tellInARow(3);
  154.                         }
  155.                         if(hitInARow == 4)
  156.                         {
  157.                            _gameClipClassRef.tellInARow(5);
  158.                         }
  159.                         if(hitInARow == 9)
  160.                         {
  161.                            _gameClipClassRef.tellInARow(10);
  162.                         }
  163.                         if(hitInARow == 24)
  164.                         {
  165.                            _gameClipClassRef.tellInARow(25);
  166.                         }
  167.                      }
  168.                      else
  169.                      {
  170.                         hitInARow = 0;
  171.                      }
  172.                      lastThingHit = HIT_ACORN;
  173.                      switch(_itemBubbleRef.getBubbleType)
  174.                      {
  175.                         case BUBBLE_TYPE_ACORN:
  176.                            _loc2_ = Math.random() * 3 + 1;
  177.                            _gameClipClassRef.playSound("acornCollected_" + _loc2_ + ".wav");
  178.                            ++acornsCollected;
  179.                            _gameClipClassRef.acornsCollected = acornsCollected;
  180.                            _gameClipClassRef.addPoints(50);
  181.                            _gameClipClassRef.particleEffect(PARTICLE_EFFECT_CHIP_PLACED,_tempPoint.x,_tempPoint.y);
  182.                            break;
  183.                         case BUBBLE_TYPE_HEALTH_POWERUP:
  184.                            _gameClipClassRef.playSound("powerUp_health.wav");
  185.                            ++acornsCollected;
  186.                            _gameClipClassRef.acornsCollected = acornsCollected;
  187.                            _gameClipClassRef.addPoints(250);
  188.                            _gameClipClassRef.addHealth(25);
  189.                            _gameClipClassRef.particleEffect(PARTICLE_EFFECT_FLICKER,_tempPoint.x,_tempPoint.y);
  190.                            break;
  191.                         case BUBBLE_TYPE_REVERSE:
  192.                            _gameClipClassRef.playSound("powerUp_reverseControls.wav");
  193.                            ++acornsCollected;
  194.                            _gameClipClassRef.acornsCollected = acornsCollected;
  195.                            _gameClipClassRef.addPoints(250);
  196.                            _gameClipClassRef.reverseControls();
  197.                            _gameClipClassRef.particleEffect(PARTICLE_EFFECT_FLICKER,_tempPoint.x,_tempPoint.y);
  198.                            break;
  199.                         case BUBBLE_TYPE_SHRINK:
  200.                            _gameClipClassRef.playSound("powerUp_shrink.wav");
  201.                            ++acornsCollected;
  202.                            _gameClipClassRef.acornsCollected = acornsCollected;
  203.                            _gameClipClassRef.addPoints(250);
  204.                            _gameClipClassRef.shrinkPlayer();
  205.                            _gameClipClassRef.particleEffect(PARTICLE_EFFECT_FLICKER,_tempPoint.x,_tempPoint.y);
  206.                            break;
  207.                         case BUBBLE_TYPE_INVINCIBLE:
  208.                            _gameClipClassRef.playSound("powerUp_invincible.wav");
  209.                            ++acornsCollected;
  210.                            _gameClipClassRef.acornsCollected = acornsCollected;
  211.                            _gameClipClassRef.addPoints(250);
  212.                            _gameClipClassRef.makeInvincible();
  213.                            _gameClipClassRef.particleEffect(PARTICLE_EFFECT_FLICKER,_tempPoint.x,_tempPoint.y);
  214.                      }
  215.                   }
  216.                   if(removeBubble)
  217.                   {
  218.                      _itemBubbleRef.setCollected();
  219.                      _clip = _itemBubbleRef.getClip();
  220.                      _clip = null;
  221.                      bubblesArray.splice(i,1);
  222.                   }
  223.                   else
  224.                   {
  225.                      _itemBubbleRef.drawBubble(_tempPoint);
  226.                   }
  227.                }
  228.             }
  229.             _gameClipClassRef.lastThingHit = lastThingHit;
  230.             _gameClipClassRef.bubblesArray = bubblesArray;
  231.          }
  232.       }
  233.    }
  234. }
  235.  
  236.