home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / rocket_rush.swf / scripts / __Packages / Player.as < prev    next >
Encoding:
Text File  |  2007-03-20  |  11.4 KB  |  474 lines

  1. class Player extends Position
  2. {
  3.    var color;
  4.    var current_target;
  5.    var bubble;
  6.    static var crosshair;
  7.    var left = false;
  8.    var right = false;
  9.    var up = false;
  10.    var down = false;
  11.    var space = false;
  12.    var ex = false;
  13.    var zed = false;
  14.    var space_down = false;
  15.    var target_count = 0;
  16.    var tutorial = false;
  17.    var speed_x = 0;
  18.    var speed_y = 0;
  19.    var speed_z = 10;
  20.    static var air_resistance_factor = 0.12;
  21.    static var acceleration = 2.5;
  22.    static var missiles_left = 5;
  23.    var health = 100;
  24.    var whited_out = false;
  25.    var white = {ra:100,rb:255,ga:100,gb:255,ba:100,bb:255,aa:100,ab:255};
  26.    var normal = {ra:100,rb:0,ga:100,gb:0,ba:100,bb:0,aa:100,ab:0};
  27.    var dead_y = 0;
  28.    function Player()
  29.    {
  30.       super();
  31.       Position.camera_x = 0;
  32.       Position.camera_y = 0;
  33.       Position.camera_z = 0;
  34.       _global.game_paused = false;
  35.       this.color = new Color(this);
  36.       Player.crosshair = this._parent.attachMovie("crosshair","crosshair",this._parent.getNextHighestDepth());
  37.       this._x = Position.center_x;
  38.       this._y = Position.center_y + Position.center_y_offset;
  39.    }
  40.    function usePlayer()
  41.    {
  42.       if(this.health > 0)
  43.       {
  44.          this.useControls();
  45.       }
  46.       else
  47.       {
  48.          this.dying();
  49.       }
  50.       this.drawToScreen();
  51.       this.cameraFollow(this);
  52.       if(this.health <= 0)
  53.       {
  54.          Position.camera_y = this.dead_y;
  55.       }
  56.       var _loc5_ = false;
  57.       var _loc4_ = 0;
  58.       while(_loc4_ < this._parent.enemies.length)
  59.       {
  60.          if(this._parent.enemies[_loc4_].hitTest(Player.crosshair.fill))
  61.          {
  62.             _loc5_ = true;
  63.             this.current_target = this._parent.enemies[_loc4_];
  64.             if(this._parent.enemies[_loc4_].attack_clip.tonsil.hitTest(Player.crosshair.fill))
  65.             {
  66.                this.current_target = this._parent.enemies[_loc4_].tonsil_target;
  67.             }
  68.          }
  69.          _loc4_ = _loc4_ + 1;
  70.       }
  71.       if(this.zed)
  72.       {
  73.          if(_loc5_)
  74.          {
  75.             this.target_count = this.target_count + 1;
  76.             Player.crosshair.gotoAndStop(2);
  77.          }
  78.          else
  79.          {
  80.             this.target_count = 0;
  81.             Player.crosshair.gotoAndStop(1);
  82.          }
  83.       }
  84.       else if(_loc5_ && this.target_count > 5)
  85.       {
  86.          this.fireMissile(this.current_target);
  87.          this.target_count = 0;
  88.          Player.crosshair.gotoAndStop(1);
  89.       }
  90.       else
  91.       {
  92.          this.target_count = 0;
  93.          Player.crosshair.gotoAndStop(1);
  94.       }
  95.       this.moveCrosshair();
  96.       this.fireCannon();
  97.       if(this.whited_out)
  98.       {
  99.          this.whited_out = null;
  100.       }
  101.       else if(this.whited_out == null)
  102.       {
  103.          this.unWhite();
  104.       }
  105.       if(this.space)
  106.       {
  107.          if(!this.space_down)
  108.          {
  109.             _global.game_paused = true;
  110.             _root.hud.play();
  111.          }
  112.       }
  113.       else
  114.       {
  115.          this.space_down = false;
  116.       }
  117.       if(this.render_z > 500)
  118.       {
  119.          _root.play();
  120.       }
  121.    }
  122.    function checkInput()
  123.    {
  124.       if(!this.tutorial)
  125.       {
  126.          if(_global.control_type == 1)
  127.          {
  128.             this.left = Key.isDown(37);
  129.             this.right = Key.isDown(39);
  130.             if(_global.updown == "reverse")
  131.             {
  132.                this.up = Key.isDown(38);
  133.                this.down = Key.isDown(40);
  134.             }
  135.             else
  136.             {
  137.                this.up = Key.isDown(40);
  138.                this.down = Key.isDown(38);
  139.             }
  140.             this.ex = Key.isDown(88);
  141.             this.zed = Key.isDown(90);
  142.          }
  143.          else if(_global.control_type == 2)
  144.          {
  145.             this.left = Key.isDown(65);
  146.             this.right = Key.isDown(68);
  147.             if(_global.updown == "reverse")
  148.             {
  149.                this.up = Key.isDown(87);
  150.                this.down = Key.isDown(83);
  151.             }
  152.             else
  153.             {
  154.                this.up = Key.isDown(83);
  155.                this.down = Key.isDown(87);
  156.             }
  157.             this.ex = Key.isDown(78);
  158.             this.zed = Key.isDown(77);
  159.          }
  160.          this.space = Key.isDown(32);
  161.       }
  162.       else
  163.       {
  164.          this.speed_z = 0;
  165.       }
  166.    }
  167.    function useControls()
  168.    {
  169.       this.checkInput();
  170.       if(this.left)
  171.       {
  172.          this.accelerateX(- Player.acceleration);
  173.       }
  174.       else if(this.right)
  175.       {
  176.          this.accelerateX(Player.acceleration);
  177.       }
  178.       else
  179.       {
  180.          this.accelerateX(this.speed_x * (Player.air_resistance_factor * 0.6));
  181.       }
  182.       if(this.up)
  183.       {
  184.          this.accelerateY(Player.acceleration);
  185.       }
  186.       else if(this.down)
  187.       {
  188.          this.accelerateY(- Player.acceleration);
  189.       }
  190.       else
  191.       {
  192.          this.accelerateY(this.speed_y * (Player.air_resistance_factor * 0.6));
  193.       }
  194.       if(this.left)
  195.       {
  196.          if(this._rotation - 8 > -50)
  197.          {
  198.             this._rotation -= 8;
  199.          }
  200.          else
  201.          {
  202.             this._rotation = -50;
  203.          }
  204.       }
  205.       else if(this.right)
  206.       {
  207.          if(this._rotation + 8 < 50)
  208.          {
  209.             this._rotation += 8;
  210.          }
  211.          else
  212.          {
  213.             this._rotation = 50;
  214.          }
  215.       }
  216.       else
  217.       {
  218.          this._rotation -= this._rotation / 6;
  219.       }
  220.       if(this.up)
  221.       {
  222.          if(this._currentframe > 1)
  223.          {
  224.             this.gotoAndStop(this._currentframe - 1);
  225.          }
  226.       }
  227.       else if(this.down)
  228.       {
  229.          if(this._currentframe < 20)
  230.          {
  231.             this.gotoAndStop(this._currentframe + 1);
  232.          }
  233.       }
  234.       else
  235.       {
  236.          if(this._currentframe > 10)
  237.          {
  238.             this.gotoAndStop(this._currentframe - 1);
  239.          }
  240.          else if(this._currentframe < 10)
  241.          {
  242.             this.gotoAndStop(this._currentframe + 1);
  243.          }
  244.          this.bubble.blue.gotoAndStop(2);
  245.       }
  246.       if(this.left)
  247.       {
  248.          this.bubble.blue.gotoAndStop(3);
  249.       }
  250.       else if(this.right)
  251.       {
  252.          this.bubble.blue.gotoAndStop(4);
  253.       }
  254.       else if(this.up)
  255.       {
  256.          this.bubble.blue.gotoAndStop(6);
  257.       }
  258.       else if(this.down)
  259.       {
  260.          this.bubble.blue.gotoAndStop(5);
  261.       }
  262.       else
  263.       {
  264.          this.bubble.blue.gotoAndStop(2);
  265.       }
  266.       this.bubble.gotoAndStop(this._currentframe);
  267.       this.moveX();
  268.       this.moveY();
  269.       this.moveZ();
  270.    }
  271.    function moveCrosshair()
  272.    {
  273.       Player.crosshair._x = this._x + this._rotation;
  274.       Player.crosshair._y = this._y - 70 - 3 * (this._currentframe - 10);
  275.       Player.crosshair.swapDepths(this.getDepth() - 1);
  276.       var _loc3_ = Player.crosshair._x - this._x;
  277.       var _loc2_ = this._y - Player.crosshair._y;
  278.       Player.crosshair.gunfire._rotation = 180 * Math.atan2(_loc3_,_loc2_) / 3.141592653589793;
  279.       Player.crosshair.gunfire._yscale = _loc2_;
  280.    }
  281.    function fireCannon()
  282.    {
  283.       if(this.ex)
  284.       {
  285.          Player.crosshair.gunfire.gotoAndPlay(2);
  286.          for(var _loc2_ in this._parent.enemies)
  287.          {
  288.             if(this._parent.enemies[_loc2_].hitTest(Player.crosshair.fill))
  289.             {
  290.                this._parent.enemies[_loc2_].getShot(Player.crosshair.fill);
  291.             }
  292.             else
  293.             {
  294.                this._parent.enemies[_loc2_].unWhite();
  295.             }
  296.          }
  297.       }
  298.       else if(Player.crosshair.gunfire._currentframe != 1)
  299.       {
  300.          for(_loc2_ in this._parent.enemies)
  301.          {
  302.             this._parent.enemies[_loc2_].unWhite();
  303.          }
  304.          Player.crosshair.gunfire.gotoAndStop(1);
  305.       }
  306.    }
  307.    function fireMissile(p_target)
  308.    {
  309.       if(Player.missiles_left > 0)
  310.       {
  311.          Player.missiles_left--;
  312.          var _loc2_ = this._parent.attachMovie("player_missile","missile" + this._parent.objects.length,-1000 + this._parent.objects.length);
  313.          _loc2_.launch(this,p_target,70,this.speed_z + 10);
  314.          this._parent.addObject(_loc2_);
  315.       }
  316.    }
  317.    function getShot()
  318.    {
  319.       this.whiteOut();
  320.       this.reduceHealth(1);
  321.    }
  322.    function getMissiled()
  323.    {
  324.       this._parent.badComment();
  325.       this.whiteOut();
  326.       this.reduceHealth(4);
  327.    }
  328.    function getEnergyBalled()
  329.    {
  330.       this._parent.badComment();
  331.       this.whiteOut();
  332.       this.reduceHealth(3);
  333.    }
  334.    function getObstacled()
  335.    {
  336.       this._parent.badComment();
  337.       this.whiteOut();
  338.       this.reduceHealth(1);
  339.    }
  340.    function getBitten()
  341.    {
  342.       this._parent.badComment();
  343.       this.whiteOut();
  344.       this.reduceHealth(10);
  345.    }
  346.    function getBarreled()
  347.    {
  348.       this._parent.badComment();
  349.       this.whiteOut();
  350.       this.reduceHealth(1);
  351.    }
  352.    function getRocked()
  353.    {
  354.       this._parent.badComment();
  355.       this.whiteOut();
  356.       this.reduceHealth(1);
  357.    }
  358.    function getLasered()
  359.    {
  360.       this._parent.badComment();
  361.       this.whiteOut();
  362.       this.reduceHealth(8);
  363.    }
  364.    function whiteOut()
  365.    {
  366.       if(!this.whited_out)
  367.       {
  368.          this.color.setTransform(this.white);
  369.          this.whited_out = true;
  370.       }
  371.    }
  372.    function increaseHealth(p_ammount)
  373.    {
  374.       this.health += p_ammount;
  375.       if(this.health > 100)
  376.       {
  377.          this.health = 100;
  378.       }
  379.       this.updateHealthBar();
  380.    }
  381.    function increaseAmmo()
  382.    {
  383.       Player.missiles_left += 5;
  384.       if(Player.missiles_left > 99)
  385.       {
  386.          Player.missiles_left = 99;
  387.       }
  388.    }
  389.    function reduceHealth(p_ammount)
  390.    {
  391.       this.health -= p_ammount;
  392.       if(this.health <= 0)
  393.       {
  394.          this.die();
  395.       }
  396.       this.updateHealthBar();
  397.    }
  398.    function updateHealthBar()
  399.    {
  400.       var _loc3_ = 101 - Math.ceil(this.health);
  401.       _root.hud.elements.health_bar.gotoAndStop(_loc3_);
  402.    }
  403.    function unWhite()
  404.    {
  405.       this.color.setTransform(this.normal);
  406.       this.whited_out = false;
  407.    }
  408.    function die()
  409.    {
  410.       this.bubble.gotoAndStop(10);
  411.       this.bubble.blue.gotoAndStop(2);
  412.       this.gotoAndStop(21);
  413.       this._rotation = 0;
  414.       this.speed_x = 0;
  415.       this.speed_y = 5;
  416.       this.dead_y = this.pos_y;
  417.       this.die = function()
  418.       {
  419.       };
  420.    }
  421.    function dying()
  422.    {
  423.       this.moveY();
  424.       this.moveZ();
  425.       if(this._y > 500)
  426.       {
  427.          _root.fadeo.gotoAndPlay(1);
  428.          _root.gotoAndPlay(_root._currentframe - 1);
  429.       }
  430.    }
  431.    function moveX()
  432.    {
  433.       this.pos_x += this.speed_x;
  434.       if(this.pos_x > 10000)
  435.       {
  436.          this._parent.shiftToX(-10000);
  437.       }
  438.       else if(this.pos_x < -10000)
  439.       {
  440.          this._parent.shiftToX(-10000);
  441.       }
  442.    }
  443.    function moveY()
  444.    {
  445.       this.pos_y += this.speed_y;
  446.       if(this.pos_y > 10000)
  447.       {
  448.          this._parent.shiftToY(-10000);
  449.       }
  450.       else if(this.pos_y < -10000)
  451.       {
  452.          this._parent.shiftToY(10000);
  453.       }
  454.    }
  455.    function moveZ()
  456.    {
  457.       this.pos_z += this.speed_z;
  458.    }
  459.    function accelerateX(p_a)
  460.    {
  461.       this.speed_x += p_a;
  462.       this.speed_x -= this.speed_x * Player.air_resistance_factor;
  463.    }
  464.    function accelerateY(p_a)
  465.    {
  466.       this.speed_y += p_a;
  467.       this.speed_y -= this.speed_y * Player.air_resistance_factor;
  468.    }
  469.    function accelerateZ(p_a)
  470.    {
  471.       this.speed_z += p_a;
  472.    }
  473. }
  474.