|
| 1 | +package unity.content; |
| 2 | + |
| 3 | +import arc.*; |
| 4 | +import arc.graphics.*; |
| 5 | +import arc.math.*; |
| 6 | +import arc.util.*; |
| 7 | +import unity.graphics.*; |
| 8 | +import unity.graphics.MultiTrail.*; |
| 9 | +import unity.util.*; |
| 10 | + |
| 11 | +public final class Trails{ |
| 12 | + public static TexturedTrail singlePhantasmal(int length){ |
| 13 | + return new TexturedTrail(Core.atlas.find("unity-phantasmal-trail"), length){{ |
| 14 | + blend = Blending.additive; |
| 15 | + fadeInterp = Interp.pow2In; |
| 16 | + sideFadeInterp = Interp.pow3In; |
| 17 | + mixInterp = Interp.pow10In; |
| 18 | + gradientInterp = Interp.pow10Out; |
| 19 | + fadeColor = new Color(0.3f, 0.5f, 1f); |
| 20 | + shrink = 0f; |
| 21 | + fadeAlpha = 1f; |
| 22 | + mixAlpha = 1f; |
| 23 | + trailChance = 0.4f; |
| 24 | + trailWidth = 1.6f; |
| 25 | + trailColor = UnityPal.monolithLight; |
| 26 | + }}; |
| 27 | + } |
| 28 | + |
| 29 | + public static TexturedTrail phantasmalExhaust(int length){ |
| 30 | + return Utils.with(singlePhantasmal(length), t -> { |
| 31 | + t.fadeInterp = Interp.pow3In; |
| 32 | + t.sideFadeInterp = Interp.pow5In; |
| 33 | + t.mixAlpha = 0f; |
| 34 | + t.trailChance = 0f; |
| 35 | + t.shrink = -3.6f; |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + public static MultiTrail phantasmal(int length){ |
| 40 | + return phantasmal(length, 3.6f, 3.5f, 0f); |
| 41 | + } |
| 42 | + |
| 43 | + public static MultiTrail phantasmal(RotationHandler rot, int length){ |
| 44 | + return phantasmal(rot, length, 3.6f, 3.5f, 0f); |
| 45 | + } |
| 46 | + |
| 47 | + public static MultiTrail phantasmal(int length, float scale, float magnitude, float offsetY){ |
| 48 | + return phantasmal(MultiTrail::calcRot, length, scale, magnitude, offsetY); |
| 49 | + } |
| 50 | + |
| 51 | + public static MultiTrail phantasmal(RotationHandler rot, int length, float scale, float magnitude, float offsetY){ |
| 52 | + int strandsAmount = 2; |
| 53 | + |
| 54 | + TrailHold[] trails = new TrailHold[strandsAmount + 2]; |
| 55 | + for(int i = 0; i < strandsAmount; i++) trails[i] = new TrailHold(Utils.with(singlePhantasmal(Mathf.round(length * 1.5f)), t -> t.trailWidth = 4.8f), 0f, 0f, 0.16f); |
| 56 | + trails[strandsAmount] = new TrailHold(singlePhantasmal(length)); |
| 57 | + trails[strandsAmount + 1] = new TrailHold(phantasmalExhaust(Mathf.round(length * 0.5f)), 0f, 1.6f, 1f); |
| 58 | + |
| 59 | + float offset = Mathf.random(Mathf.PI2 * scale); |
| 60 | + return new MultiTrail(rot, trails){ |
| 61 | + @Override |
| 62 | + public void update(float x, float y, float width){ |
| 63 | + float angle = rotation.get(this, x, y) - 90f; |
| 64 | + for(int i = 0; i < strandsAmount; i++){ |
| 65 | + Tmp.v1.trns(angle, Mathf.sin((Time.time + offset + (Mathf.PI2 * scale) * ((float)i / strandsAmount)), scale, magnitude * width), offsetY); |
| 66 | + |
| 67 | + TrailHold trail = trails[i]; |
| 68 | + trail.trail.update(x + Tmp.v1.x, y + Tmp.v1.y, width * trail.width); |
| 69 | + } |
| 70 | + |
| 71 | + for(int i = strandsAmount; i < trails.length; i++){ |
| 72 | + TrailHold trail = trails[i]; |
| 73 | + Tmp.v1.trns(angle, trail.x, trail.y); |
| 74 | + |
| 75 | + trail.trail.update(x + Tmp.v1.x, y + Tmp.v1.y, width * trail.width); |
| 76 | + } |
| 77 | + |
| 78 | + lastX = x; |
| 79 | + lastY = y; |
| 80 | + } |
| 81 | + }; |
| 82 | + } |
| 83 | + |
| 84 | + public static TexturedTrail singleSoul(int length){ |
| 85 | + return new TexturedTrail(Core.atlas.find("unity-soul-trail"), length){{ |
| 86 | + blend = Blending.additive; |
| 87 | + fadeInterp = Interp.pow5In; |
| 88 | + sideFadeInterp = Interp.pow10In; |
| 89 | + mixInterp = Interp.pow5In; |
| 90 | + gradientInterp = Interp.pow5Out; |
| 91 | + fadeColor = new Color(0.1f, 0.2f, 1f); |
| 92 | + shrink = 1f; |
| 93 | + mixAlpha = 0.8f; |
| 94 | + fadeAlpha = 0.5f; |
| 95 | + trailChance = 0f; |
| 96 | + }}; |
| 97 | + } |
| 98 | + |
| 99 | + public static MultiTrail soul(int length){ |
| 100 | + return soul(length, 6f, 2.2f); |
| 101 | + } |
| 102 | + |
| 103 | + public static MultiTrail soul(RotationHandler rot, int length){ |
| 104 | + return soul(rot, length, 6f, 2.2f); |
| 105 | + } |
| 106 | + |
| 107 | + public static MultiTrail soul(int length, float scale, float magnitude){ |
| 108 | + return soul(MultiTrail::calcRot, length, scale, magnitude); |
| 109 | + } |
| 110 | + |
| 111 | + public static MultiTrail soul(RotationHandler rot, int length, float scale, float magnitude){ |
| 112 | + int strandsAmount = 3; |
| 113 | + |
| 114 | + TrailHold[] trails = new TrailHold[strandsAmount + 1]; |
| 115 | + for(int i = 0; i < strandsAmount; i++) trails[i] = new TrailHold(Utils.with(singleSoul(Mathf.round(length * 1.5f)), t -> t.mixAlpha = 0f), 0f, 0f, 0.56f); |
| 116 | + trails[strandsAmount] = new TrailHold(singlePhantasmal(length), UnityPal.monolith); |
| 117 | + |
| 118 | + float dir = Mathf.sign(Mathf.chance(0.5f)); |
| 119 | + float offset = Mathf.random(Mathf.PI2 * scale); |
| 120 | + return new MultiTrail(rot, trails){ |
| 121 | + @Override |
| 122 | + public void update(float x, float y, float width){ |
| 123 | + float angle = rotation.get(this, x, y) - 90f; |
| 124 | + for(int i = 0; i < strandsAmount; i++){ |
| 125 | + float rad = (Time.time + offset + (Mathf.PI2 * scale) * ((float)i / strandsAmount)) * dir; |
| 126 | + float scl = Mathf.map(Mathf.sin(rad, scale, 1f), -1f, 1f, 0.2f, 1f); |
| 127 | + Tmp.v1.trns(angle, Mathf.cos(rad, scale, magnitude * width)); |
| 128 | + |
| 129 | + TrailHold trail = trails[i]; |
| 130 | + trail.trail.update(x + Tmp.v1.x, y + Tmp.v1.y, width * trail.width * scl); |
| 131 | + } |
| 132 | + |
| 133 | + TrailHold main = trails[trails.length - 1]; |
| 134 | + Tmp.v1.trns(angle, main.x, main.y); |
| 135 | + |
| 136 | + main.trail.update(x + Tmp.v1.x, y + Tmp.v1.y, width * main.width); |
| 137 | + |
| 138 | + lastX = x; |
| 139 | + lastY = y; |
| 140 | + } |
| 141 | + }; |
| 142 | + } |
| 143 | + |
| 144 | + private Trails(){ |
| 145 | + throw new AssertionError(); |
| 146 | + } |
| 147 | +} |
0 commit comments