home *** CD-ROM | disk | FTP | other *** search
- function initialization()
- {
- fullHp = hp;
- vx = 0;
- vy = 0;
- startJump = false;
- floorY = _parent._y;
- frozenCounter = 0;
- dieCounter = 0;
- invincibleCounter = 0;
- team = _parent.team;
- rebornRate = _parent.rebornRate;
- comeOutPoint = _parent.comeOutPoint;
- hidePoint = _parent.hidePoint;
- gameEngine.addToList("characterList" + team,{id:eval(_target),parent:eval(_parent._target)});
- if(team == 0)
- {
- gameEngine.mainCharHp(hp,fullHp);
- }
- movie = eval(_parent.movie);
- if(team == 1)
- {
- _parent._visible = false;
- _parent._alpha = 0;
- movie.gotoAndPlay("sleep");
- }
- initialized = true;
- }
- function move(s)
- {
- _parent._x += s;
- }
- function scrollBackground()
- {
- if(_parent._x > 400)
- {
- gameEngine.moveBackgroundRequest((400 - _parent._x) / 10);
- }
- if(_parent._x < 300)
- {
- gameEngine.moveBackgroundRequest((300 - _parent._x) / 10);
- }
- }
- function state_Walk()
- {
- if(_parent.input.right)
- {
- _parent._xscale = 100;
- }
- if(_parent.input.left)
- {
- _parent._xscale = -100;
- }
- if(_parent.input.attack && canAttack)
- {
- movie.gotoAndPlay("attack");
- }
- else if(_parent.input.up && canJump)
- {
- movie.gotoAndPlay("jump");
- startJump = true;
- }
- else if(_parent.input.right)
- {
- if(canWalk)
- {
- movie.play();
- _parent._x += walkVX;
- }
- }
- else if(_parent.input.left)
- {
- if(canWalk)
- {
- movie.play();
- _parent._x -= walkVX;
- }
- }
- else
- {
- movie.stop();
- }
- }
- function state_Jump()
- {
- if(startJump)
- {
- vy = jumpVY;
- if(_parent.input.right)
- {
- vx = jumpVX;
- }
- else if(_parent.input.left)
- {
- vx = - jumpVX;
- }
- startJump = false;
- }
- else if(_parent._y >= floorY)
- {
- _parent._y = floorY;
- vx = 0;
- vy = 0;
- movie.state = "crouch";
- movie.gotoAndPlay("crouch");
- }
- else if(movie.state == "jump" && _parent.input.attack && canJumpAttack)
- {
- movie.gotoAndPlay("jumpAttack");
- }
- }
- function state_Hurt()
- {
- if(_parent._y >= floorY)
- {
- _parent._y = floorY;
- vx = 0;
- vy = 0;
- movie.state = "die";
- movie.gotoAndPlay("die");
- }
- }
- function state_Die()
- {
- if(_parent._alpha > 0)
- {
- _parent._alpha -= 10;
- }
- else
- {
- _parent._visible = false;
- var canReborn = false;
- if(team == 0)
- {
- if(_global.life > 0)
- {
- gameEngine.deductLife(1);
- canReborn = true;
- }
- else if(gameEngine.gameOver == false)
- {
- gameEngine.gameIsOver();
- }
- }
- if(team == 1 && gameEngine.backgroundX >= comeOutPoint && gameEngine.backgroundX <= hidePoint && random(rebornRate) == 0 && gameEngine.stageClear == false)
- {
- canReborn = true;
- }
- if(canReborn)
- {
- _parent._visible = true;
- _parent._y = floorY;
- _parent._alpha = 100;
- movie.gotoAndPlay("walk");
- hp = fullHp;
- if(team == 1)
- {
- if(random(2) == 0)
- {
- _parent._x = -200;
- _parent._xscale = 100;
- }
- else
- {
- _parent._x = 900;
- _parent._xscale = -100;
- }
- }
- if(team == 0)
- {
- invincibleCounter = 125;
- }
- }
- }
- }
- function physics()
- {
- if(_parent._y < floorY || vy != 0)
- {
- _parent._y += vy;
- vy += gameEngine.gravity;
- }
- _parent._x += vx;
- if(_parent._y == floorY && vy == 0)
- {
- vx /= 1.5;
- }
- }
- function attackBy(attacker, hpDeduct)
- {
- hp += hpDeduct;
- if(attacker._parent._xscale > 0)
- {
- vx = 15;
- }
- else
- {
- vx = -15;
- }
- if(hp <= 0)
- {
- hp = 0;
- if(attacker._parent._xscale > 0)
- {
- _parent._xscale = -100;
- }
- else
- {
- _parent._xscale = 100;
- }
- vy = -15;
- if(team == 1)
- {
- gameEngine.addScore(score);
- }
- }
- if(hp > fullHp)
- {
- hp = fullHp;
- }
- attacker.frozenCounter = 2;
- frozenCounter = -4;
- if(team == 0)
- {
- invincibleCounter = 25;
- }
- }
- function run()
- {
- if(hp == 0 && movie.state != "hurt" && movie.state != "die")
- {
- movie.state = "hurt";
- movie.gotoAndPlay("hurt");
- }
- if(invincibleCounter > 0)
- {
- invincibleCounter--;
- _parent._alpha = 100 - invincibleCounter % 2 * 50;
- }
- if(frozenCounter == 0)
- {
- physics();
- if(movie.state == "walk")
- {
- state_Walk();
- }
- else if(movie.state == "jump" || movie.state == "jumpAttack")
- {
- state_Jump();
- }
- else if(movie.state == "hurt")
- {
- state_Hurt();
- }
- else if(movie.state == "die")
- {
- state_Die();
- }
- }
- else if(frozenCounter > 0)
- {
- frozenCounter--;
- }
- else if(frozenCounter < 0)
- {
- _parent._x += frozenCounter % 2 * 8 + 4;
- frozenCounter++;
- }
- if(team == 0)
- {
- scrollBackground();
- if(_parent._x < 0)
- {
- _parent._x = 0;
- }
- if(_parent._x > gameEngine.width)
- {
- _parent._x = gameEngine.width;
- }
- }
- else
- {
- if(_parent._x < -200)
- {
- _parent._x = 900;
- _parent._xscale = -100;
- }
- if(_parent._x > 900)
- {
- _parent._x = -200;
- _parent._xscale = 100;
- }
- }
- }
- onEnterFrame = function()
- {
- if(_parent.movie == undefined)
- {
- if(movieNotFound == undefined)
- {
- trace("WARNING: badgeCharacter:[" + _target + "] --- Instance:[movie] not found!");
- movieNotFound = true;
- }
- }
- else if(initialized == undefined)
- {
- gameEngine = eval(gameEngineName);
- if(gameEngine == undefined)
- {
- if(gameEngineNotFound == undefined)
- {
- trace("WARNING: badgeCharacter:[" + _target + "] --- gameEngine:[" + gameEngineName + "] not found!");
- gameEngineNotFound = true;
- }
- }
- else if(gameEngine.initialized == true)
- {
- initialization();
- }
- }
- else
- {
- run();
- }
- };
-