home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Easter_Eggs.swf / scripts / __Packages / com / novelgames / flashgames / eggsAS2 / Egg.as < prev    next >
Text File  |  2008-09-04  |  5KB  |  138 lines

  1. class com.novelgames.flashgames.eggsAS2.Egg extends com.novelgames.flashgames.commonAS2.NewMovieClip
  2. {
  3.    function Egg()
  4.    {
  5.       super();
  6.       this.button.__proto__ = com.novelgames.flashgames.commonAS2.NewButton.prototype;
  7.       this.picture.__proto__ = com.novelgames.flashgames.commonAS2.NewMovieClip.prototype;
  8.    }
  9.    function initialize(x, y, type)
  10.    {
  11.       this.__set__x(x);
  12.       this.__set__y(y);
  13.       this.type = type;
  14.       this.picture.gotoAndStop(type + 1);
  15.       this.showNormal();
  16.       this.cacheAsBitmap = true;
  17.       this.button.addEventListener(com.novelgames.flashgames.commonAS2.MouseEvent.CLICK,this,"buttonClicked");
  18.    }
  19.    function setXY(x, y)
  20.    {
  21.       this.indexX = x;
  22.       this.indexY = y;
  23.    }
  24.    function showNormal()
  25.    {
  26.       this.button.__set__visible(true);
  27.       this.gotoAndStop("normal");
  28.    }
  29.    function showChosen()
  30.    {
  31.       this.button.__set__visible(false);
  32.       this.gotoAndStop("chosen");
  33.    }
  34.    function swapTo(x, y)
  35.    {
  36.       this.targetX = x;
  37.       this.targetY = y;
  38.       this.targetRealX = Object(this.__get__parent().parent).getRealX(x,y);
  39.       this.targetRealY = Object(this.__get__parent().parent).getRealY(x,y);
  40.       this.speedX = (this.targetRealX - this.__get__x()) * 1000 / com.novelgames.flashgames.eggsAS2.Config.SWAPTIME;
  41.       this.speedY = (this.targetRealY - this.__get__y()) * 1000 / com.novelgames.flashgames.eggsAS2.Config.SWAPTIME;
  42.       this.isSwapping = true;
  43.       this.startTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
  44.       this.endTime = this.startTime + com.novelgames.flashgames.eggsAS2.Config.SWAPTIME;
  45.       this.lastTime = this.startTime;
  46.    }
  47.    function unswapTo(x, y)
  48.    {
  49.       this.targetX = x;
  50.       this.targetY = y;
  51.       this.targetRealX = Object(this.__get__parent().parent).getRealX(x,y);
  52.       this.targetRealY = Object(this.__get__parent().parent).getRealY(x,y);
  53.       this.speedX = (this.targetRealX - this.__get__x()) * 1000 / com.novelgames.flashgames.eggsAS2.Config.SWAPTIME;
  54.       this.speedY = (this.targetRealY - this.__get__y()) * 1000 / com.novelgames.flashgames.eggsAS2.Config.SWAPTIME;
  55.       this.isUnswapping = true;
  56.       this.startTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
  57.       this.endTime = this.startTime + com.novelgames.flashgames.eggsAS2.Config.SWAPTIME;
  58.       this.lastTime = this.startTime;
  59.    }
  60.    function destroy()
  61.    {
  62.       this.isDestroying = true;
  63.       this.startTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
  64.    }
  65.    function drop(y)
  66.    {
  67.       this.targetX = this.indexX;
  68.       this.targetY = y;
  69.       this.targetRealX = this.x;
  70.       this.targetRealY = Object(this.__get__parent().parent).getRealY(this.indexX,y);
  71.       this.speedX = 0;
  72.       this.speedY = com.novelgames.flashgames.eggsAS2.Config.DROPSPEED;
  73.       this.isDropping = true;
  74.       this.startTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
  75.       this.endTime = this.startTime + Math.floor((this.targetRealY - this.__get__y()) * 1000 / com.novelgames.flashgames.eggsAS2.Config.DROPSPEED);
  76.       this.lastTime = this.startTime;
  77.    }
  78.    function onTime()
  79.    {
  80.       var _loc2_ = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
  81.       this.move(_loc2_);
  82.       this.lastTime = _loc2_;
  83.    }
  84.    function move(time)
  85.    {
  86.       var _loc2_ = undefined;
  87.       if(!Object(this.__get__parent().parent).gameStarted)
  88.       {
  89.          return undefined;
  90.       }
  91.       if(this.isSwapping || this.isUnswapping || this.isDropping)
  92.       {
  93.          this.x += this.speedX * (time - this.lastTime) / 1000;
  94.          this.y += this.speedY * (time - this.lastTime) / 1000;
  95.          if(time >= this.endTime)
  96.          {
  97.             this.__set__x(this.targetRealX);
  98.             this.__set__y(this.targetRealY);
  99.             if(this.isSwapping)
  100.             {
  101.                this.isSwapping = false;
  102.                Object(this.__get__parent().parent).finishSwapping();
  103.             }
  104.             else if(this.isUnswapping)
  105.             {
  106.                this.isUnswapping = false;
  107.                Object(this.__get__parent().parent).finishUnswapping();
  108.             }
  109.             else if(this.isDropping)
  110.             {
  111.                this.isDropping = false;
  112.                Object(this.__get__parent().parent).finishDropping();
  113.             }
  114.          }
  115.       }
  116.       else if(this.isDestroying)
  117.       {
  118.          _loc2_ = (time - this.startTime) / com.novelgames.flashgames.eggsAS2.Config.DESTROYTIME;
  119.          if(_loc2_ > 1)
  120.          {
  121.             _loc2_ = 1;
  122.          }
  123.          this.__set__scaleX(1 - _loc2_);
  124.          this.__set__scaleY(1 - _loc2_);
  125.          if(_loc2_ >= 1)
  126.          {
  127.             this.__set__visible(false);
  128.             this.isDestroying = false;
  129.             Object(this.__get__parent().parent).finishDestroying();
  130.          }
  131.       }
  132.    }
  133.    function buttonClicked(mouseEvent)
  134.    {
  135.       Object(this.__get__parent().parent).chooseEgg(this);
  136.    }
  137. }
  138.