Files
Mindustry/core/src/mindustry/entities/comp/ChildComp.java
Matthew Peng 083c21ea3f Effect Rotate With Parent (#5999)
* Effect Rotate With Parent

* Use Rotc

* Wording

* Base Rotation

* Rotate effect rotation with parent.
2021-09-27 11:55:56 -04:00

42 lines
1.2 KiB
Java

package mindustry.entities.comp;
import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@Component
abstract class ChildComp implements Posc, Rotc{
@Import float x, y, rotation;
@Nullable Posc parent;
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){
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;
}
}
}
}