home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / midnightstrike1.swf / scripts / __Packages / PlatformPlayerSprite.as
Encoding:
Text File  |  2007-04-02  |  14.1 KB  |  501 lines

  1. class PlatformPlayerSprite extends com.neodelight.v2D.RectSprite
  2. {
  3.    var player;
  4.    var vMax;
  5.    var a;
  6.    var t;
  7.    var boundingRectFrom;
  8.    var boundingRectTo;
  9.    var keys;
  10.    var ducked;
  11.    var origin;
  12.    var mc;
  13.    var freeMovement;
  14.    var guns;
  15.    var gun;
  16.    var throwPower;
  17.    var pos;
  18.    var v;
  19.    var paralyzed;
  20.    var shotReload;
  21.    var lookDir;
  22.    var dead;
  23.    var actHitPoints;
  24.    var defHitPoints;
  25.    var maxHitPoints;
  26.    var config;
  27.    var size;
  28.    var animMgr;
  29.    var inactive;
  30.    var ground;
  31.    var showAnimWalking;
  32.    var shotV = 5;
  33.    var duckOffY = 60;
  34.    var duckGunOffY = 0;
  35.    function PlatformPlayerSprite(mc)
  36.    {
  37.       super(mc,undefined,undefined,com.neodelight.v2D.V2DObject.FlagCarryable,undefined);
  38.       this.isPlayer = true;
  39.       this.player = _global.game.player;
  40.       _global.plSprite = this;
  41.       this.player.sprite = this;
  42.       this.vMax = new com.neodelight.std.Vector3D(8,0,0);
  43.       this.a = new com.neodelight.std.Vector3D(2.8,27,0);
  44.       this.t = new com.neodelight.std.Vector(0,0);
  45.       this.boundingRectFrom = new com.neodelight.std.Vector(0,0);
  46.       this.boundingRectTo = new com.neodelight.std.Vector(0,0);
  47.       this.keys = new Object();
  48.       this.ducked = false;
  49.       com.neodelight.v2D.Sprite.gravity = 1;
  50.       this.origin = new com.neodelight.std.Vector(this.mc._x,this.mc._y);
  51.       this.freeMovement = true;
  52.       this.guns[0].id = 0;
  53.       this.guns[1].id = 1;
  54.       this.guns[2].id = 2;
  55.       this.guns[3].id = 3;
  56.       this.guns[4].id = 4;
  57.       this.gun = this.guns[0];
  58.       this.throwPower = new com.neodelight.std.Vector3D(0,0,0);
  59.       this.reset();
  60.    }
  61.    function reset()
  62.    {
  63.       super.reset();
  64.       if(!this.player)
  65.       {
  66.          return undefined;
  67.       }
  68.       this.pos.x = this.origin.x;
  69.       this.pos.y = this.origin.y;
  70.       this.v.x = 0;
  71.       this.v.y = 0;
  72.       this.v.z = 0;
  73.       this.paralyzed = 0;
  74.       this.mc._x = this.pos.x;
  75.       this.mc._y = this.pos.y;
  76.       this.shotReload = 0;
  77.       this.lookDir = 1;
  78.       this.keys.jumpTokens = 1;
  79.       this.keys.jumpMemory = 0;
  80.       this.keys.airJumpTokens = 1;
  81.       this.keys.weaponTokens = 1;
  82.       this.keys.shootTokens = 1;
  83.       this.keys.gunTokens0 = 1;
  84.       this.keys.gunTokens1 = 1;
  85.       this.keys.gunTokens2 = 1;
  86.       this.keys.gunTokens3 = 1;
  87.       this.keys.gunTokens4 = 1;
  88.       this.unduck();
  89.       this.dead = false;
  90.       this.redraw();
  91.       if(this.player.actHitPoints > 0)
  92.       {
  93.          this.actHitPoints = this.player.actHitPoints;
  94.       }
  95.       this.player.actHitPoints = this.actHitPoints;
  96.       this.player.defHitPoints = this.defHitPoints;
  97.       this.player.maxHitPoints = this.maxHitPoints;
  98.       this.maxHitPoints = Math.min(this.maxHitPoints,this.config.statHitPoints - _root.difficulty);
  99.       this.actHitPoints = Math.min(this.actHitPoints,this.config.statHitPoints - _root.difficulty);
  100.       this.defHitPoints = Math.min(this.defHitPoints,this.config.statHitPoints - _root.difficulty);
  101.       this.guns[0].actBullets = this.guns[0].maxBullets;
  102.       var _loc4_ = 1;
  103.       while(_loc4_ < this.guns.length)
  104.       {
  105.          this.guns[_loc4_].actBullets = com.neodelight.std.XMath.toNumber(this.player.actBullets[_loc4_]);
  106.          _loc4_ = _loc4_ + 1;
  107.       }
  108.       this.gun = this.guns[int(this.player.actWeaponId)];
  109.       this.player.actAbilities.doubleJump = true;
  110.       this.redraw();
  111.       _root.osd.update();
  112.    }
  113.    function store()
  114.    {
  115.       this.unduck();
  116.       if(!this.dead)
  117.       {
  118.          var _loc2_ = 0;
  119.          while(_loc2_ < this.guns.length)
  120.          {
  121.             this.player.actBullets[_loc2_] = this.guns[_loc2_].actBullets;
  122.             _loc2_ = _loc2_ + 1;
  123.          }
  124.       }
  125.       this.player.actWeaponId = this.gun.id;
  126.       this.player.actHitPoints = this.actHitPoints;
  127.    }
  128.    function unduck()
  129.    {
  130.       if(this.ducked)
  131.       {
  132.          this.ducked = false;
  133.          this.size.y += this.duckOffY;
  134.          this.pos.y -= this.duckOffY;
  135.          var _loc2_ = 0;
  136.          while(_loc2_ < this.guns.length)
  137.          {
  138.             this.guns[_loc2_].offset.y = this.size.y * 0.5 + com.neodelight.std.XMath.toNumber(this.guns[_loc2_].config.gunOffsetY);
  139.             _loc2_ = _loc2_ + 1;
  140.          }
  141.       }
  142.       this.animMgr.prefix = "";
  143.    }
  144.    function redraw()
  145.    {
  146.       super.redraw();
  147.       if(!this.inactive)
  148.       {
  149.          if(this.ducked)
  150.          {
  151.             this.mc.gfx.gotoAndStop("duck");
  152.             if(Math.abs(this.v.x) > 0.01)
  153.             {
  154.                this.mc.gfx.gfx.play();
  155.             }
  156.             else
  157.             {
  158.                this.mc.gfx.gfx.stop();
  159.             }
  160.          }
  161.          else if(this.ground)
  162.          {
  163.             if(this.showAnimWalking > 0)
  164.             {
  165.                this.mc.gfx.gotoAndStop("walk");
  166.             }
  167.             else
  168.             {
  169.                this.mc.gfx.gotoAndStop("stay");
  170.             }
  171.          }
  172.          else if(this.v.y > 0)
  173.          {
  174.             this.mc.gfx.gotoAndStop("flyDown");
  175.          }
  176.          else
  177.          {
  178.             this.mc.gfx.gotoAndStop("flyUp");
  179.          }
  180.       }
  181.    }
  182.    function damage(amount)
  183.    {
  184.       var _loc4_ = super.damage(amount);
  185.       this.player.actHitPoints = this.actHitPoints;
  186.       _global.osd.update();
  187.       return _loc4_;
  188.    }
  189.    function die()
  190.    {
  191.       super.die();
  192.       var _loc4_ = 1;
  193.       while(_loc4_ < this.guns.length)
  194.       {
  195.          this.player.actBullets[_loc4_] = 0;
  196.          _loc4_ = _loc4_ + 1;
  197.       }
  198.       this.player.actAbilities.doubleJump = false;
  199.       _root.osd.update();
  200.       if(_root.actLifes == 0)
  201.       {
  202.          _root.startPhase(_root.stepGameOver);
  203.       }
  204.       else
  205.       {
  206.          _root.eventRestartLevel();
  207.       }
  208.       this.dead = true;
  209.    }
  210.    function dieMover()
  211.    {
  212.       return undefined;
  213.    }
  214.    function eventXtraAmmo(self, partner, args)
  215.    {
  216.       _root.snd.playEvent("pickup_powerup",1);
  217.       if(args[0] != 4)
  218.       {
  219.          var _loc6_ = true;
  220.          var _loc4_ = args[0];
  221.          while(_loc4_ < 4)
  222.          {
  223.             if(this.guns[_loc4_].actBullets > 0)
  224.             {
  225.                _loc6_ = false;
  226.             }
  227.             _loc4_ = _loc4_ + 1;
  228.          }
  229.          if(_loc6_)
  230.          {
  231.             this.gun = this.guns[args[0]];
  232.          }
  233.       }
  234.       this.guns[args[0]].actBullets = Math.min(this.guns[args[0]].maxBullets,this.guns[args[0]].actBullets + args[1]);
  235.       _global.osd.update();
  236.    }
  237.    function eventXtraEnergy(self, partner, args)
  238.    {
  239.       _root.snd.playEvent("pickup_powerup",1);
  240.       this.actHitPoints = Math.min(this.maxHitPoints,this.actHitPoints + args[0]);
  241.       _global.osd.update();
  242.    }
  243.    function eventXtraDoubleJump(self, partner, args)
  244.    {
  245.       this.player.actAbilities.doubleJump = true;
  246.       _global.osd.update();
  247.    }
  248.    function eventDuck()
  249.    {
  250.       if(!this.ducked)
  251.       {
  252.          this.animMgr.prefix = "ducked_";
  253.          this.ducked = true;
  254.          this.size.y -= this.duckOffY;
  255.          this.pos.y += this.duckOffY;
  256.          var _loc2_ = 0;
  257.          while(_loc2_ < this.guns.length)
  258.          {
  259.             this.guns[_loc2_].offset.y += this.duckGunOffY;
  260.             _loc2_ = _loc2_ + 1;
  261.          }
  262.       }
  263.    }
  264.    function move()
  265.    {
  266.       if(this.dead)
  267.       {
  268.          this.dieMover();
  269.          return undefined;
  270.       }
  271.       com.neodelight.std.Inputs.update();
  272.       if(this.gun.actBullets <= 0 && this.gun.id != 0)
  273.       {
  274.          var _loc5_ = this.gun.id;
  275.          while(_loc5_ >= 0)
  276.          {
  277.             if(this.guns[_loc5_].actBullets > 0 || _loc5_ == 0)
  278.             {
  279.                _global.game.snd.playEvent("weapon_select",1);
  280.                this.gun = this.guns[_loc5_];
  281.                break;
  282.             }
  283.             _loc5_ = _loc5_ - 1;
  284.          }
  285.       }
  286.       if(com.neodelight.std.Inputs.isPressed("gun0"))
  287.       {
  288.          if(this.keys.gunTokens0 == 1)
  289.          {
  290.             _global.game.snd.playEvent("weapon_select",1);
  291.             this.gun = this.guns[0];
  292.             _root.osd.update();
  293.             this.keys.gunTokens0 = 0;
  294.          }
  295.       }
  296.       else
  297.       {
  298.          this.keys.gunTokens0 = 1;
  299.       }
  300.       if(com.neodelight.std.Inputs.isPressed("gun1") && this.guns[1].actBullets > 0)
  301.       {
  302.          if(this.keys.gunTokens1 == 1)
  303.          {
  304.             _global.game.snd.playEvent("weapon_select",1);
  305.             this.gun = this.guns[1];
  306.             _root.osd.update();
  307.             this.keys.gunTokens1 = 0;
  308.          }
  309.       }
  310.       else
  311.       {
  312.          this.keys.gunTokens1 = 1;
  313.       }
  314.       if(com.neodelight.std.Inputs.isPressed("gun2") && this.guns[2].actBullets > 0)
  315.       {
  316.          if(this.keys.gunTokens2 == 1)
  317.          {
  318.             _global.game.snd.playEvent("weapon_select",1);
  319.             this.gun = this.guns[2];
  320.             _root.osd.update();
  321.             this.keys.gunTokens2 = 0;
  322.          }
  323.       }
  324.       else
  325.       {
  326.          this.keys.gunTokens2 = 1;
  327.       }
  328.       if(com.neodelight.std.Inputs.isPressed("gun3") && this.guns[3].actBullets > 0)
  329.       {
  330.          if(this.keys.gunTokens3 == 1)
  331.          {
  332.             _global.game.snd.playEvent("weapon_select",1);
  333.             this.gun = this.guns[3];
  334.             _root.osd.update();
  335.             this.keys.gunTokens3 = 0;
  336.          }
  337.       }
  338.       else
  339.       {
  340.          this.keys.gunTokens3 = 1;
  341.       }
  342.       if(com.neodelight.std.Inputs.isPressed("gun4") && this.guns[4].actBullets > 0)
  343.       {
  344.          if(this.keys.gunTokens4 == 1)
  345.          {
  346.             _global.game.snd.playEvent("weapon_select",1);
  347.             this.gun = this.guns[4];
  348.             _root.osd.update();
  349.             this.keys.gunTokens4 = 0;
  350.          }
  351.       }
  352.       else
  353.       {
  354.          this.keys.gunTokens4 = 1;
  355.       }
  356.       if(com.neodelight.std.Inputs.isPressed("gunNext"))
  357.       {
  358.          if(this.keys.weaponTokens == 1)
  359.          {
  360.             _global.game.snd.playEvent("weapon_select",1);
  361.             this.keys.weaponTokens = 0;
  362.             do
  363.             {
  364.                this.gun = this.guns[(Number(this.gun.id) + 6) % 5];
  365.             }
  366.             while(this.gun.actBullets <= 0 && this.gun.id != 0);
  367.             
  368.             _root.osd.update();
  369.          }
  370.       }
  371.       else if(com.neodelight.std.Inputs.isPressed("gunPrev"))
  372.       {
  373.          if(this.keys.weaponTokens == 1)
  374.          {
  375.             _global.game.snd.playEvent("weapon_select",1);
  376.             this.keys.weaponTokens = 0;
  377.             do
  378.             {
  379.                this.gun = this.guns[(Number(this.gun.id) + 4) % 5];
  380.             }
  381.             while(this.gun.actBullets <= 0 && this.gun.id != 0);
  382.             
  383.             _root.osd.update();
  384.          }
  385.       }
  386.       else
  387.       {
  388.          this.keys.weaponTokens = 1;
  389.       }
  390.       this.showAnimWalking = this.showAnimWalking - 1;
  391.       if(com.neodelight.std.Inputs.isPressed("right") && this.paralyzed == 0)
  392.       {
  393.          this.v.x = Math.min(Math.max(0,this.v.x) + this.a.x,this.vMax.x);
  394.          this.lookDir = 1;
  395.          this.showAnimWalking = 1;
  396.       }
  397.       else if(com.neodelight.std.Inputs.isPressed("left") && this.paralyzed == 0)
  398.       {
  399.          this.v.x = Math.max(Math.min(0,this.v.x) - this.a.x,this.vMax.x * -1);
  400.          this.lookDir = -1;
  401.          this.showAnimWalking = 1;
  402.       }
  403.       else
  404.       {
  405.          this.v.x *= 0.4;
  406.          if(Math.abs(this.v.x) < 1)
  407.          {
  408.             this.v.x = 0;
  409.          }
  410.       }
  411.       if(com.neodelight.std.Inputs.isPressed("jump") && this.paralyzed == 0)
  412.       {
  413.          if(this.keys.jumpTokens > 0)
  414.          {
  415.             this.keys.jumpTokens = 0;
  416.             this.keys.jumpTrigger = 3;
  417.          }
  418.          else
  419.          {
  420.             this.keys.jumpTrigger = Math.max(0,this.keys.jumpTrigger - 1);
  421.          }
  422.       }
  423.       else
  424.       {
  425.          if(this.v.y < 0)
  426.          {
  427.             this.v.y *= 0.7;
  428.          }
  429.          this.keys.jumpTrigger = Math.max(0,this.keys.jumpTrigger - 1);
  430.          this.keys.jumpTokens = 1;
  431.       }
  432.       if(com.neodelight.std.Inputs.isPressed("duck") && !this.keys.jumpTrigger && this.paralyzed == 0)
  433.       {
  434.          if(!this.ducked && this.ground)
  435.          {
  436.             this.animMgr.prefix = "ducked_";
  437.             this.pos.y += this.duckOffY;
  438.             this.size.y -= this.duckOffY;
  439.             _loc5_ = 0;
  440.             while(_loc5_ < this.guns.length)
  441.             {
  442.                this.guns[_loc5_].offset.y += this.duckGunOffY;
  443.                _loc5_ = _loc5_ + 1;
  444.             }
  445.             this.ducked = true;
  446.          }
  447.       }
  448.       else if(this.ducked)
  449.       {
  450.          var _loc6_ = this.tryPush(new com.neodelight.std.Vector3D(0,- this.duckOffY,0));
  451.          if(_loc6_ == 1)
  452.          {
  453.             this.animMgr.prefix = "";
  454.             this.ducked = false;
  455.             this.size.y += this.duckOffY;
  456.             _loc5_ = 0;
  457.             while(_loc5_ < this.guns.length)
  458.             {
  459.                this.guns[_loc5_].offset.y -= this.duckGunOffY;
  460.                _loc5_ = _loc5_ + 1;
  461.             }
  462.          }
  463.          else if(_loc6_ > 0)
  464.          {
  465.             this.tryPush(new com.neodelight.std.Vector3D(0,this.duckOffY * _loc6_));
  466.          }
  467.       }
  468.       if(this.ducked && this.ground)
  469.       {
  470.          this.v.x = Math.max(-3,Math.min(3,this.v.x));
  471.       }
  472.       if((this.ground || this.player.actAbilities.doubleJump && this.keys.airJumpTokens > 0 && this.v.y <= 10) && this.keys.jumpTrigger)
  473.       {
  474.          if(!this.ground)
  475.          {
  476.             this.keys.airJumpTokens = 0;
  477.          }
  478.          else
  479.          {
  480.             this.keys.airJumpTokens = 1;
  481.          }
  482.          this.v.y = 0;
  483.          this.v.y += -1 * this.a.y;
  484.          this.keys.jumpTrigger = 0;
  485.       }
  486.       super.move();
  487.       if(com.neodelight.std.Inputs.isPressed("shoot") && this.paralyzed == 0)
  488.       {
  489.          if(this.gun.shoot())
  490.          {
  491.             _root.osd.update();
  492.          }
  493.       }
  494.       if(this.guns[0].actBullets < this.guns[0].maxBullets)
  495.       {
  496.          this.guns[0].actBullets = Math.min(this.guns[0].maxBullets,this.guns[0].actBullets + 0.085);
  497.          _root.osd.update();
  498.       }
  499.    }
  500. }
  501.