home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Acao / fwg_knight.swf / scripts / __Packages / fwg / Knight.as < prev   
Encoding:
Text File  |  2008-08-28  |  12.9 KB  |  420 lines

  1. class fwg.Knight extends MovieClip
  2. {
  3.    var nTime_hit;
  4.    var nGn;
  5.    var bRun;
  6.    var nW_h;
  7.    var nSpeed_x;
  8.    var nSpeed_y;
  9.    var nY_p1;
  10.    var nY_p2;
  11.    var nR;
  12.    var nR_weapon;
  13.    var nMoment;
  14.    var nMode;
  15.    var bChain;
  16.    var nMode_skill;
  17.    var nTime_0;
  18.    var nTime_hold;
  19.    var bFall;
  20.    var nDir;
  21.    var nRadius;
  22.    var nSuper_max;
  23.    var nHealth_max;
  24.    var vHit;
  25.    var nCombo;
  26.    var sdHit;
  27.    var sdRun;
  28.    var nY_house;
  29.    var mHouse;
  30.    var nY_hero;
  31.    var mHero;
  32.    var __nHealth;
  33.    var nKill;
  34.    var pCtrl;
  35.    var __nSuper;
  36.    var __nKill;
  37.    var nHealth;
  38.    var nSuper;
  39.    function Knight()
  40.    {
  41.       super();
  42.       this.nTime_hit = 0;
  43.       this.nGn = 0;
  44.       this.bRun = true;
  45.       this.nW_h = 20;
  46.       this.nSpeed_x = 0;
  47.       this.nSpeed_y = 0;
  48.       this.nY_p1 = 0;
  49.       this.nY_p2 = 0;
  50.       this.nR = 0;
  51.       this.nR_weapon = 0;
  52.       this.nMoment = 0;
  53.       this.nMode = 0;
  54.       this.bChain = false;
  55.       this.nMode_skill = 0;
  56.       this.nTime_0 = 0;
  57.       this.nTime_hold = 0;
  58.       this.bFall = true;
  59.       this.nDir = 1;
  60.       this.nRadius = 40;
  61.       this.nSuper = this.nSuper_max = 200;
  62.       this.nHealth = this.nHealth_max = 100;
  63.       this.vHit = new math.Vector(0,-30);
  64.       this.nKill = 0;
  65.       this.nCombo = 0;
  66.       this.sdHit = new Sound(this);
  67.       this.sdRun = new Sound(this);
  68.       this.sdRun.attachSound("sdHorse_run");
  69.       this.sdHit.attachSound("sdHit_" + random(3));
  70.    }
  71.    function init()
  72.    {
  73.       this.nY_house = this.mHouse._y;
  74.       this.nY_hero = this.mHero._y;
  75.    }
  76.    function get nHealth()
  77.    {
  78.       return this.__nHealth;
  79.    }
  80.    function set nHealth(_nHealth)
  81.    {
  82.       this.__nHealth = _nHealth;
  83.       if(this.__nHealth < 0)
  84.       {
  85.          Global.GAME.nKill = this.nKill;
  86.          Global.GAME.gotoAndStop("gameover");
  87.       }
  88.       Global.GAME.mHealth.mClip._xscale = this.__nHealth / this.nHealth_max * 100;
  89.    }
  90.    function onEnterFrame()
  91.    {
  92.       if(!Global.GAME.bPause)
  93.       {
  94.          this.pCtrl.move();
  95.          this.falling();
  96.          this.moving();
  97.          this.movement();
  98.       }
  99.    }
  100.    function get nSuper()
  101.    {
  102.       return this.__nSuper;
  103.    }
  104.    function set nSuper(_nSuper)
  105.    {
  106.       this.__nSuper = _nSuper;
  107.       Global.GAME.mSuper.mClip._xscale = this.__nSuper / this.nSuper_max * 100;
  108.    }
  109.    function get nKill()
  110.    {
  111.       return this.__nKill;
  112.    }
  113.    function set nKill(_nKill)
  114.    {
  115.       this.__nKill = _nKill;
  116.       Global.GAME.mKill.sTxt = "KILLS: " + this.__nKill;
  117.       if(this.__nKill > 0)
  118.       {
  119.          this.nCombo = this.nCombo + 1;
  120.          Global.GAME.nScore += this.nCombo;
  121.          Global.GAME.mCombo.removeMovieClip();
  122.          Global.GAME.mCombo = Global.GAME.attachMovie("mCombo","mCombo",Global.GAME.getNextHighestDepth(),{_x:Global.WIDTH - 10,_y:350,sTxt:"SLAUGHTER\nBONUS " + this.nCombo,nTime:120 - this.nCombo * 2,rtFun:function()
  123.          {
  124.             Global.GAME.pKnight.nCombo = 0;
  125.          }});
  126.       }
  127.    }
  128.    function beHit(_l, _r)
  129.    {
  130.       if(getTimer() - this.nTime_hit > 50)
  131.       {
  132.          this.nTime_hit = getTimer();
  133.          this.sdHit.attachSound("sdHit_" + random(3));
  134.          this.sdHit.start();
  135.       }
  136.       this.nHealth -= 2;
  137.    }
  138.    function walk(_n)
  139.    {
  140.       if(this.nDir != _n || this.nSpeed_x == 0)
  141.       {
  142.          this.nDir = _n;
  143.          this._xscale = this.nDir * 100;
  144.          !this.bRun ? (this.nSpeed_x = _n * 4) : (this.nSpeed_x = _n * 7);
  145.          if(!this.bFall)
  146.          {
  147.             if(this.bRun)
  148.             {
  149.                this.nMoment = 2;
  150.             }
  151.             else
  152.             {
  153.                this.nMoment = 1;
  154.                this.mHouse._y = this.nY_house;
  155.                this.mHero._y = this.nY_hero;
  156.                this.mHouse.mTail._rotation = 0;
  157.             }
  158.          }
  159.       }
  160.    }
  161.    function stand()
  162.    {
  163.       this.nSpeed_x = 0;
  164.       this.bRun = true;
  165.       if(!this.bFall)
  166.       {
  167.          this.nMoment = 0;
  168.          this.mHouse._y = this.nY_house;
  169.          this.mHero._y = this.nY_hero;
  170.          this.mHouse.mTail._rotation = 0;
  171.          this.mHouse.mLeg_0._rotation = 0;
  172.          this.mHouse.mLeg_2._rotation = 0;
  173.          this.mHouse.mLeg_1._rotation = 0;
  174.          this.mHouse.mLeg_3._rotation = 0;
  175.          this.setPos();
  176.       }
  177.    }
  178.    function jump()
  179.    {
  180.       if(!this.bFall)
  181.       {
  182.          Global.playSound("sdJp");
  183.          this.nMoment = 3;
  184.          this.nSpeed_y = -24;
  185.          this.bFall = true;
  186.          this.mHouse._y = this.nY_house;
  187.          this.mHero._y = this.nY_hero;
  188.          this.mHouse.mTail._rotation = 90;
  189.          this.mHouse.mLeg_0._rotation = -90;
  190.          this.mHouse.mLeg_2._rotation = -90;
  191.          this.mHouse.mLeg_1._rotation = 60;
  192.          this.mHouse.mLeg_3._rotation = 60;
  193.       }
  194.    }
  195.    function fallEnd()
  196.    {
  197.       this.bFall = false;
  198.       this.nSpeed_y = 0;
  199.       this.setPos();
  200.       if(this.nSpeed_x != 0)
  201.       {
  202.          this.nMoment = 2;
  203.       }
  204.       else
  205.       {
  206.          this.sdRun.start();
  207.          this.stand();
  208.       }
  209.    }
  210.    function houseAtk()
  211.    {
  212.    }
  213.    function attacking()
  214.    {
  215.       this.nTime_hold = this.nTime_hold + 1;
  216.    }
  217.    function attack_2()
  218.    {
  219.       if(this.nSuper > 160)
  220.       {
  221.          this.nSuper -= 160;
  222.          this.mHero.mArm_0.gotoAndStop(this.nMode * 10 + 2);
  223.       }
  224.    }
  225.    function isStop()
  226.    {
  227.       var _loc2_ = !this.bChain;
  228.       this.bChain = false;
  229.       return _loc2_;
  230.    }
  231.    function atkReady()
  232.    {
  233.       this.nTime_0 = 0;
  234.       this.bChain = false;
  235.    }
  236.    function attack_0()
  237.    {
  238.       if(this.nMode_skill == 0)
  239.       {
  240.          if(getTimer() - this.nTime_0 < 300)
  241.          {
  242.             this.bChain = true;
  243.          }
  244.          this.nTime_0 = getTimer();
  245.          this.mHero.mArm_0.mClip.play();
  246.       }
  247.    }
  248.    function ckHit(_m)
  249.    {
  250.       var _loc4_ = {x:0,y:0};
  251.       var _loc2_ = new Object();
  252.       _m.localToGlobal(_loc4_);
  253.       for(var _loc9_ in Global.GAME.aEnemy)
  254.       {
  255.          _loc2_.x = Global.GAME.aEnemy[_loc9_].vHit.x;
  256.          _loc2_.y = Global.GAME.aEnemy[_loc9_].vHit.y;
  257.          Global.GAME.aEnemy[_loc9_].localToGlobal(_loc2_);
  258.          var _loc5_ = Common.distance(_loc4_.x,_loc4_.y,_loc2_.x,_loc2_.y);
  259.          if(_loc5_ < _m.nRadius + Global.GAME.aEnemy[_loc9_].nRadius)
  260.          {
  261.             if(getTimer() - this.nTime_hit > 50)
  262.             {
  263.                this.nTime_hit = getTimer();
  264.                this.sdHit.attachSound("sdHit_" + random(3));
  265.                this.sdHit.start();
  266.             }
  267.             this.nSuper < 200 && this.nSuper;
  268.             Global.GAME.aEnemy[_loc9_].beHit(_m.nPower,this.nDir <= 0 ? 3.141592653589793 - _m._rotation / Common.a2r : _m._rotation / Common.a2r);
  269.             _loc2_.x = (_loc4_.x + _loc2_.x) / 2;
  270.             _loc2_.y = (_loc4_.y + _loc2_.y) / 2;
  271.             Global.GAME.aEnemy[_loc9_].globalToLocal(_loc2_);
  272.             Common.addClip("mBlood",null,Global.GAME.aEnemy[_loc9_],{_x:_loc2_.x,_y:_loc2_.y,_rotation:_m._rotation + Common.rdm_2(-60,60)});
  273.          }
  274.       }
  275.    }
  276.    function changeWeapon(_n)
  277.    {
  278.       if(_n == undefined)
  279.       {
  280.          this.nMode != 1 ? (this.nMode = 1) : (this.nMode = 0);
  281.       }
  282.       else
  283.       {
  284.          this.nMode = _n;
  285.       }
  286.       Global.playSound("sdCh");
  287.       this.mHero.mArm_0.gotoAndStop(this.nMode * 10 + 1);
  288.    }
  289.    function movement()
  290.    {
  291.       var _loc2_ = getTimer();
  292.       switch(this.nMoment)
  293.       {
  294.          case 0:
  295.             this.mHero.mHead._y = - Common.linearCycle(_loc2_,800,2) - 10;
  296.             this.mHouse.mHead._rotation = Common.linearCycle(_loc2_,800,15);
  297.             break;
  298.          case 1:
  299.             this.mHero.mHead._y = - Common.linearCycle(_loc2_,800,2) - 10;
  300.             this.mHouse.mHead._rotation = Common.linearCycle(_loc2_,800,15);
  301.             this.mHouse.mLeg_0._rotation = 45 - Common.linearCycle(_loc2_,800,90);
  302.             this.mHouse.mLeg_2._rotation = 45 - Common.linearCycle(_loc2_ + 400,800,90);
  303.             this.mHouse.mLeg_1._rotation = 45 - Common.linearCycle(_loc2_ + 100,800,90);
  304.             this.mHouse.mLeg_3._rotation = 45 - Common.linearCycle(_loc2_ + 500,800,90);
  305.             break;
  306.          case 2:
  307.             this.mHero.mHead._y = - Common.unlinearCycle(_loc2_,500,2) - 10;
  308.             this.mHouse.mHead._rotation = Common.unlinearCycle(_loc2_,500,15);
  309.             this.mHouse.mTail._rotation = Common.linearCycle(_loc2_ - 100,500,60);
  310.             this.mHouse.mLeg_0._rotation = 60 - Common.unlinearCycle(_loc2_,500,120);
  311.             this.mHouse.mLeg_2._rotation = 60 - Common.unlinearCycle(_loc2_ + 50,500,120);
  312.             this.mHouse.mLeg_1._rotation = Common.unlinearCycle(_loc2_,500,120) - 60;
  313.             this.mHouse.mLeg_3._rotation = Common.unlinearCycle(_loc2_ + 50,500,120) - 60;
  314.             this.mHouse._y = - Common.linearCycle(_loc2_ + 50,500,20) + this.nY_house + 5;
  315.             this.mHero._y = - Common.linearCycle(_loc2_ + 25,500,20) + this.nY_hero + 5;
  316.             if(this.mHero._y > -27 && this.sdRun.position > 300)
  317.             {
  318.                this.sdRun.start();
  319.             }
  320.             break;
  321.          case 3:
  322.             this.mHouse._rotation = _loc0_ = this.nSpeed_y;
  323.             this.mHero._rotation = _loc0_;
  324.             break;
  325.          case 4:
  326.          case 5:
  327.          case 6:
  328.       }
  329.    }
  330.    function moving()
  331.    {
  332.       if(this.nSpeed_x)
  333.       {
  334.          this._x += this.nSpeed_x;
  335.          this.ground();
  336.          !this.bFall && this.setPos();
  337.       }
  338.    }
  339.    function falling()
  340.    {
  341.       if(this.bFall)
  342.       {
  343.          this.nSpeed_y += Game.nG;
  344.          if(Game.hitGround(this._x,this._y + this.nSpeed_y,this._parent,Global.GAME.mClip.mMid))
  345.          {
  346.             this.fallEnd();
  347.          }
  348.          else
  349.          {
  350.             this._y += this.nSpeed_y;
  351.          }
  352.       }
  353.    }
  354.    function setPos()
  355.    {
  356.       this.nY_p1 = Game.getBetween(this._x - this.nW_h,this._y,this._parent,Global.GAME.mClip.mMid);
  357.       this.nY_p2 = Game.getBetween(this._x + this.nW_h,this._y,this._parent,Global.GAME.mClip.mMid);
  358.       this._y = (Game.getBetween(this._x,this._y,this._parent,Global.GAME.mClip.mMid) + this._y) / 2 - 1;
  359.       this.nR = (Math.atan2(this.nY_p1 - this.nY_p2,this.nW_h * 2) + this.nR) / 2;
  360.       this.mHero._rotation = this.mHouse._rotation = (- this.nR) * Common.a2r * this.nDir;
  361.    }
  362.    function ground()
  363.    {
  364.       var _loc3_ = this._x + this._parent._x;
  365.       if(this.nSpeed_x > 0)
  366.       {
  367.          if(_loc3_ > 400)
  368.          {
  369.             if(Global.GAME.mMid.mShape_0._x + Global.GAME.mMid._x < -320)
  370.             {
  371.                Global.GAME.mMid.mShape_0._x += Global.WIDTH * 2 - 20;
  372.                Global.GAME.mMid.mShape_0.mClip.gotoAndStop(random(6) + 1);
  373.                Global.GAME.mMid.mShape_0._name = "mShape_0_";
  374.                Global.GAME.mMid.mShape_1._name = "mShape_0";
  375.                Global.GAME.mMid.mShape_2._name = "mShape_1";
  376.                Global.GAME.mMid.mShape_0_._name = "mShape_2";
  377.             }
  378.             this._parent._x -= this.nSpeed_x;
  379.             this._parent._parent.mMid._x = this._parent._x * 0.5;
  380.             var _loc2_ = (Math.abs(this._parent._x) + Global.WIDTH / 2) / Global.WIDTH;
  381.             if(this.nGn != int(_loc2_))
  382.             {
  383.                this.nGn = int(_loc2_);
  384.                Global.GAME.mClip.mMid.mShape_0.gotoAndStop(random(9) + 1);
  385.                Global.GAME.mClip.mMid.mShape_0._x += Global.WIDTH * 3;
  386.                Global.GAME.mClip.mMid.mShape_0._name = "mShape_0_";
  387.                Global.GAME.mClip.mMid.mShape_1._name = "mShape_0";
  388.                Global.GAME.mClip.mMid.mShape_2._name = "mShape_1";
  389.                Global.GAME.mClip.mMid.mShape_0_._name = "mShape_2";
  390.             }
  391.          }
  392.       }
  393.       else if(_loc3_ < 240)
  394.       {
  395.          if(Global.GAME.mMid.mShape_2._x + Global.GAME.mMid._x > 960)
  396.          {
  397.             Global.GAME.mMid.mShape_2._x -= Global.WIDTH * 2 - 20;
  398.             Global.GAME.mMid.mShape_2.mClip.gotoAndStop(random(6) + 1);
  399.             Global.GAME.mMid.mShape_2._name = "mShape_2_";
  400.             Global.GAME.mMid.mShape_1._name = "mShape_2";
  401.             Global.GAME.mMid.mShape_0._name = "mShape_1";
  402.             Global.GAME.mMid.mShape_2_._name = "mShape_0";
  403.          }
  404.          this._parent._x -= this.nSpeed_x;
  405.          this._parent._parent.mMid._x = this._parent._x * 0.5;
  406.          _loc2_ = (Math.abs(this._parent._x) + Global.WIDTH / 2) / Global.WIDTH;
  407.          if(this.nGn != int(_loc2_))
  408.          {
  409.             this.nGn = int(_loc2_);
  410.             Global.GAME.mClip.mMid.mShape_2.gotoAndStop(random(9) + 1);
  411.             Global.GAME.mClip.mMid.mShape_2._x -= Global.WIDTH * 3;
  412.             Global.GAME.mClip.mMid.mShape_2._name = "mShape_2_";
  413.             Global.GAME.mClip.mMid.mShape_1._name = "mShape_2";
  414.             Global.GAME.mClip.mMid.mShape_0._name = "mShape_1";
  415.             Global.GAME.mClip.mMid.mShape_2_._name = "mShape_0";
  416.          }
  417.       }
  418.    }
  419. }
  420.