|
| 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