home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / Swing.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  2.5 KB  |  93 lines

  1. class Swing extends smashing.Renderable
  2. {
  3.    var arc;
  4.    var pLength;
  5.    var pHalfLength;
  6.    var length;
  7.    var botThresh;
  8.    var pCurrLength;
  9.    var pCurrHalf;
  10.    var x;
  11.    var y;
  12.    var nSwing = 3;
  13.    var cSwing = 0;
  14.    var color = 13333275;
  15.    var cDisable = 0;
  16.    var nDisable = 1;
  17.    var topThresh = 50;
  18.    var hitLength = 0;
  19.    var grabbable = true;
  20.    var bSwung = false;
  21.    function Swing()
  22.    {
  23.       super();
  24.       this.arc = 0.6283185307179586;
  25.       this.pLength = new smashing.Point(0,300);
  26.       this.pHalfLength = new smashing.Point(0,this.pLength.y / 2);
  27.       this.length = this.pLength.y;
  28.       this.botThresh = this.length - 10;
  29.    }
  30.    function update(nElapsed)
  31.    {
  32.       this.cDisable += nElapsed;
  33.       this.cSwing += nElapsed;
  34.       this.cSwing %= this.nSwing;
  35.       var _loc2_ = Math.sin(this.cSwing / this.nSwing * smashing.Phys.TWOPI) * this.arc;
  36.       this.pCurrLength = this.pLength.rotate(_loc2_);
  37.       this.pCurrHalf = this.pHalfLength.rotate(_loc2_ * 0.5);
  38.    }
  39.    function render()
  40.    {
  41.       var _loc2_ = smashing.Viewport.getPos(this);
  42.       this._x = _loc2_.x + smashing.Viewport.centerX;
  43.       this._y = _loc2_.y + smashing.Viewport.centerY;
  44.       this.clear();
  45.       this.lineStyle(4,this.color);
  46.       this.moveTo(0,0);
  47.       if(this.bSwung == true)
  48.       {
  49.          this.lineTo(this.pCurrLength.x,this.pCurrLength.y);
  50.       }
  51.       else
  52.       {
  53.          this.curveTo(this.pCurrHalf.x,this.pCurrHalf.y,this.pCurrLength.x,this.pCurrLength.y);
  54.       }
  55.    }
  56.    function react(oPlayer)
  57.    {
  58.       this.bSwung = true;
  59.       oPlayer.swing(this);
  60.    }
  61.    function checkHit(oPlayer)
  62.    {
  63.       if(this.cDisable > this.nDisable)
  64.       {
  65.          var _loc4_ = new smashing.Point(this.pCurrLength.y,- this.pCurrLength.x);
  66.          _loc4_.normalizeMe();
  67.          var _loc3_ = new smashing.Point(oPlayer.x - this.x,oPlayer.y - this.y);
  68.          var _loc6_ = Math.abs(_loc3_.dot(_loc4_));
  69.          if(_loc6_ > oPlayer.r)
  70.          {
  71.             this.hitLength = 0;
  72.             return false;
  73.          }
  74.          var _loc5_ = this.pCurrLength.normalize();
  75.          var _loc2_ = _loc3_.dot(_loc5_);
  76.          if(_loc2_ < this.topThresh)
  77.          {
  78.             this.hitLength = 0;
  79.             return false;
  80.          }
  81.          if(_loc2_ > this.botThresh)
  82.          {
  83.             this.hitLength = 0;
  84.             return false;
  85.          }
  86.          this.hitLength = _loc2_;
  87.          return true;
  88.       }
  89.       this.hitLength = 0;
  90.       return false;
  91.    }
  92. }
  93.