Effect Rotate With Parent (#5999)
* Effect Rotate With Parent * Use Rotc * Wording * Base Rotation * Rotate effect rotation with parent.
This commit is contained in:
@@ -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}]}
|
||||||
@@ -362,13 +362,13 @@ public class Fx{
|
|||||||
|
|
||||||
Fill.circle(e.x, e.y, e.fin() * 10);
|
Fill.circle(e.x, e.y, e.fin() * 10);
|
||||||
Drawf.light(e.x, e.y, e.fin() * 20f, Pal.heal, 0.7f);
|
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 -> {
|
greenLaserChargeSmall = new Effect(40f, 100f, e -> {
|
||||||
color(Pal.heal);
|
color(Pal.heal);
|
||||||
stroke(e.fin() * 2f);
|
stroke(e.fin() * 2f);
|
||||||
Lines.circle(e.x, e.y, e.fout() * 50f);
|
Lines.circle(e.x, e.y, e.fout() * 50f);
|
||||||
}).followParent(true),
|
}).followParent(true).rotWithParent(true),
|
||||||
|
|
||||||
greenCloud = new Effect(80f, e -> {
|
greenCloud = new Effect(80f, e -> {
|
||||||
color(Pal.heal);
|
color(Pal.heal);
|
||||||
@@ -1943,7 +1943,7 @@ public class Fx{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lines.endLine();
|
Lines.endLine();
|
||||||
}).followParent(false),
|
}).followParent(false).rotWithParent(false),
|
||||||
|
|
||||||
chainEmp = new Effect(30f, 300f, e -> {
|
chainEmp = new Effect(30f, 300f, e -> {
|
||||||
if(!(e.data instanceof Position p)) return;
|
if(!(e.data instanceof Position p)) return;
|
||||||
@@ -1980,5 +1980,5 @@ public class Fx{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lines.endLine();
|
Lines.endLine();
|
||||||
}).followParent(false);
|
}).followParent(false).rotWithParent(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,12 @@ public class Effect{
|
|||||||
public float lifetime = 50f;
|
public float lifetime = 50f;
|
||||||
/** Clip size. */
|
/** Clip size. */
|
||||||
public float clip;
|
public float clip;
|
||||||
|
/** Amount added to rotation */
|
||||||
|
public float baseRotation;
|
||||||
/** If true, parent unit is data are followed. */
|
/** If true, parent unit is data are followed. */
|
||||||
public boolean followParent;
|
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 layer = Layer.effect;
|
||||||
public float layerDuration;
|
public float layerDuration;
|
||||||
@@ -61,11 +65,21 @@ public class Effect{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Effect rotWithParent(boolean follow){
|
||||||
|
rotWithParent = follow;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Effect layer(float l){
|
public Effect layer(float l){
|
||||||
layer = l;
|
layer = l;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Effect baseRotation(float d){
|
||||||
|
baseRotation = d;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Effect layer(float l, float duration){
|
public Effect layer(float l, float duration){
|
||||||
layer = l;
|
layer = l;
|
||||||
this.layerDuration = duration;
|
this.layerDuration = duration;
|
||||||
@@ -156,12 +170,15 @@ public class Effect{
|
|||||||
|
|
||||||
EffectState entity = EffectState.create();
|
EffectState entity = EffectState.create();
|
||||||
entity.effect = effect;
|
entity.effect = effect;
|
||||||
entity.rotation = rotation;
|
entity.rotation = effect.baseRotation + rotation;
|
||||||
entity.data = data;
|
entity.data = data;
|
||||||
entity.lifetime = effect.lifetime;
|
entity.lifetime = effect.lifetime;
|
||||||
entity.set(x, y);
|
entity.set(x, y);
|
||||||
entity.color.set(color);
|
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();
|
entity.add();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,41 @@
|
|||||||
package mindustry.entities.comp;
|
package mindustry.entities.comp;
|
||||||
|
|
||||||
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
abstract class ChildComp implements Posc{
|
abstract class ChildComp implements Posc, Rotc{
|
||||||
@Import float x, y;
|
@Import float x, y, rotation;
|
||||||
|
|
||||||
@Nullable Posc parent;
|
@Nullable Posc parent;
|
||||||
float offsetX, offsetY;
|
boolean rotWithParent;
|
||||||
|
float offsetX, offsetY, offsetPos, offsetRot;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(){
|
public void add(){
|
||||||
if(parent != null){
|
if(parent != null){
|
||||||
offsetX = x - parent.getX();
|
offsetX = x - parent.getX();
|
||||||
offsetY = y - parent.getY();
|
offsetY = y - parent.getY();
|
||||||
|
if(rotWithParent && parent instanceof Rotc r){
|
||||||
|
offsetPos = -r.rotation();
|
||||||
|
offsetRot = rotation - r.rotation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
if(parent != null){
|
if(parent != null){
|
||||||
x = parent.getX() + offsetX;
|
if(rotWithParent && parent instanceof Rotc r){
|
||||||
y = parent.getY() + offsetY;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user