|
|
@@ -14,17 +14,28 @@ define([ |
|
|
|
effect: null, |
|
|
|
|
|
|
|
ttl: 6, |
|
|
|
lineGrow: false, |
|
|
|
linePercentage: 0.1, |
|
|
|
|
|
|
|
lineShrink: false, |
|
|
|
shrinking: false, |
|
|
|
|
|
|
|
init: function() { |
|
|
|
effects.register(this); |
|
|
|
|
|
|
|
var xOffset = (this.toX >= this.obj.x) ? 1 : 0; |
|
|
|
|
|
|
|
var fromX = this.obj.x + xOffset; |
|
|
|
var fromY = this.obj.y + 0.5; |
|
|
|
|
|
|
|
var toX = this.lineGrow ? fromX : this.toX + 0.5; |
|
|
|
var toY = this.lineGrow ? fromY : this.toY + 0.5; |
|
|
|
|
|
|
|
this.effect = lightningBuilder.build({ |
|
|
|
fromX: this.obj.x + xOffset, |
|
|
|
fromY: this.obj.y + 0.5, |
|
|
|
toX: this.toX + 0.5, |
|
|
|
toY: this.toY + 0.5, |
|
|
|
fromX: fromX, |
|
|
|
fromY: fromY, |
|
|
|
toX: toX, |
|
|
|
toY: toY, |
|
|
|
divisions: this.divisions, |
|
|
|
colors: this.colors, |
|
|
|
maxDeviate: this.maxDeviate |
|
|
@@ -42,30 +53,77 @@ define([ |
|
|
|
lightningBuilder.destroy(this.effect); |
|
|
|
this.effect = null; |
|
|
|
|
|
|
|
this.ttl--; |
|
|
|
if (this.ttl == 0) { |
|
|
|
this.destroyed = true; |
|
|
|
return; |
|
|
|
if (!this.shrinking) { |
|
|
|
this.ttl--; |
|
|
|
if (this.ttl == 0) { |
|
|
|
this.destroyed = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var xOffset = (this.toX > this.obj.x) ? 1 : 0; |
|
|
|
var xOffset = (this.toX >= this.obj.x) ? 1 : 0; |
|
|
|
|
|
|
|
var fromX = this.obj.x + xOffset; |
|
|
|
var fromY = this.obj.y + 0.5; |
|
|
|
|
|
|
|
var toX = this.toX + 0.5; |
|
|
|
var toY = this.toY + 0.5; |
|
|
|
|
|
|
|
var changeTo = ( |
|
|
|
( |
|
|
|
(this.lineGrow) && |
|
|
|
(this.linePercentage < 1) |
|
|
|
) || |
|
|
|
( |
|
|
|
(this.shrinking) && |
|
|
|
(this.linePercentage > 0) |
|
|
|
) |
|
|
|
); |
|
|
|
|
|
|
|
if (changeTo) { |
|
|
|
var linePercentage = this.linePercentage; |
|
|
|
if (this.shrinking) { |
|
|
|
linePercentage /= 3; |
|
|
|
} else { |
|
|
|
linePercentage *= 1.5; |
|
|
|
if (linePercentage > 1) |
|
|
|
linePercentage = 1; |
|
|
|
} |
|
|
|
this.linePercentage = linePercentage; |
|
|
|
|
|
|
|
var angle = Math.atan2(toY - fromY, toX - fromX); |
|
|
|
var distance = Math.sqrt(Math.pow(fromX - toX, 2) + Math.pow(fromY - toY, 2)); |
|
|
|
toX = fromX + (Math.cos(angle) * distance * this.linePercentage); |
|
|
|
toY = fromY + (Math.sin(angle) * distance * this.linePercentage); |
|
|
|
} |
|
|
|
|
|
|
|
this.effect = lightningBuilder.build({ |
|
|
|
fromX: this.obj.x + xOffset, |
|
|
|
fromY: this.obj.y + 0.5, |
|
|
|
toX: this.toX + 0.5, |
|
|
|
toY: this.toY + 0.5, |
|
|
|
fromX: fromX, |
|
|
|
fromY: fromY, |
|
|
|
toX: toX, |
|
|
|
toY: toY, |
|
|
|
divisions: this.divisions, |
|
|
|
colors: this.colors, |
|
|
|
maxDeviate: this.maxDeviate |
|
|
|
}); |
|
|
|
|
|
|
|
if ((this.shrinking) && (linePercentage < 0.1)) |
|
|
|
this.destroyed = true; |
|
|
|
}, |
|
|
|
|
|
|
|
destroyManual: function() { |
|
|
|
if (this.effect) |
|
|
|
lightningBuilder.destroy(this.effect); |
|
|
|
if ((!this.lineShrink) || (this.shrinking)) { |
|
|
|
if (this.effect) |
|
|
|
lightningBuilder.destroy(this.effect); |
|
|
|
|
|
|
|
effects.unregister(this); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.destroyed = false; |
|
|
|
this.shrinking = true; |
|
|
|
|
|
|
|
effects.unregister(this); |
|
|
|
return true; |
|
|
|
} |
|
|
|
}; |
|
|
|
}); |