home *** CD-ROM | disk | FTP | other *** search
- class com.neodelight.v2D.MoverLine extends com.neodelight.v2D.Mover
- {
- var destination;
- var origin;
- var defaultOrigin;
- var defaultDestination;
- var speed;
- var destinationPause;
- var dir;
- var flagSkip;
- var flagTrigger;
- var startPos;
- var pos;
- var sleep;
- var active;
- var v;
- var client;
- function MoverLine(client, config)
- {
- super(client);
- this.destination = new com.neodelight.std.Vector3D(this.origin.x + int(config.moverDx),this.origin.y + int(config.moverDy),0);
- this.defaultOrigin = this.origin;
- this.defaultDestination = this.destination;
- this.speed = com.neodelight.std.XMath.toNumber(config.moverV);
- this.destinationPause = com.neodelight.std.XMath.toNumber(config.moverDestinationPause);
- this.dir = 1;
- this.flagSkip = Boolean(config.moverSkip);
- this.flagTrigger = Boolean(config.moverTrigger);
- this.startPos = com.neodelight.std.XMath.toNumber(config.moverStartPos);
- this.reset();
- }
- function reset()
- {
- super.reset();
- if(this.startPos < 0)
- {
- this.destination = this.defaultOrigin;
- this.origin = this.defaultDestination;
- }
- this.pos.x = this.origin.x + Math.abs(this.startPos) * (this.destination.x - this.pos.x);
- this.pos.y = this.origin.y + Math.abs(this.startPos) * (this.destination.y - this.pos.y);
- this.sleep = 0;
- }
- function move()
- {
- if(!this.active)
- {
- this.v.x = 0;
- this.v.y = 0;
- return undefined;
- }
- super.move();
- if(this.sleep)
- {
- this.sleep = Math.max(0,this.sleep - _global.dt);
- this.v.x = 0;
- this.v.y = 0;
- }
- else
- {
- this.v.x = this.destination.x - this.pos.x;
- this.v.y = this.destination.y - this.pos.y;
- var _loc4_ = Math.max(0,Math.min(1,this.speed / Math.sqrt(this.v.x * this.v.x + this.v.y * this.v.y)));
- if(Math.round(_loc4_ * 1000) / 1000 == 1)
- {
- this.sleep = this.destinationPause;
- if(this.flagSkip)
- {
- this.pos.x = this.origin.x;
- this.pos.y = this.origin.y;
- }
- else
- {
- var _loc5_ = this.destination;
- this.destination = this.origin;
- this.origin = _loc5_;
- }
- if(this.flagTrigger)
- {
- this.active = false;
- }
- }
- this.v.x *= _loc4_;
- this.v.y *= _loc4_;
- this.client.lookDir = this.v.x >= 0 ? 1 : -1;
- }
- }
- function getTotalBoundingRect()
- {
- this.client.totalBoundingRect.p0.x = this.origin.x;
- this.client.totalBoundingRect.p0.y = this.origin.y;
- this.client.totalBoundingRect.p1.x = this.destination.x;
- this.client.totalBoundingRect.p1.y = this.destination.y;
- this.client.totalBoundingRect.standardize();
- return this.client.totalBoundingRect;
- }
- }
-