home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Survival.swf / scripts / Player.as < prev    next >
Encoding:
Text File  |  2008-09-04  |  2.3 KB  |  116 lines

  1. package
  2. {
  3.    import flash.display.*;
  4.    import flash.events.*;
  5.    
  6.    [Embed(source="/_assets/assets.swf", symbol="Player")]
  7.    public class Player extends Actor
  8.    {
  9.        
  10.       
  11.       internal var shot:Boolean;
  12.       
  13.       internal var speed:int;
  14.       
  15.       internal var health:int;
  16.       
  17.       internal var gun:Gun;
  18.       
  19.       public function Player()
  20.       {
  21.          super();
  22.          init();
  23.       }
  24.       
  25.       internal function init() : void
  26.       {
  27.          addEventListener(Event.ENTER_FRAME,update);
  28.          speed = 7;
  29.          gun = new Gun(3,25);
  30.          health = 5;
  31.          shot = false;
  32.       }
  33.       
  34.       internal function die() : void
  35.       {
  36.          visible = false;
  37.          (parent as MovieClip).restart();
  38.       }
  39.       
  40.       internal function controls(param1:Array) : void
  41.       {
  42.          var _loc2_:int = 0;
  43.          var _loc3_:int = 0;
  44.          velx = 0;
  45.          vely = 0;
  46.          if(param1[38])
  47.          {
  48.             vely = speed * -1;
  49.          }
  50.          else if(param1[40])
  51.          {
  52.             vely = speed;
  53.          }
  54.          else if(param1[37])
  55.          {
  56.             velx = speed * -1;
  57.          }
  58.          else if(param1[39])
  59.          {
  60.             velx = speed;
  61.          }
  62.          _loc3_ = 0;
  63.          _loc2_ = 0;
  64.          if(param1[87])
  65.          {
  66.             _loc3_ = -1;
  67.          }
  68.          if(param1[83])
  69.          {
  70.             _loc3_ = 1;
  71.          }
  72.          if(param1[65])
  73.          {
  74.             _loc2_ = -1;
  75.          }
  76.          if(param1[68])
  77.          {
  78.             _loc2_ = 1;
  79.          }
  80.          if((_loc3_ != 0 || _loc2_ != 0) && shot == false)
  81.          {
  82.             gun.fire(x,y,_loc2_,_loc3_);
  83.             shot = true;
  84.          }
  85.          if(!param1[87] && !param1[83] && !param1[65] && !param1[68])
  86.          {
  87.             shot = false;
  88.          }
  89.       }
  90.       
  91.       internal function update(param1:Event) : void
  92.       {
  93.          var _loc2_:int = 0;
  94.          x += velx;
  95.          y += vely;
  96.          if(x < 0)
  97.          {
  98.             x = 0;
  99.          }
  100.          if(x > 720)
  101.          {
  102.             x = 720;
  103.          }
  104.          if(y < 0)
  105.          {
  106.             y = 0;
  107.          }
  108.          if(y > 480)
  109.          {
  110.             y = 480;
  111.          }
  112.          gun.update(param1);
  113.       }
  114.    }
  115. }
  116.