home *** CD-ROM | disk | FTP | other *** search
- class LittleFish extends MovieClip
- {
- var isJump;
- var isUnder;
- var isFly;
- var isDead;
- var isInit;
- var onKeyDown;
- var onKeyUp;
- var road_num;
- var y_arr;
- function LittleFish()
- {
- super();
- this.setListener();
- }
- function initFish()
- {
- this.isJump = false;
- this.isUnder = false;
- this.isFly = false;
- this.isDead = false;
- this.isInit = true;
- }
- function setListener()
- {
- var tempFish;
- tempFish = this;
- this.onKeyDown = function()
- {
- if(_root.game.isPause == false && !this.isDead)
- {
- if(Key.isDown(37))
- {
- tempFish.doDown();
- }
- if(Key.isDown(38))
- {
- tempFish.doMoveUp();
- }
- if(Key.isDown(40))
- {
- tempFish.doMoveDown();
- }
- if(Key.isDown(39))
- {
- tempFish.doJump();
- }
- }
- };
- this.onKeyUp = function()
- {
- if(_root.game.isPause == false && !this.isDead)
- {
- if(Key.getCode() == 37)
- {
- tempFish.doUp();
- }
- }
- };
- Key.addListener(this);
- }
- function doDown()
- {
- if(!this.isUnder && !this.isJump)
- {
- this.gotoAndPlay("down");
- this.isUnder = true;
- this.isFly = false;
- _root.game.soundManage.playSound("down_s");
- }
- }
- function doUp()
- {
- if(this.isUnder)
- {
- this.gotoAndPlay("up");
- this.isUnder = false;
- _root.game.soundManage.playSound("up_s");
- }
- }
- function doMoveUp()
- {
- if(!this.isJump)
- {
- if(this.road_num > 0)
- {
- this.road_num = this.road_num - 1;
- !this.isFly ? this.gotoAndPlay("move") : 1;
- this._y = this.y_arr[this.road_num] - 8;
- this.swapDepths(this.road_num * 100 + 98);
- }
- else
- {
- this.road_num = 0;
- !this.isUnder ? 1 : this.gotoAndPlay("move");
- }
- }
- }
- function doMoveDown()
- {
- if(!this.isJump)
- {
- if(this.road_num < this.y_arr.length - 1)
- {
- this.road_num = this.road_num + 1;
- !this.isFly ? this.gotoAndPlay("moveDown") : 1;
- this._y = this.y_arr[this.road_num] - 8;
- this.swapDepths(this.road_num * 100 + 98);
- }
- else
- {
- this.road_num = this.y_arr.length - 1;
- !this.isUnder ? 1 : this.gotoAndPlay("move");
- }
- }
- }
- function doJump()
- {
- if(!this.isJump)
- {
- this.gotoAndPlay("jump");
- this.isJump = true;
- this.isFly = false;
- _root.game.soundManage.playSound("jump_s");
- }
- }
- }
-