Skip to content

Commit 59dd182

Browse files
committed
Better swirl effect
Also convert to a dedicated class to make editing easier
1 parent 5a74f83 commit 59dd182

File tree

3 files changed

+125
-70
lines changed

3 files changed

+125
-70
lines changed

src/progressed/content/effects/EnergyFx.java

+3-69
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import arc.util.*;
77
import mindustry.entities.*;
88
import mindustry.graphics.*;
9+
import progressed.entities.effect.*;
910
import progressed.graphics.*;
1011
import progressed.util.*;
1112

@@ -78,9 +79,9 @@ public class EnergyFx{
7879
Drawf.light(e.x, e.y, rX * 2f, e.color, 0.8f);
7980
}),
8081

81-
kugelblitzCharge = makeSwirlEffect(30f, 8, 2f, 15f, 90f, false).layer(Layer.bullet - 0.03f),
82+
kugelblitzCharge = new SwirlEffect(30f, 8, 2f, 30f, 90f, false).layer(Layer.bullet - 0.03f),
8283

83-
blackHoleSwirl = makeSwirlEffect(90f, 8, 3f, 180f, 720f, true, true).layer(Layer.effect + 0.005f),
84+
blackHoleSwirl = new SwirlEffect(90f, 8, 3f, 120f, 480f, true, true).layer(Layer.effect + 0.005f),
8485

8586
blackHoleDespawn = new Effect(80f, e -> {
8687
float rad = 24f;
@@ -133,71 +134,4 @@ public class EnergyFx{
133134

134135
Drawf.light(e.x, e.y, circleRad * 1.6f, Pal.heal, e.fout());
135136
});
136-
137-
public static Effect makeSwirlEffect(Color color, float eLifetime, int length, float maxWidth, float minRot, float maxRot, float minDst, float maxDst, boolean light, boolean lerp){
138-
return new Effect(eLifetime, 400f, e -> {
139-
if(e.time < 1f) return;
140-
141-
float lifetime = e.lifetime - length;
142-
float dst;
143-
if(minDst < 0 || maxDst < 0){
144-
dst = Math.abs(e.rotation);
145-
}else{
146-
dst = Mathf.randomSeed(e.id, minDst, maxDst);
147-
}
148-
float l = Mathf.clamp(e.time / lifetime);
149-
if(lerp){
150-
color(color, e.color, l);
151-
}else{
152-
color(color);
153-
}
154-
155-
int points = (int)Math.min(e.time, length);
156-
float width = Mathf.clamp(e.time / (e.lifetime - length)) * maxWidth;
157-
float size = width / points;
158-
float baseRot = Mathf.randomSeed(e.id + 1, 360f), addRot = Mathf.randomSeed(e.id + 2, minRot, maxRot) * Mathf.sign(e.rotation);
159-
160-
float fout, lastAng = 0f;
161-
for(int i = 0; i < points; i++){
162-
fout = 1f - Mathf.clamp((e.time - points + i) / lifetime);
163-
v1.trns(baseRot + addRot * PMMathf.cbrt(fout), Mathf.maxZero(dst * fout));
164-
fout = 1f - Mathf.clamp((e.time - points + i + 1) / lifetime);
165-
v2.trns(baseRot + addRot * PMMathf.cbrt(fout), Mathf.maxZero(dst * fout));
166-
167-
float a2 = -v1.angleTo(v2) * Mathf.degRad;
168-
float a1 = i == 0 ? a2 : lastAng;
169-
170-
float
171-
cx = Mathf.sin(a1) * i * size,
172-
cy = Mathf.cos(a1) * i * size,
173-
nx = Mathf.sin(a2) * (i + 1) * size,
174-
ny = Mathf.cos(a2) * (i + 1) * size;
175-
176-
Fill.quad(
177-
e.x + v1.x - cx, e.y + v1.y - cy,
178-
e.x + v1.x + cx, e.y + v1.y + cy,
179-
e.x + v2.x + nx, e.y + v2.y + ny,
180-
e.x + v2.x - nx, e.y + v2.y - ny
181-
);
182-
if(light){
183-
Drawf.light(
184-
e.x + v1.x, e.y + v1.y,
185-
e.x + v2.x, e.y + v2.y,
186-
i * size * 6f, Draw.getColor().cpy(), l
187-
);
188-
}
189-
190-
lastAng = a2;
191-
}
192-
Draw.rect("hcircle", e.x + v2.x, e.y + v2.y, width * 2f, width * 2f, -Mathf.radDeg * lastAng);
193-
});
194-
}
195-
196-
public static Effect makeSwirlEffect(float eLifetime, int length, float maxWidth, float minRot, float maxRot, boolean light, boolean lerp){
197-
return makeSwirlEffect(Color.black, eLifetime, length, maxWidth, minRot, maxRot, -1, -1, light, lerp);
198-
}
199-
200-
public static Effect makeSwirlEffect(float eLifetime, int length, float maxWidth, float minRot, float maxRot, boolean lerp){
201-
return makeSwirlEffect(Color.black, eLifetime, length, maxWidth, minRot, maxRot, -1, -1, false, lerp);
202-
}
203137
}

src/progressed/content/effects/ModuleFx.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import mindustry.content.*;
99
import mindustry.entities.*;
1010
import mindustry.graphics.*;
11+
import progressed.entities.effect.*;
1112
import progressed.graphics.*;
1213

1314
import static arc.graphics.g2d.Draw.*;
@@ -107,7 +108,7 @@ public class ModuleFx{
107108
};
108109
}).layer(Layer.effect + 1.004f),
109110

110-
abyssSwirl = EnergyFx.makeSwirlEffect(Color.black, 30f, 5, 1.5f, 0f, 0f, 12f, 40f, false, false).layer(Layer.effect + 1.005f),
111+
abyssSwirl = new SwirlEffect(30f, Color.black, 5, 1.5f, 0f, 0f, 12f, 40f, false, false).layer(Layer.effect + 1.005f),
111112

112113
abyssGrow = new Effect(45f, e -> {
113114
float rad = 2f + e.fin(Interp.pow2Out) * 3f;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package progressed.entities.effect;
2+
3+
import arc.*;
4+
import arc.graphics.*;
5+
import arc.graphics.g2d.*;
6+
import arc.math.*;
7+
import mindustry.entities.*;
8+
import mindustry.graphics.*;
9+
10+
import static arc.graphics.g2d.Draw.*;
11+
import static arc.util.Tmp.*;
12+
13+
public class SwirlEffect extends Effect{
14+
public static TextureRegion hCircle;
15+
16+
public int length;
17+
public float width;
18+
public float minRot, maxRot;
19+
public float minDst, maxDst;
20+
public boolean light;
21+
public boolean lerp;
22+
public Color centerColor;
23+
public Interp fallterp = Interp.pow2Out;
24+
public Interp spinterp = Interp.pow3Out;
25+
26+
public SwirlEffect(float lifetime, float clipsize, Color centerColor, int length, float width, float minRot, float maxRot, float minDst, float maxDst, boolean light, boolean lerp){
27+
super();
28+
this.lifetime = lifetime;
29+
this.clip = clipsize;
30+
this.centerColor = centerColor;
31+
this.length = length;
32+
this.width = width;
33+
this.minRot = minRot;
34+
this.maxRot = maxRot;
35+
this.minDst = minDst;
36+
this.maxDst = maxDst;
37+
this.light = light;
38+
this.lerp = lerp;
39+
}
40+
41+
public SwirlEffect(float lifetime, Color centerColor, int length, float width, float minRot, float maxRot, float minDst, float maxDst, boolean light, boolean lerp){
42+
this(lifetime, 400f, centerColor, length, width, minRot, maxRot, minDst, maxDst, light, lerp);
43+
}
44+
45+
public SwirlEffect(float lifetime, int length, float width, float minRot, float maxRot, boolean light, boolean lerp){
46+
this(lifetime, Color.black, length, width, minRot, maxRot, -1, -1, light, lerp);
47+
}
48+
49+
public SwirlEffect(float lifetime, int length, float width, float minRot, float maxRot, boolean lerp){
50+
this(lifetime, Color.black, length, width, minRot, maxRot, -1, -1, false, lerp);
51+
}
52+
53+
public SwirlEffect setInterps(Interp fallterp, Interp spinterp){
54+
this.fallterp = fallterp;
55+
this.spinterp = spinterp;
56+
return this;
57+
}
58+
59+
public SwirlEffect setInterps(Interp interp){
60+
return setInterps(interp, interp);
61+
}
62+
63+
@Override
64+
public void render(EffectContainer e){
65+
float lifetime = e.lifetime - length;
66+
float dst;
67+
if(minDst < 0 || maxDst < 0){
68+
dst = Math.abs(e.rotation);
69+
}else{
70+
dst = Mathf.randomSeed(e.id, minDst, maxDst);
71+
}
72+
float l = Mathf.clamp(e.time / lifetime);
73+
if(lerp){
74+
color(centerColor, e.color, l);
75+
}else{
76+
color(centerColor);
77+
}
78+
79+
int points = (int)Math.min(e.time, length);
80+
float width = Mathf.clamp(e.time / (e.lifetime - length)) * this.width;
81+
float size = width / points;
82+
float baseRot = Mathf.randomSeed(e.id + 1, 360f), addRot = Mathf.randomSeed(e.id + 2, minRot, maxRot) * Mathf.sign(e.rotation);
83+
84+
float fout, lastAng = 0f;
85+
for(int i = 0; i < points; i++){
86+
fout = 1f - Mathf.clamp((e.time - points + i) / lifetime);
87+
v1.trns(baseRot + addRot * spinterp.apply(fout), Mathf.maxZero(dst * fallterp.apply(fout)));
88+
fout = 1f - Mathf.clamp((e.time - points + i + 1) / lifetime);
89+
v2.trns(baseRot + addRot * spinterp.apply(fout), Mathf.maxZero(dst * fallterp.apply(fout)));
90+
91+
float a2 = -v1.angleTo(v2) * Mathf.degRad;
92+
float a1 = i == 0 ? a2 : lastAng;
93+
94+
float
95+
cx = Mathf.sin(a1) * i * size,
96+
cy = Mathf.cos(a1) * i * size,
97+
nx = Mathf.sin(a2) * (i + 1) * size,
98+
ny = Mathf.cos(a2) * (i + 1) * size;
99+
100+
Fill.quad(
101+
e.x + v1.x - cx, e.y + v1.y - cy,
102+
e.x + v1.x + cx, e.y + v1.y + cy,
103+
e.x + v2.x + nx, e.y + v2.y + ny,
104+
e.x + v2.x - nx, e.y + v2.y - ny
105+
);
106+
if(light){
107+
Drawf.light(
108+
e.x + v1.x, e.y + v1.y,
109+
e.x + v2.x, e.y + v2.y,
110+
i * size * 6f, Draw.getColor().cpy(), l
111+
);
112+
}
113+
114+
lastAng = a2;
115+
}
116+
117+
if(hCircle == null) hCircle = Core.atlas.find("hcircle");
118+
Draw.rect(hCircle, e.x + v2.x, e.y + v2.y, width * 2f, width * 2f, -Mathf.radDeg * lastAng);
119+
}
120+
}

0 commit comments

Comments
 (0)