home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / FishyHop.swf / scripts / __Packages / LittleFish.as < prev    next >
Encoding:
Text File  |  2008-09-05  |  2.9 KB  |  129 lines

  1. class LittleFish extends MovieClip
  2. {
  3.    var isJump;
  4.    var isUnder;
  5.    var isFly;
  6.    var isDead;
  7.    var isInit;
  8.    var onKeyDown;
  9.    var onKeyUp;
  10.    var road_num;
  11.    var y_arr;
  12.    function LittleFish()
  13.    {
  14.       super();
  15.       this.setListener();
  16.    }
  17.    function initFish()
  18.    {
  19.       this.isJump = false;
  20.       this.isUnder = false;
  21.       this.isFly = false;
  22.       this.isDead = false;
  23.       this.isInit = true;
  24.    }
  25.    function setListener()
  26.    {
  27.       var tempFish;
  28.       tempFish = this;
  29.       this.onKeyDown = function()
  30.       {
  31.          if(_root.game.isPause == false && !this.isDead)
  32.          {
  33.             if(Key.isDown(37))
  34.             {
  35.                tempFish.doDown();
  36.             }
  37.             if(Key.isDown(38))
  38.             {
  39.                tempFish.doMoveUp();
  40.             }
  41.             if(Key.isDown(40))
  42.             {
  43.                tempFish.doMoveDown();
  44.             }
  45.             if(Key.isDown(39))
  46.             {
  47.                tempFish.doJump();
  48.             }
  49.          }
  50.       };
  51.       this.onKeyUp = function()
  52.       {
  53.          if(_root.game.isPause == false && !this.isDead)
  54.          {
  55.             if(Key.getCode() == 37)
  56.             {
  57.                tempFish.doUp();
  58.             }
  59.          }
  60.       };
  61.       Key.addListener(this);
  62.    }
  63.    function doDown()
  64.    {
  65.       if(!this.isUnder && !this.isJump)
  66.       {
  67.          this.gotoAndPlay("down");
  68.          this.isUnder = true;
  69.          this.isFly = false;
  70.          _root.game.soundManage.playSound("down_s");
  71.       }
  72.    }
  73.    function doUp()
  74.    {
  75.       if(this.isUnder)
  76.       {
  77.          this.gotoAndPlay("up");
  78.          this.isUnder = false;
  79.          _root.game.soundManage.playSound("up_s");
  80.       }
  81.    }
  82.    function doMoveUp()
  83.    {
  84.       if(!this.isJump)
  85.       {
  86.          if(this.road_num > 0)
  87.          {
  88.             this.road_num = this.road_num - 1;
  89.             !this.isFly ? this.gotoAndPlay("move") : 1;
  90.             this._y = this.y_arr[this.road_num] - 8;
  91.             this.swapDepths(this.road_num * 100 + 98);
  92.          }
  93.          else
  94.          {
  95.             this.road_num = 0;
  96.             !this.isUnder ? 1 : this.gotoAndPlay("move");
  97.          }
  98.       }
  99.    }
  100.    function doMoveDown()
  101.    {
  102.       if(!this.isJump)
  103.       {
  104.          if(this.road_num < this.y_arr.length - 1)
  105.          {
  106.             this.road_num = this.road_num + 1;
  107.             !this.isFly ? this.gotoAndPlay("moveDown") : 1;
  108.             this._y = this.y_arr[this.road_num] - 8;
  109.             this.swapDepths(this.road_num * 100 + 98);
  110.          }
  111.          else
  112.          {
  113.             this.road_num = this.y_arr.length - 1;
  114.             !this.isUnder ? 1 : this.gotoAndPlay("move");
  115.          }
  116.       }
  117.    }
  118.    function doJump()
  119.    {
  120.       if(!this.isJump)
  121.       {
  122.          this.gotoAndPlay("jump");
  123.          this.isJump = true;
  124.          this.isFly = false;
  125.          _root.game.soundManage.playSound("jump_s");
  126.       }
  127.    }
  128. }
  129.