home *** CD-ROM | disk | FTP | other *** search
- class Player extends Entity
- {
- var scripttimer;
- var scriptlock;
- var entity;
- var inputlocked;
- var grounded;
- var inp;
- var queuedinp;
- var animationtick;
- var oldanim;
- var newanim;
- var dead;
- var HP;
- var lastinp;
- var attackkeydown;
- var jumpkeydown;
- var x;
- var xv;
- var y;
- var yv;
- var z;
- var zv;
- var myname;
- var i;
- static var PLAYER_ID = "player";
- static var ACCELLERATION = 2;
- static var MAX_SPEED = 8;
- static var JUMP_VELOCITY = 20;
- static var keylog = new Array();
- var scriptedmove = new Array();
- function Player(target, entityname, startx, starty, startz, startsize, collides)
- {
- super(target,entityname,startx,starty,startz,startsize,collides);
- this.scripttimer = 0;
- this.scriptlock = false;
- this.entity.gotoAndStop(Player.PLAYER_ID);
- this.entity.combo = 0;
- this.inputlocked = false;
- this.grounded = true;
- this.entity.attacking = false;
- this.entity.hurting = false;
- this.inp = "neutral";
- this.queuedinp = "none";
- this.animationtick = 0;
- this.oldanim = "null";
- this.newanim = "idle";
- this.entity.lastattack = "none";
- this.dead = false;
- this.HP = 100;
- }
- function addscriptedmove(keystroke, duration)
- {
- this.scriptedmove.push({action:keystroke,frames:duration});
- }
- function update()
- {
- if(this.scriptedmove.length > 0 || this.scripttimer > 0)
- {
- this.scriptlock = true;
- this.scripttimer = this.scripttimer - 1;
- if(this.scripttimer < 1)
- {
- if(this.scriptedmove.length < 1)
- {
- this.scriptlock = false;
- }
- else
- {
- this.inp = this.scriptedmove[0].action;
- this.scripttimer = this.scriptedmove[0].frames;
- this.scriptedmove.splice(0,1);
- }
- }
- }
- this.entity._parent._parent._parent.playerhp = this.HP;
- this.HP += 0.05;
- if(this.HP > 100)
- {
- this.HP = 100;
- }
- this.lastinp = this.inp;
- if(!this.scriptlock)
- {
- this.inp = "neutral";
- if(Key.isDown(37))
- {
- this.addinput("left");
- }
- if(Key.isDown(39))
- {
- this.addinput("right");
- }
- if(Key.isDown(38))
- {
- this.addinput("up");
- }
- if(Key.isDown(40))
- {
- this.addinput("down");
- }
- if(Key.isDown(65))
- {
- if(!this.attackkeydown)
- {
- this.addinput("attack");
- }
- this.attackkeydown = true;
- }
- else
- {
- this.attackkeydown = false;
- }
- if(Key.isDown(83))
- {
- if(!this.jumpkeydown)
- {
- this.addinput("jump");
- }
- this.jumpkeydown = true;
- }
- else
- {
- this.jumpkeydown = false;
- }
- }
- this.logkeys();
- this.takeaction();
- if(this.HP < 0 && this.HP != -100)
- {
- _root.deathscreen.play();
- GameStage.TIME_STEP -= 0.02;
- if(GameStage.TIME_STEP < 0)
- {
- GameStage.TIME_STEP = 0;
- }
- this.HP = -100;
- this.newanim = "die";
- this.scriptlock = true;
- }
- this.updateanimation();
- this.x += this.xv * GameStage.TIME_STEP;
- this.y += this.yv * GameStage.TIME_STEP;
- this.z += this.zv * GameStage.TIME_STEP;
- this.entity._x = this.x;
- this.entity._y = GameStage.GROUND_LEVEL + this.y / 3 - this.z;
- this.animationtick += GameStage.TIME_STEP;
- if(this.animationtick >= 1)
- {
- this.animationtick -= 1;
- this.entity.anims.nextFrame();
- }
- EntityManager.MANAGER.entityCollide(this.myname,this);
- this.entity.x = this.x;
- this.entity.y = this.y;
- this.entity.z = this.z;
- }
- function addinput(newinp)
- {
- switch(this.inp)
- {
- case "default":
- this.inp = newinp;
- break;
- case "upleft":
- if(newinp == "right")
- {
- this.inp = "up";
- }
- if(newinp == "down")
- {
- this.inp = "left";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "up":
- if(newinp == "left")
- {
- this.inp = "upleft";
- }
- if(newinp == "right")
- {
- this.inp = "upright";
- }
- if(newinp == "down")
- {
- this.inp = "neutral";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "upright":
- if(newinp == "left")
- {
- this.inp = "up";
- }
- if(newinp == "down")
- {
- this.inp = "right";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "left":
- if(newinp == "right")
- {
- this.inp = "neutral";
- }
- if(newinp == "up")
- {
- this.inp = "upleft";
- }
- if(newinp == "down")
- {
- this.inp = "downleft";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- if(this.entity._xscale > 0)
- {
- this.inp = "backattack";
- }
- else
- {
- this.inp = "attack";
- }
- }
- break;
- case "neutral":
- if(newinp == "left")
- {
- this.inp = "left";
- }
- if(newinp == "right")
- {
- this.inp = "right";
- }
- if(newinp == "up")
- {
- this.inp = "up";
- }
- if(newinp == "down")
- {
- this.inp = "down";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "right":
- if(newinp == "left")
- {
- this.inp = "neutral";
- }
- if(newinp == "up")
- {
- this.inp = "upright";
- }
- if(newinp == "down")
- {
- this.inp = "downright";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- if(this.entity._xscale < 0)
- {
- this.inp = "backattack";
- }
- else
- {
- this.inp = "attack";
- }
- }
- break;
- case "downleft":
- if(newinp == "right")
- {
- this.inp = "down";
- }
- if(newinp == "up")
- {
- this.inp = "left";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "down":
- if(newinp == "left")
- {
- this.inp = "downleft";
- }
- if(newinp == "right")
- {
- this.inp = "downright";
- }
- if(newinp == "up")
- {
- this.inp = "neutral";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "downright":
- if(newinp == "left")
- {
- this.inp = "down";
- }
- if(newinp == "up")
- {
- this.inp = "right";
- }
- if(newinp == "jump")
- {
- this.inp = "jump";
- }
- if(newinp == "attack")
- {
- this.inp = "attack";
- }
- break;
- case "attack":
- if(newinp == "jump")
- {
- this.inp = "jumpattack";
- }
- }
- }
- function logkeys()
- {
- if(this.lastinp == this.inp)
- {
- Player.keylog.push("hold");
- }
- else
- {
- Player.keylog.push(this.inp);
- }
- if(Player.keylog.length > 2)
- {
- Player.keylog.splice(0,Player.keylog.length - 2);
- }
- }
- function takeaction()
- {
- if(this.entity.combo > 0)
- {
- this.entity.combo--;
- }
- if(!this.inputlocked)
- {
- if(this.queuedinp != "none")
- {
- Player.keylog[0] = this.queuedinp;
- this.queuedinp = "none";
- }
- if(this.inp == "left" || this.inp == "upleft" || this.inp == "downleft")
- {
- if(this.grounded)
- {
- this.xv -= Player.ACCELLERATION * GameStage.TIME_STEP;
- }
- }
- if(this.inp == "right" || this.inp == "upright" || this.inp == "downright")
- {
- if(this.grounded)
- {
- this.xv += Player.ACCELLERATION * GameStage.TIME_STEP;
- }
- }
- if(this.inp == "upleft" || this.inp == "up" || this.inp == "upright")
- {
- if(this.grounded)
- {
- this.yv -= Player.ACCELLERATION * GameStage.TIME_STEP;
- }
- }
- if(this.inp == "downleft" || this.inp == "down" || this.inp == "downright")
- {
- if(this.grounded)
- {
- this.yv += Player.ACCELLERATION * GameStage.TIME_STEP;
- }
- }
- if(Player.keylog[0] == "jump" && Player.keylog[1] == "attack" || Player.keylog[0] == "attack" && Player.keylog[1] == "jump" || Player.keylog[0] == "jumpattack")
- {
- if(this.grounded)
- {
- this.xv *= 0.5;
- this.yv = 0;
- this.grounded = false;
- this.zv = Player.JUMP_VELOCITY;
- this.newanim = "jumpattack";
- }
- }
- else if(Player.keylog[0] == "jump")
- {
- if(this.grounded)
- {
- this.xv *= 1.3;
- this.yv = 0;
- this.grounded = false;
- this.zv = Player.JUMP_VELOCITY;
- this.newanim = "jump";
- }
- }
- else if(Player.keylog[1] == "backattack" || Player.keylog[0] == "attack" && Player.keylog[1] == "left" && this.entity._xscale > 0 || Player.keylog[0] == "attack" && Player.keylog[1] == "right" && this.entity._xscale < 0 || Player.keylog[0] == "backattack")
- {
- if(this.grounded)
- {
- if(this.entity.combo > 0)
- {
- if(this.entity.lastattack == "backattack")
- {
- this.entity._xscale = - this.entity._xscale;
- this.newanim = "attack1";
- this.entity.lastattack = "attack1";
- }
- else
- {
- this.newanim = "backattack";
- this.entity.lastattack = "backattack";
- }
- }
- else
- {
- this.newanim = "backattack";
- this.entity.lastattack = "backattack";
- }
- this.entity.attacking = true;
- this.inputlocked = true;
- }
- }
- else if(Player.keylog[0] == "attack")
- {
- if(this.grounded)
- {
- if(Math.abs(this.xv) > 5)
- {
- this.newanim = "runattack";
- this.entity.lastattack = "runattack";
- }
- else if(this.entity.combo > 0)
- {
- if(this.entity.lastattack == "attack1")
- {
- this.newanim = "attack2";
- this.entity.lastattack = "attack2";
- }
- else if(this.entity.lastattack == "attack2")
- {
- this.newanim = "attack3";
- this.entity.lastattack = "attack3";
- }
- else
- {
- this.newanim = "attack1";
- this.entity.lastattack = "attack1";
- }
- }
- else
- {
- this.newanim = "attack1";
- this.entity.lastattack = "attack1";
- }
- this.entity.attacking = true;
- this.inputlocked = true;
- }
- else
- {
- if(this.entity.combo > 0)
- {
- if(this.entity.lastattack == "airattack")
- {
- this.newanim = "airattack2";
- this.entity.lastattack = "airattack2";
- }
- else
- {
- this.newanim = "airattack";
- this.entity.lastattack = "airattack";
- }
- }
- else
- {
- this.newanim = "airattack";
- this.entity.lastattack = "airattack";
- }
- this.entity.attacking = true;
- this.inputlocked = true;
- }
- }
- }
- else
- {
- if(Player.keylog[0] != "hold" && Player.keylog[0] != "neutral" && Player.keylog[0] != "left" && Player.keylog[0] != "right" && Player.keylog[0] != "up" && Player.keylog[0] != "down")
- {
- this.queuedinp = Player.keylog[0];
- }
- if(!this.entity.attacking && !this.entity.hurting)
- {
- this.inputlocked = false;
- }
- }
- if(this.grounded)
- {
- if(!this.entity.attacking)
- {
- if(this.xv < - Player.MAX_SPEED)
- {
- this.xv = - Player.MAX_SPEED;
- }
- if(this.xv > Player.MAX_SPEED)
- {
- this.xv = Player.MAX_SPEED;
- }
- if(this.yv > Player.MAX_SPEED)
- {
- this.yv = Player.MAX_SPEED;
- }
- if(this.yv < - Player.MAX_SPEED)
- {
- this.yv = - Player.MAX_SPEED;
- }
- }
- this.xv *= Math.pow(0.8,GameStage.TIME_STEP);
- this.yv *= Math.pow(0.8,GameStage.TIME_STEP);
- }
- else
- {
- this.zv -= GameStage.GRAVITY * GameStage.TIME_STEP;
- if(this.z + this.zv < 0)
- {
- this.zv = 0;
- this.z = 0;
- this.grounded = true;
- this.entity.attacking = false;
- if(this.HP >= 0)
- {
- this.entity.anims.gotoAndStop("idle");
- }
- this.entity.anim = "idle";
- this.entity.hurting = false;
- if(this.xv < - Player.MAX_SPEED)
- {
- this.xv = - Player.MAX_SPEED;
- }
- if(this.xv > Player.MAX_SPEED)
- {
- this.xv = Player.MAX_SPEED;
- }
- if(this.yv > Player.MAX_SPEED)
- {
- this.yv = Player.MAX_SPEED;
- }
- if(this.yv < - Player.MAX_SPEED)
- {
- this.yv = - Player.MAX_SPEED;
- }
- }
- }
- if(this.x < GameStage.LEFT_LIMIT)
- {
- this.x = GameStage.LEFT_LIMIT;
- }
- if(this.x > GameStage.RIGHT_LIMIT)
- {
- this.x = GameStage.RIGHT_LIMIT;
- }
- if(this.y < 0)
- {
- this.y = 0;
- }
- if(this.y > 150)
- {
- this.y = 150;
- }
- }
- function updateanimation()
- {
- if(this.grounded && !this.entity.attacking && !this.entity.hurting)
- {
- if(this.xv < -2)
- {
- this.entity._xscale = -100;
- }
- if(this.xv > 2)
- {
- this.entity._xscale = 100;
- }
- if(Math.abs(this.xv) < 1)
- {
- this.xv = 0;
- this.newanim = "idle";
- }
- if(Math.abs(this.xv) >= 1 && Math.abs(this.xv) <= 5 || Math.abs(this.yv) > 1)
- {
- this.newanim = "walk";
- }
- if(Math.abs(this.xv) > 5)
- {
- this.newanim = "run";
- }
- }
- if(this.HP < 0)
- {
- this.newanim = "die";
- }
- if(this.newanim != this.oldanim)
- {
- switch(this.newanim)
- {
- case "die":
- this.entity.anims.gotoAndStop("died");
- this.entity.anim = "died";
- break;
- case "idle":
- this.entity.anims.gotoAndStop("idle");
- this.entity.anim = "idle";
- break;
- case "walk":
- this.entity.anims.gotoAndStop("walk");
- this.entity.anim = "walk";
- this.i = 0;
- while(this.i < this.entity.animoffs)
- {
- this.entity.anims.nextFrame();
- this.entity.anims.nextFrame();
- this.i = this.i + 1;
- }
- break;
- case "run":
- this.entity.anims.gotoAndStop("run");
- this.entity.anim = "run";
- this.i = 0;
- while(this.i < this.entity.animoffs)
- {
- this.entity.anims.nextFrame();
- this.entity.anims.nextFrame();
- this.i = this.i + 1;
- }
- break;
- case "attack1":
- this.entity.anims.gotoAndStop("attack1");
- this.entity.anim = "attack1";
- this.xv = this.entity._xscale / 25;
- break;
- case "attack2":
- this.entity.anims.gotoAndStop("attack2");
- this.entity.anim = "attack2";
- this.xv = this.entity._xscale / 25;
- break;
- case "attack3":
- this.entity.anims.gotoAndStop("attack3");
- this.entity.anim = "attack3";
- this.xv = this.entity._xscale / 20;
- break;
- case "backattack":
- this.entity.anims.gotoAndStop("backattack");
- this.entity.anim = "backattack";
- this.xv = (- this.entity._xscale) / 20;
- break;
- case "airattack":
- this.entity.anims.gotoAndStop("airattack");
- this.entity.anim = "airattack";
- if(this.zv < 0)
- {
- this.zv += 8;
- }
- break;
- case "airattack2":
- this.entity.anims.gotoAndStop("airattack2");
- this.entity.anim = "airattack2";
- if(this.zv < 0)
- {
- this.zv += 8;
- }
- break;
- case "runattack":
- this.entity.anims.gotoAndStop("runattack");
- this.entity.anim = "runattack";
- this.xv = this.entity._xscale / 8;
- break;
- case "jump":
- this.entity.anims.gotoAndStop("jump");
- this.entity.anim = "jump";
- break;
- case "jumpattack":
- this.entity.anims.gotoAndStop("jumpattack");
- this.entity.anim = "jumpattack";
- break;
- case "hurt":
- this.entity.anims.gotoAndStop("hurt");
- this.entity.anim = "hurt";
- }
- }
- this.oldanim = this.newanim;
- }
- function hurt(amount)
- {
- this.newanim = "hurt";
- this.oldanim = "idle";
- this.HP -= amount * 2;
- this.entity.hurting = true;
- this.inputlocked = true;
- }
- function lift(amount)
- {
- this.zv += amount;
- this.grounded = false;
- }
- function remove()
- {
- this.entity.removeMovieClip();
- }
- }
-