Effect Rotate With Parent (#5999)

* Effect Rotate With Parent

* Use Rotc

* Wording

* Base Rotation

* Rotate effect rotation with parent.
This commit is contained in:
Matthew Peng 2021-09-27 08:55:56 -07:00 committed by GitHub
parent 6fb7f4fe26
commit 083c21ea3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 11 deletions

View File

@ -0,0 +1 @@
{version:6,fields:[{name:color,type:arc.graphics.Color},{name:data,type:java.lang.Object},{name:effect,type:mindustry.entities.Effect},{name:lifetime,type:float},{name:offsetPos,type:float},{name:offsetRot,type:float},{name:offsetX,type:float},{name:offsetY,type:float},{name:parent,type:mindustry.gen.Posc},{name:rotDirWithParent,type:boolean},{name:rotPosWithParent,type:boolean},{name:rotation,type:float},{name:time,type:float},{name:x,type:float},{name:y,type:float}]}

View File

@ -362,13 +362,13 @@ public class Fx{
Fill.circle(e.x, e.y, e.fin() * 10);
Drawf.light(e.x, e.y, e.fin() * 20f, Pal.heal, 0.7f);
}).followParent(true),
}).followParent(true).rotWithParent(true),
greenLaserChargeSmall = new Effect(40f, 100f, e -> {
color(Pal.heal);
stroke(e.fin() * 2f);
Lines.circle(e.x, e.y, e.fout() * 50f);
}).followParent(true),
}).followParent(true).rotWithParent(true),
greenCloud = new Effect(80f, e -> {
color(Pal.heal);
@ -1943,7 +1943,7 @@ public class Fx{
}
Lines.endLine();
}).followParent(false),
}).followParent(false).rotWithParent(false),
chainEmp = new Effect(30f, 300f, e -> {
if(!(e.data instanceof Position p)) return;
@ -1980,5 +1980,5 @@ public class Fx{
}
Lines.endLine();
}).followParent(false);
}).followParent(false).rotWithParent(false);
}

View File

@ -30,8 +30,12 @@ public class Effect{
public float lifetime = 50f;
/** Clip size. */
public float clip;
/** Amount added to rotation */
public float baseRotation;
/** If true, parent unit is data are followed. */
public boolean followParent;
/** If this and followParent are true, the effect will offset and rotate with the parent's rotation. */
public boolean rotWithParent;
public float layer = Layer.effect;
public float layerDuration;
@ -61,11 +65,21 @@ public class Effect{
return this;
}
public Effect rotWithParent(boolean follow){
rotWithParent = follow;
return this;
}
public Effect layer(float l){
layer = l;
return this;
}
public Effect baseRotation(float d){
baseRotation = d;
return this;
}
public Effect layer(float l, float duration){
layer = l;
this.layerDuration = duration;
@ -156,12 +170,15 @@ public class Effect{
EffectState entity = EffectState.create();
entity.effect = effect;
entity.rotation = rotation;
entity.rotation = effect.baseRotation + rotation;
entity.data = data;
entity.lifetime = effect.lifetime;
entity.set(x, y);
entity.color.set(color);
if(effect.followParent && data instanceof Posc p) entity.parent = p;
if(effect.followParent && data instanceof Posc p){
entity.parent = p;
entity.rotWithParent = effect.rotWithParent;
}
entity.add();
}
}

View File

@ -1,29 +1,41 @@
package mindustry.entities.comp;
import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@Component
abstract class ChildComp implements Posc{
@Import float x, y;
abstract class ChildComp implements Posc, Rotc{
@Import float x, y, rotation;
@Nullable Posc parent;
float offsetX, offsetY;
boolean rotWithParent;
float offsetX, offsetY, offsetPos, offsetRot;
@Override
public void add(){
if(parent != null){
offsetX = x - parent.getX();
offsetY = y - parent.getY();
if(rotWithParent && parent instanceof Rotc r){
offsetPos = -r.rotation();
offsetRot = rotation - r.rotation();
}
}
}
@Override
public void update(){
if(parent != null){
x = parent.getX() + offsetX;
y = parent.getY() + offsetY;
if(rotWithParent && parent instanceof Rotc r){
x = parent.getX() + Angles.trnsx(r.rotation() + offsetPos, offsetX, offsetY);
y = parent.getY() + Angles.trnsy(r.rotation() + offsetPos, offsetX, offsetY);
rotation = r.rotation() + offsetRot;
}else{
x = parent.getX() + offsetX;
y = parent.getY() + offsetY;
}
}
}
}