home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / midnightstrike1.swf / scripts / __Packages / com / neodelight / v2D / MoverLine.as < prev    next >
Encoding:
Text File  |  2007-04-02  |  3.0 KB  |  98 lines

  1. class com.neodelight.v2D.MoverLine extends com.neodelight.v2D.Mover
  2. {
  3.    var destination;
  4.    var origin;
  5.    var defaultOrigin;
  6.    var defaultDestination;
  7.    var speed;
  8.    var destinationPause;
  9.    var dir;
  10.    var flagSkip;
  11.    var flagTrigger;
  12.    var startPos;
  13.    var pos;
  14.    var sleep;
  15.    var active;
  16.    var v;
  17.    var client;
  18.    function MoverLine(client, config)
  19.    {
  20.       super(client);
  21.       this.destination = new com.neodelight.std.Vector3D(this.origin.x + int(config.moverDx),this.origin.y + int(config.moverDy),0);
  22.       this.defaultOrigin = this.origin;
  23.       this.defaultDestination = this.destination;
  24.       this.speed = com.neodelight.std.XMath.toNumber(config.moverV);
  25.       this.destinationPause = com.neodelight.std.XMath.toNumber(config.moverDestinationPause);
  26.       this.dir = 1;
  27.       this.flagSkip = Boolean(config.moverSkip);
  28.       this.flagTrigger = Boolean(config.moverTrigger);
  29.       this.startPos = com.neodelight.std.XMath.toNumber(config.moverStartPos);
  30.       this.reset();
  31.    }
  32.    function reset()
  33.    {
  34.       super.reset();
  35.       if(this.startPos < 0)
  36.       {
  37.          this.destination = this.defaultOrigin;
  38.          this.origin = this.defaultDestination;
  39.       }
  40.       this.pos.x = this.origin.x + Math.abs(this.startPos) * (this.destination.x - this.pos.x);
  41.       this.pos.y = this.origin.y + Math.abs(this.startPos) * (this.destination.y - this.pos.y);
  42.       this.sleep = 0;
  43.    }
  44.    function move()
  45.    {
  46.       if(!this.active)
  47.       {
  48.          this.v.x = 0;
  49.          this.v.y = 0;
  50.          return undefined;
  51.       }
  52.       super.move();
  53.       if(this.sleep)
  54.       {
  55.          this.sleep = Math.max(0,this.sleep - _global.dt);
  56.          this.v.x = 0;
  57.          this.v.y = 0;
  58.       }
  59.       else
  60.       {
  61.          this.v.x = this.destination.x - this.pos.x;
  62.          this.v.y = this.destination.y - this.pos.y;
  63.          var _loc4_ = Math.max(0,Math.min(1,this.speed / Math.sqrt(this.v.x * this.v.x + this.v.y * this.v.y)));
  64.          if(Math.round(_loc4_ * 1000) / 1000 == 1)
  65.          {
  66.             this.sleep = this.destinationPause;
  67.             if(this.flagSkip)
  68.             {
  69.                this.pos.x = this.origin.x;
  70.                this.pos.y = this.origin.y;
  71.             }
  72.             else
  73.             {
  74.                var _loc5_ = this.destination;
  75.                this.destination = this.origin;
  76.                this.origin = _loc5_;
  77.             }
  78.             if(this.flagTrigger)
  79.             {
  80.                this.active = false;
  81.             }
  82.          }
  83.          this.v.x *= _loc4_;
  84.          this.v.y *= _loc4_;
  85.          this.client.lookDir = this.v.x >= 0 ? 1 : -1;
  86.       }
  87.    }
  88.    function getTotalBoundingRect()
  89.    {
  90.       this.client.totalBoundingRect.p0.x = this.origin.x;
  91.       this.client.totalBoundingRect.p0.y = this.origin.y;
  92.       this.client.totalBoundingRect.p1.x = this.destination.x;
  93.       this.client.totalBoundingRect.p1.y = this.destination.y;
  94.       this.client.totalBoundingRect.standardize();
  95.       return this.client.totalBoundingRect;
  96.    }
  97. }
  98.