home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / flameout.swf / scripts / __Packages / Player.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  8.9 KB  |  281 lines

  1. class Player extends LRG.LRGMovieClip
  2. {
  3.    var m_kController;
  4.    var m_fAngularVelocity;
  5.    var m_fSpeed;
  6.    var m_fLastUpdateTime;
  7.    var m_fLastShootTime;
  8.    var m_bTurningLeft;
  9.    var m_bTurningRight;
  10.    var m_bEndingTurn;
  11.    var m_fLastRotation;
  12.    var m_bFiring;
  13.    var m_fFireRate;
  14.    var m_kFireBeamEmissionPoint;
  15.    function Player()
  16.    {
  17.       super();
  18.    }
  19.    function init()
  20.    {
  21.       super.init();
  22.       this.setClock(_global.getGameTimer());
  23.       var _loc4_ = new Object();
  24.       _loc4_.m_sName = "GENERIC";
  25.       _loc4_.m_fFPS = 120;
  26.       var _loc5_ = new LRG.LRGGenericAction(_loc4_);
  27.       this.addAction(_loc5_);
  28.       this.setupTurnAnimationActions();
  29.       this.m_kController = undefined;
  30.       this.m_fAngularVelocity = 0;
  31.       this.m_fSpeed = 0;
  32.       this.m_fLastUpdateTime = this.getClipTime();
  33.       this.m_fLastShootTime = this.getClipTime();
  34.       this.m_bTurningLeft = false;
  35.       this.m_bTurningRight = false;
  36.       this.m_bEndingTurn = false;
  37.    }
  38.    function setupTurnAnimationActions()
  39.    {
  40.       var _loc6_ = new Object();
  41.       _loc6_.m_sName = "START_LEFT_TURN";
  42.       _loc6_.m_fFPS = 120;
  43.       _loc6_.m_fStartFrame = 83;
  44.       _loc6_.m_fEndFrame = 112;
  45.       _loc6_.m_bLoop = false;
  46.       _loc6_.m_fDirection = 1;
  47.       var _loc12_ = new LRG.LRGAnimationAction(_loc6_);
  48.       this.addAction(_loc12_);
  49.       var _loc4_ = new Object();
  50.       _loc4_.m_sName = "LOOP_LEFT_TURN";
  51.       _loc4_.m_fFPS = 120;
  52.       _loc4_.m_fStartFrame = 113;
  53.       _loc4_.m_fEndFrame = 142;
  54.       _loc4_.m_bLoop = false;
  55.       _loc4_.m_fDirection = 1;
  56.       var _loc13_ = new LRG.LRGAnimationAction(_loc4_);
  57.       this.addAction(_loc13_);
  58.       var _loc5_ = new Object();
  59.       _loc5_.m_sName = "STOP_LEFT_TURN";
  60.       _loc5_.m_fFPS = 20;
  61.       _loc5_.m_fStartFrame = 83;
  62.       _loc5_.m_fEndFrame = 112;
  63.       _loc5_.m_bLoop = false;
  64.       _loc5_.m_fDirection = -1;
  65.       var _loc8_ = new LRG.LRGAnimationAction(_loc5_);
  66.       this.addAction(_loc8_);
  67.       var _loc2_ = new Object();
  68.       _loc2_.m_sName = "START_RIGHT_TURN";
  69.       _loc2_.m_fFPS = 120;
  70.       _loc2_.m_fStartFrame = 23;
  71.       _loc2_.m_fEndFrame = 52;
  72.       _loc2_.m_bLoop = false;
  73.       _loc2_.m_fDirection = 1;
  74.       var _loc9_ = new LRG.LRGAnimationAction(_loc2_);
  75.       this.addAction(_loc9_);
  76.       var _loc3_ = new Object();
  77.       _loc3_.m_sName = "LOOP_RIGHT_TURN";
  78.       _loc3_.m_fFPS = 120;
  79.       _loc3_.m_fStartFrame = 53;
  80.       _loc3_.m_fEndFrame = 82;
  81.       _loc3_.m_bLoop = false;
  82.       _loc3_.m_fDirection = 1;
  83.       var _loc10_ = new LRG.LRGAnimationAction(_loc3_);
  84.       this.addAction(_loc10_);
  85.       var _loc7_ = new Object();
  86.       _loc7_.m_sName = "STOP_RIGHT_TURN";
  87.       _loc7_.m_fFPS = 20;
  88.       _loc7_.m_fStartFrame = 23;
  89.       _loc7_.m_fEndFrame = 52;
  90.       _loc7_.m_bLoop = false;
  91.       _loc7_.m_fDirection = -1;
  92.       var _loc11_ = new LRG.LRGAnimationAction(_loc7_);
  93.       this.addAction(_loc11_);
  94.    }
  95.    function onStartGame()
  96.    {
  97.       this.m_kController.onStartGame();
  98.    }
  99.    function onStartRound()
  100.    {
  101.       this.setSpeed(Settings(_global.getSettings()).getSetting("PLAYER_TURN_SPEED"));
  102.       this.setFireRate(Settings(_global.getSettings()).getSetting("PLAYER_FIRE_RATE"));
  103.       this.m_fLastUpdateTime = this.getClipTime();
  104.       this.m_fLastShootTime = 0;
  105.       this.startAction("GENERIC",null,true);
  106.       this.m_kController.onStartRound();
  107.       this.m_fLastRotation = 0;
  108.       this.m_bFiring = false;
  109.       this.gotoAndStop("Normal");
  110.    }
  111.    function onEndRound()
  112.    {
  113.       this.m_kController.onEndRound();
  114.       this.stopAction("GENERIC",false);
  115.    }
  116.    function setController(kController)
  117.    {
  118.       this.m_kController = kController;
  119.       this.m_kController.setPlayer(this);
  120.    }
  121.    function setAngularVelocity(fVel)
  122.    {
  123.       this.m_fAngularVelocity = fVel;
  124.    }
  125.    function getAngularVelocity()
  126.    {
  127.       return this.m_fAngularVelocity;
  128.    }
  129.    function setSpeed(fSpeed)
  130.    {
  131.       this.m_fSpeed = fSpeed;
  132.    }
  133.    function getSpeed()
  134.    {
  135.       return this.m_fSpeed;
  136.    }
  137.    function setFireRate(fFireRate)
  138.    {
  139.       this.m_fFireRate = fFireRate;
  140.    }
  141.    function getFireRate()
  142.    {
  143.       return this.m_fFireRate;
  144.    }
  145.    function isFiring()
  146.    {
  147.       return this.m_bFiring;
  148.    }
  149.    function onRequestTurnLeft()
  150.    {
  151.       this.setAngularVelocity(- this.m_fSpeed);
  152.    }
  153.    function onRequestTurnRight()
  154.    {
  155.       this.setAngularVelocity(this.m_fSpeed);
  156.    }
  157.    function onRequestStop()
  158.    {
  159.       this.setAngularVelocity(0);
  160.    }
  161.    function onRequestShootFireBeam()
  162.    {
  163.       if(!this.m_bFiring)
  164.       {
  165.          var _loc4_ = _global.g_kApplication.m_kGameScreen;
  166.          var _loc3_ = this.getClipTime() - this.m_fLastShootTime;
  167.          if(_loc3_ > 1 / this.m_fFireRate)
  168.          {
  169.             this.playAnimation("SHOOT_FIRE",45,11,21,false,1);
  170.             this.m_bFiring = true;
  171.          }
  172.       }
  173.    }
  174.    function doEnterFrame()
  175.    {
  176.       if(ApplicationState(_global.getApplicationState()).isPaused())
  177.       {
  178.          return undefined;
  179.       }
  180.       var _loc3_ = this.getClipTime() - this.m_fLastUpdateTime;
  181.       this.m_kController.update(_loc3_);
  182.       this._rotation += this.m_fAngularVelocity * _loc3_;
  183.       if(this._rotation != this.m_fLastRotation && !this.m_bFiring)
  184.       {
  185.          if(!this.m_bTurningLeft && !this.m_bTurningRight)
  186.          {
  187.             var _loc5_ = Math.abs(this._rotation - this.m_fLastRotation + 360) % 360;
  188.             var _loc4_ = Math.abs(this.m_fLastRotation - this._rotation + 360) % 360;
  189.             if(_loc5_ < _loc4_)
  190.             {
  191.                if(this.m_bEndingTurn)
  192.                {
  193.                   this.m_bEndingTurn = false;
  194.                   this.startAction("LOOP_RIGHT_TURN",null,true);
  195.                }
  196.                else
  197.                {
  198.                   this.startAction("START_RIGHT_TURN",null,true);
  199.                }
  200.                this.m_bTurningRight = true;
  201.             }
  202.             else
  203.             {
  204.                if(this.m_bEndingTurn)
  205.                {
  206.                   this.m_bEndingTurn = false;
  207.                   this.startAction("LOOP_LEFT_TURN",null,true);
  208.                }
  209.                else
  210.                {
  211.                   this.startAction("START_LEFT_TURN",null,true);
  212.                }
  213.                this.m_bTurningLeft = true;
  214.             }
  215.          }
  216.       }
  217.       this.m_fLastRotation = this._rotation;
  218.       this.m_fLastUpdateTime = this.getClipTime();
  219.    }
  220.    function onActionCompleted(sActionKey)
  221.    {
  222.       switch(sActionKey)
  223.       {
  224.          case "SHOOT_FIRE":
  225.             var _loc4_ = _global.g_kApplication.m_kGameScreen;
  226.             this.m_bFiring = false;
  227.             if(_loc4_.getFireBeam())
  228.             {
  229.                _loc4_.onRequestRemoveFireBeam();
  230.             }
  231.             _global.playSound("fma_roy_shoots.wav",1,this);
  232.             PlayerState(_global.getPlayerState()).setShotsThisRound(PlayerState(_global.getPlayerState()).getShotsThisRound() + 1);
  233.             PlayerState(_global.getPlayerState()).setShotsTotal(PlayerState(_global.getPlayerState()).getShotsTotal() + 1);
  234.             this.m_fLastShootTime = this.getClipTime();
  235.             var _loc3_ = {x:this.m_kFireBeamEmissionPoint._x,y:this.m_kFireBeamEmissionPoint._y};
  236.             this.localToGlobal(_loc3_);
  237.             _loc4_.shootFireBeam(_loc3_.x,_loc3_.y,this._rotation,Settings(_global.getSettings()).getSetting("FIRE_BEAM_SPEED"));
  238.          case "START_LEFT_TURN":
  239.          case "START_RIGHT_TURN":
  240.          case "LOOP_LEFT_TURN":
  241.          case "LOOP_RIGHT_TURN":
  242.             if(this._rotation != this.m_fLastRotation)
  243.             {
  244.                var _loc6_ = Math.abs(this._rotation - this.m_fLastRotation + 360) % 360;
  245.                var _loc5_ = Math.abs(this.m_fLastRotation - this._rotation + 360) % 360;
  246.                if(_loc6_ < _loc5_)
  247.                {
  248.                   this.startAction("LOOP_RIGHT_TURN",null,true);
  249.                   this.m_bTurningRight = true;
  250.                   this.m_bTurningLeft = false;
  251.                }
  252.                else
  253.                {
  254.                   this.startAction("LOOP_LEFT_TURN",null,true);
  255.                   this.m_bTurningLeft = true;
  256.                   this.m_bTurningRight = false;
  257.                }
  258.             }
  259.             else
  260.             {
  261.                if(this.m_bTurningLeft)
  262.                {
  263.                   this.startAction("STOP_LEFT_TURN",null,true);
  264.                }
  265.                else
  266.                {
  267.                   this.startAction("STOP_RIGHT_TURN",null,true);
  268.                }
  269.                this.m_bEndingTurn = true;
  270.                this.m_bTurningLeft = false;
  271.                this.m_bTurningRight = false;
  272.             }
  273.             break;
  274.          case "STOP_LEFT_TURN":
  275.          case "STOP_RIGHT_TURN":
  276.             this.m_bEndingTurn = false;
  277.             this.gotoAndStop("Stand");
  278.       }
  279.    }
  280. }
  281.