home *** CD-ROM | disk | FTP | other *** search
- class PlatformPlayerSprite extends com.neodelight.v2D.RectSprite
- {
- var player;
- var vMax;
- var a;
- var t;
- var boundingRectFrom;
- var boundingRectTo;
- var keys;
- var ducked;
- var origin;
- var mc;
- var freeMovement;
- var guns;
- var gun;
- var throwPower;
- var pos;
- var v;
- var paralyzed;
- var shotReload;
- var lookDir;
- var dead;
- var actHitPoints;
- var defHitPoints;
- var maxHitPoints;
- var config;
- var size;
- var animMgr;
- var inactive;
- var ground;
- var showAnimWalking;
- var shotV = 5;
- var duckOffY = 60;
- var duckGunOffY = 0;
- function PlatformPlayerSprite(mc)
- {
- super(mc,undefined,undefined,com.neodelight.v2D.V2DObject.FlagCarryable,undefined);
- this.isPlayer = true;
- this.player = _global.game.player;
- _global.plSprite = this;
- this.player.sprite = this;
- this.vMax = new com.neodelight.std.Vector3D(8,0,0);
- this.a = new com.neodelight.std.Vector3D(2.8,27,0);
- this.t = new com.neodelight.std.Vector(0,0);
- this.boundingRectFrom = new com.neodelight.std.Vector(0,0);
- this.boundingRectTo = new com.neodelight.std.Vector(0,0);
- this.keys = new Object();
- this.ducked = false;
- com.neodelight.v2D.Sprite.gravity = 1;
- this.origin = new com.neodelight.std.Vector(this.mc._x,this.mc._y);
- this.freeMovement = true;
- this.guns[0].id = 0;
- this.guns[1].id = 1;
- this.guns[2].id = 2;
- this.guns[3].id = 3;
- this.guns[4].id = 4;
- this.gun = this.guns[0];
- this.throwPower = new com.neodelight.std.Vector3D(0,0,0);
- this.reset();
- }
- function reset()
- {
- super.reset();
- if(!this.player)
- {
- return undefined;
- }
- this.pos.x = this.origin.x;
- this.pos.y = this.origin.y;
- this.v.x = 0;
- this.v.y = 0;
- this.v.z = 0;
- this.paralyzed = 0;
- this.mc._x = this.pos.x;
- this.mc._y = this.pos.y;
- this.shotReload = 0;
- this.lookDir = 1;
- this.keys.jumpTokens = 1;
- this.keys.jumpMemory = 0;
- this.keys.airJumpTokens = 1;
- this.keys.weaponTokens = 1;
- this.keys.shootTokens = 1;
- this.keys.gunTokens0 = 1;
- this.keys.gunTokens1 = 1;
- this.keys.gunTokens2 = 1;
- this.keys.gunTokens3 = 1;
- this.keys.gunTokens4 = 1;
- this.unduck();
- this.dead = false;
- this.redraw();
- if(this.player.actHitPoints > 0)
- {
- this.actHitPoints = this.player.actHitPoints;
- }
- this.player.actHitPoints = this.actHitPoints;
- this.player.defHitPoints = this.defHitPoints;
- this.player.maxHitPoints = this.maxHitPoints;
- this.maxHitPoints = Math.min(this.maxHitPoints,this.config.statHitPoints - _root.difficulty);
- this.actHitPoints = Math.min(this.actHitPoints,this.config.statHitPoints - _root.difficulty);
- this.defHitPoints = Math.min(this.defHitPoints,this.config.statHitPoints - _root.difficulty);
- this.guns[0].actBullets = this.guns[0].maxBullets;
- var _loc4_ = 1;
- while(_loc4_ < this.guns.length)
- {
- this.guns[_loc4_].actBullets = com.neodelight.std.XMath.toNumber(this.player.actBullets[_loc4_]);
- _loc4_ = _loc4_ + 1;
- }
- this.gun = this.guns[int(this.player.actWeaponId)];
- this.player.actAbilities.doubleJump = true;
- this.redraw();
- _root.osd.update();
- }
- function store()
- {
- this.unduck();
- if(!this.dead)
- {
- var _loc2_ = 0;
- while(_loc2_ < this.guns.length)
- {
- this.player.actBullets[_loc2_] = this.guns[_loc2_].actBullets;
- _loc2_ = _loc2_ + 1;
- }
- }
- this.player.actWeaponId = this.gun.id;
- this.player.actHitPoints = this.actHitPoints;
- }
- function unduck()
- {
- if(this.ducked)
- {
- this.ducked = false;
- this.size.y += this.duckOffY;
- this.pos.y -= this.duckOffY;
- var _loc2_ = 0;
- while(_loc2_ < this.guns.length)
- {
- this.guns[_loc2_].offset.y = this.size.y * 0.5 + com.neodelight.std.XMath.toNumber(this.guns[_loc2_].config.gunOffsetY);
- _loc2_ = _loc2_ + 1;
- }
- }
- this.animMgr.prefix = "";
- }
- function redraw()
- {
- super.redraw();
- if(!this.inactive)
- {
- if(this.ducked)
- {
- this.mc.gfx.gotoAndStop("duck");
- if(Math.abs(this.v.x) > 0.01)
- {
- this.mc.gfx.gfx.play();
- }
- else
- {
- this.mc.gfx.gfx.stop();
- }
- }
- else if(this.ground)
- {
- if(this.showAnimWalking > 0)
- {
- this.mc.gfx.gotoAndStop("walk");
- }
- else
- {
- this.mc.gfx.gotoAndStop("stay");
- }
- }
- else if(this.v.y > 0)
- {
- this.mc.gfx.gotoAndStop("flyDown");
- }
- else
- {
- this.mc.gfx.gotoAndStop("flyUp");
- }
- }
- }
- function damage(amount)
- {
- var _loc4_ = super.damage(amount);
- this.player.actHitPoints = this.actHitPoints;
- _global.osd.update();
- return _loc4_;
- }
- function die()
- {
- super.die();
- var _loc4_ = 1;
- while(_loc4_ < this.guns.length)
- {
- this.player.actBullets[_loc4_] = 0;
- _loc4_ = _loc4_ + 1;
- }
- this.player.actAbilities.doubleJump = false;
- _root.osd.update();
- if(_root.actLifes == 0)
- {
- _root.startPhase(_root.stepGameOver);
- }
- else
- {
- _root.eventRestartLevel();
- }
- this.dead = true;
- }
- function dieMover()
- {
- return undefined;
- }
- function eventXtraAmmo(self, partner, args)
- {
- _root.snd.playEvent("pickup_powerup",1);
- if(args[0] != 4)
- {
- var _loc6_ = true;
- var _loc4_ = args[0];
- while(_loc4_ < 4)
- {
- if(this.guns[_loc4_].actBullets > 0)
- {
- _loc6_ = false;
- }
- _loc4_ = _loc4_ + 1;
- }
- if(_loc6_)
- {
- this.gun = this.guns[args[0]];
- }
- }
- this.guns[args[0]].actBullets = Math.min(this.guns[args[0]].maxBullets,this.guns[args[0]].actBullets + args[1]);
- _global.osd.update();
- }
- function eventXtraEnergy(self, partner, args)
- {
- _root.snd.playEvent("pickup_powerup",1);
- this.actHitPoints = Math.min(this.maxHitPoints,this.actHitPoints + args[0]);
- _global.osd.update();
- }
- function eventXtraDoubleJump(self, partner, args)
- {
- this.player.actAbilities.doubleJump = true;
- _global.osd.update();
- }
- function eventDuck()
- {
- if(!this.ducked)
- {
- this.animMgr.prefix = "ducked_";
- this.ducked = true;
- this.size.y -= this.duckOffY;
- this.pos.y += this.duckOffY;
- var _loc2_ = 0;
- while(_loc2_ < this.guns.length)
- {
- this.guns[_loc2_].offset.y += this.duckGunOffY;
- _loc2_ = _loc2_ + 1;
- }
- }
- }
- function move()
- {
- if(this.dead)
- {
- this.dieMover();
- return undefined;
- }
- com.neodelight.std.Inputs.update();
- if(this.gun.actBullets <= 0 && this.gun.id != 0)
- {
- var _loc5_ = this.gun.id;
- while(_loc5_ >= 0)
- {
- if(this.guns[_loc5_].actBullets > 0 || _loc5_ == 0)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.gun = this.guns[_loc5_];
- break;
- }
- _loc5_ = _loc5_ - 1;
- }
- }
- if(com.neodelight.std.Inputs.isPressed("gun0"))
- {
- if(this.keys.gunTokens0 == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.gun = this.guns[0];
- _root.osd.update();
- this.keys.gunTokens0 = 0;
- }
- }
- else
- {
- this.keys.gunTokens0 = 1;
- }
- if(com.neodelight.std.Inputs.isPressed("gun1") && this.guns[1].actBullets > 0)
- {
- if(this.keys.gunTokens1 == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.gun = this.guns[1];
- _root.osd.update();
- this.keys.gunTokens1 = 0;
- }
- }
- else
- {
- this.keys.gunTokens1 = 1;
- }
- if(com.neodelight.std.Inputs.isPressed("gun2") && this.guns[2].actBullets > 0)
- {
- if(this.keys.gunTokens2 == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.gun = this.guns[2];
- _root.osd.update();
- this.keys.gunTokens2 = 0;
- }
- }
- else
- {
- this.keys.gunTokens2 = 1;
- }
- if(com.neodelight.std.Inputs.isPressed("gun3") && this.guns[3].actBullets > 0)
- {
- if(this.keys.gunTokens3 == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.gun = this.guns[3];
- _root.osd.update();
- this.keys.gunTokens3 = 0;
- }
- }
- else
- {
- this.keys.gunTokens3 = 1;
- }
- if(com.neodelight.std.Inputs.isPressed("gun4") && this.guns[4].actBullets > 0)
- {
- if(this.keys.gunTokens4 == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.gun = this.guns[4];
- _root.osd.update();
- this.keys.gunTokens4 = 0;
- }
- }
- else
- {
- this.keys.gunTokens4 = 1;
- }
- if(com.neodelight.std.Inputs.isPressed("gunNext"))
- {
- if(this.keys.weaponTokens == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.keys.weaponTokens = 0;
- do
- {
- this.gun = this.guns[(Number(this.gun.id) + 6) % 5];
- }
- while(this.gun.actBullets <= 0 && this.gun.id != 0);
-
- _root.osd.update();
- }
- }
- else if(com.neodelight.std.Inputs.isPressed("gunPrev"))
- {
- if(this.keys.weaponTokens == 1)
- {
- _global.game.snd.playEvent("weapon_select",1);
- this.keys.weaponTokens = 0;
- do
- {
- this.gun = this.guns[(Number(this.gun.id) + 4) % 5];
- }
- while(this.gun.actBullets <= 0 && this.gun.id != 0);
-
- _root.osd.update();
- }
- }
- else
- {
- this.keys.weaponTokens = 1;
- }
- this.showAnimWalking = this.showAnimWalking - 1;
- if(com.neodelight.std.Inputs.isPressed("right") && this.paralyzed == 0)
- {
- this.v.x = Math.min(Math.max(0,this.v.x) + this.a.x,this.vMax.x);
- this.lookDir = 1;
- this.showAnimWalking = 1;
- }
- else if(com.neodelight.std.Inputs.isPressed("left") && this.paralyzed == 0)
- {
- this.v.x = Math.max(Math.min(0,this.v.x) - this.a.x,this.vMax.x * -1);
- this.lookDir = -1;
- this.showAnimWalking = 1;
- }
- else
- {
- this.v.x *= 0.4;
- if(Math.abs(this.v.x) < 1)
- {
- this.v.x = 0;
- }
- }
- if(com.neodelight.std.Inputs.isPressed("jump") && this.paralyzed == 0)
- {
- if(this.keys.jumpTokens > 0)
- {
- this.keys.jumpTokens = 0;
- this.keys.jumpTrigger = 3;
- }
- else
- {
- this.keys.jumpTrigger = Math.max(0,this.keys.jumpTrigger - 1);
- }
- }
- else
- {
- if(this.v.y < 0)
- {
- this.v.y *= 0.7;
- }
- this.keys.jumpTrigger = Math.max(0,this.keys.jumpTrigger - 1);
- this.keys.jumpTokens = 1;
- }
- if(com.neodelight.std.Inputs.isPressed("duck") && !this.keys.jumpTrigger && this.paralyzed == 0)
- {
- if(!this.ducked && this.ground)
- {
- this.animMgr.prefix = "ducked_";
- this.pos.y += this.duckOffY;
- this.size.y -= this.duckOffY;
- _loc5_ = 0;
- while(_loc5_ < this.guns.length)
- {
- this.guns[_loc5_].offset.y += this.duckGunOffY;
- _loc5_ = _loc5_ + 1;
- }
- this.ducked = true;
- }
- }
- else if(this.ducked)
- {
- var _loc6_ = this.tryPush(new com.neodelight.std.Vector3D(0,- this.duckOffY,0));
- if(_loc6_ == 1)
- {
- this.animMgr.prefix = "";
- this.ducked = false;
- this.size.y += this.duckOffY;
- _loc5_ = 0;
- while(_loc5_ < this.guns.length)
- {
- this.guns[_loc5_].offset.y -= this.duckGunOffY;
- _loc5_ = _loc5_ + 1;
- }
- }
- else if(_loc6_ > 0)
- {
- this.tryPush(new com.neodelight.std.Vector3D(0,this.duckOffY * _loc6_));
- }
- }
- if(this.ducked && this.ground)
- {
- this.v.x = Math.max(-3,Math.min(3,this.v.x));
- }
- if((this.ground || this.player.actAbilities.doubleJump && this.keys.airJumpTokens > 0 && this.v.y <= 10) && this.keys.jumpTrigger)
- {
- if(!this.ground)
- {
- this.keys.airJumpTokens = 0;
- }
- else
- {
- this.keys.airJumpTokens = 1;
- }
- this.v.y = 0;
- this.v.y += -1 * this.a.y;
- this.keys.jumpTrigger = 0;
- }
- super.move();
- if(com.neodelight.std.Inputs.isPressed("shoot") && this.paralyzed == 0)
- {
- if(this.gun.shoot())
- {
- _root.osd.update();
- }
- }
- if(this.guns[0].actBullets < this.guns[0].maxBullets)
- {
- this.guns[0].actBullets = Math.min(this.guns[0].maxBullets,this.guns[0].actBullets + 0.085);
- _root.osd.update();
- }
- }
- }
-