v0.7.4c: warding vfx are now faster when shooting at a distant target

This commit is contained in:
Evan Debenham 2019-08-11 15:59:56 -04:00
parent d6db2b6a45
commit 1ccccd58f8
2 changed files with 19 additions and 2 deletions

View File

@ -44,6 +44,8 @@ public class MagicMissile extends Emitter {
private Callback callback;
private PointF to;
private float sx;
private float sy;
private float time;
@ -90,6 +92,8 @@ public class MagicMissile extends Emitter {
revive();
this.to = to;
x = from.x;
y = from.y;
width = 0;
@ -160,15 +164,24 @@ public class MagicMissile extends Emitter {
y -= size / 2;
width = height = size;
}
public void setSpeed( float newSpeed ){
PointF d = PointF.diff( to, new PointF(x, y) );
PointF speed = new PointF( d ).normalize().scale( newSpeed );
sx = speed.x;
sy = speed.y;
time = d.length() / newSpeed;
}
//convenience method for the common case of a bolt going from a character to a tile or enemy
public static void boltFromChar(Group group, int type, Visual sprite, int to, Callback callback){
public static MagicMissile boltFromChar(Group group, int type, Visual sprite, int to, Callback callback){
MagicMissile missile = ((MagicMissile)group.recycle( MagicMissile.class ));
if (Actor.findChar(to) != null){
missile.reset(type, sprite.center(), Actor.findChar(to).sprite.destinationCenter(), callback);
} else {
missile.reset(type, sprite, to, callback);
}
return missile;
}
@Override

View File

@ -103,11 +103,15 @@ public class WandOfWarding extends Wand {
@Override
protected void fx(Ballistica bolt, Callback callback) {
MagicMissile.boltFromChar(curUser.sprite.parent,
MagicMissile m = MagicMissile.boltFromChar(curUser.sprite.parent,
MagicMissile.WARD,
curUser.sprite,
bolt.collisionPos,
callback);
if (bolt.dist > 10){
m.setSpeed(bolt.dist*20);
}
Sample.INSTANCE.play(Assets.SND_ZAP);
}