home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / attention_hog.swf / scripts / __Packages / com / leadpipe / attentionhog / Item.as < prev    next >
Encoding:
Text File  |  2008-09-22  |  3.9 KB  |  133 lines

  1. class com.leadpipe.attentionhog.Item extends MovieClip
  2. {
  3.    var timerWarn;
  4.    var timerEnd;
  5.    var isPowerUp;
  6.    var type;
  7.    var itemImage_mc;
  8.    var bounds_obj;
  9.    var hit;
  10.    var point;
  11.    var pointPlayer;
  12.    var distInit;
  13.    static var play_maxY = 380;
  14.    static var instanceList = new Array();
  15.    function Item()
  16.    {
  17.       super();
  18.       com.leadpipe.attentionhog.Item.instanceList.push(this);
  19.       this.timerWarn = new com.leadpipe.attentionhog.Timer(this,"warn",6400,6400);
  20.       this.timerWarn.start();
  21.       this.timerEnd = new com.leadpipe.attentionhog.Timer(this,"destroy",7000,7000);
  22.       this.timerEnd.start();
  23.       this.setType();
  24.       this.setPos();
  25.    }
  26.    function onEnterFrame()
  27.    {
  28.       if(this.checkCollision(_root.player_mc.body_mc))
  29.       {
  30.          _root.player_mc.startGrunt();
  31.          if(this.isPowerUp)
  32.          {
  33.             com.leadpipe.attentionhog.Player.instance.abilities[this.type - 1].startPowerUp();
  34.          }
  35.          else
  36.          {
  37.             com.leadpipe.attentionhog.Game.instance.gaugeSlop[this.type - 1].increase();
  38.          }
  39.          this.destroy();
  40.       }
  41.    }
  42.    function setType()
  43.    {
  44.       this.type = random(com.leadpipe.attentionhog.Game.instance.getItemsUnlocked()) + 1;
  45.       if(random(12) == 0)
  46.       {
  47.          this.isPowerUp = true;
  48.          this.itemImage_mc.gotoAndStop(this.type + 6);
  49.       }
  50.       else
  51.       {
  52.          this.isPowerUp = false;
  53.          this.itemImage_mc.gotoAndStop(this.type);
  54.       }
  55.    }
  56.    function checkCollision(mc)
  57.    {
  58.       this.bounds_obj = this.getBounds(_root);
  59.       if(mc.hitTest(this.bounds_obj.xMin,this.bounds_obj.yMin,true) || mc.hitTest(this.bounds_obj.xMin,this.bounds_obj.yMax,true) || mc.hitTest(this.bounds_obj.xMax,this.bounds_obj.yMin,true) || mc.hitTest(this.bounds_obj.xMax,this.bounds_obj.yMax,true))
  60.       {
  61.          this.hit = true;
  62.       }
  63.       else
  64.       {
  65.          this.hit = false;
  66.       }
  67.       return this.hit;
  68.    }
  69.    function destroy()
  70.    {
  71.       this.timerWarn.clear();
  72.       this.timerEnd.clear();
  73.       for(var _loc2_ in com.leadpipe.attentionhog.Item.instanceList)
  74.       {
  75.          if(com.leadpipe.attentionhog.Item.instanceList[_loc2_] == this)
  76.          {
  77.             com.leadpipe.attentionhog.Item.instanceList.splice(_loc2_,1);
  78.             break;
  79.          }
  80.       }
  81.       this.removeMovieClip();
  82.    }
  83.    function warn()
  84.    {
  85.       this.timerWarn.clear();
  86.       this.gotoAndPlay("warn");
  87.    }
  88.    function setPosRandom()
  89.    {
  90.       this._x = this.randomInt(50,Stage.width - 20);
  91.       this._y = this.randomInt(50,410);
  92.    }
  93.    function setPos()
  94.    {
  95.       this.point = new flash.geom.Point(this.randomInt(50,Stage.width - 20),this.randomInt(50,410));
  96.       this.pointPlayer = new flash.geom.Point(_root.player_mc._x,_root.player_mc._y);
  97.       this.distInit = flash.geom.Point.distance(this.point,this.pointPlayer);
  98.       while(this.distInit < 60)
  99.       {
  100.          this.point = new flash.geom.Point(this.randomInt(50,Stage.width - 20),this.randomInt(50,410));
  101.          this.distInit = flash.geom.Point.distance(this.point,this.pointPlayer);
  102.       }
  103.       this._x = this.point.x;
  104.       this._y = this.point.y;
  105.    }
  106.    function randomInt(min, max)
  107.    {
  108.       return Math.floor(Math.random() * (max - min + 1)) + min;
  109.    }
  110.    static function destroyAll()
  111.    {
  112.       for(var _loc1_ in com.leadpipe.attentionhog.Item.instanceList)
  113.       {
  114.          com.leadpipe.attentionhog.Item.instanceList[_loc1_].destroy();
  115.       }
  116.       com.leadpipe.attentionhog.Item.instanceList = new Array();
  117.    }
  118.    static function pauseAll()
  119.    {
  120.       for(var _loc1_ in com.leadpipe.attentionhog.Item.instanceList)
  121.       {
  122.          com.leadpipe.attentionhog.Item.instanceList[_loc1_].pause();
  123.       }
  124.    }
  125.    static function resumeAll()
  126.    {
  127.       for(var _loc1_ in com.leadpipe.attentionhog.Item.instanceList)
  128.       {
  129.          com.leadpipe.attentionhog.Item.instanceList[_loc1_].resume();
  130.       }
  131.    }
  132. }
  133.