Starsector API
Loading...
Searching...
No Matches
RiftTrailEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.util.List;
4
5import java.awt.Color;
6
7import org.lwjgl.util.vector.Vector2f;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
11import com.fs.starfarer.api.combat.CombatEngineAPI;
12import com.fs.starfarer.api.combat.MissileAPI;
13import com.fs.starfarer.api.combat.ShipAPI;
14import com.fs.starfarer.api.input.InputEventAPI;
15import com.fs.starfarer.api.util.IntervalUtil;
16import com.fs.starfarer.api.util.Misc;
17
19
20 protected IntervalUtil interval = new IntervalUtil(0.1f, 0.3f);
21
23 protected ShipAPI ship;
24 protected String loopId;
25
26
28 this.missile = missile;
29 this.loopId = loopId;
30 }
31
33 this.ship = ship;
34 this.loopId = loopId;
35 }
36
37 @Override
38 public void advance(float amount, List<InputEventAPI> events) {
39 if (Global.getCombatEngine().isPaused()) return;
40
41 if (missile != null) {
42 if (loopId != null) {
45 }
46
47 interval.advance(amount);
48 if (interval.intervalElapsed()) {
50 }
51
54 }
55 } else if (ship != null) {
56 if (loopId != null) {
59 }
60
61 interval.advance(amount);
62 if (interval.intervalElapsed()) {
64 }
65
68 }
69 }
70 }
71
72 protected Color getUndercolor() {
74 }
78 protected float getBaseParticleDuration() {
79 return 4f;
80 }
81
82 protected float getBaseParticleSize() {
83 if (missile != null) return missile.getSpec().getGlowRadius() * 0.5f;
84 return ship.getCollisionRadius();
85 }
86 protected float getCurrentBaseAlpha() {
87 if (missile != null) return missile.getCurrentBaseAlpha();
88 return 1f;
89 }
90 protected Vector2f getEntityLocation() {
91 if (missile != null) return missile.getLocation();
92 return ship.getLocation();
93 }
94 protected Vector2f getEntityVelocity() {
95 if (missile != null) return missile.getVelocity();
96 return ship.getVelocity();
97 }
98
99 public void addParticles() {
101 Color c = getDarkeningColor();
102 // subtracting the standard color looks better, makes the red a bit purplish
103 // inverting red to substract doesn't look as good for the trails
104// MissileSpecAPI spec = missile.getSpec();
105// c = spec.getExplosionColor();
106
107 Color undercolor = getUndercolor();
108
109 float b = getCurrentBaseAlpha();
110 c = Misc.scaleAlpha(c, b);
111 undercolor = Misc.scaleAlpha(undercolor, b);
112
113 float baseDuration = getBaseParticleDuration();
114 float size = 30f;
115 size = getBaseParticleSize();
116
117 Vector2f point = new Vector2f(getEntityLocation());
118 Vector2f pointOffset = new Vector2f(getEntityVelocity());
119 pointOffset.scale(0.1f);
120 Vector2f.add(point, pointOffset, point);
121
122 Vector2f vel = new Vector2f();
123
124 for (int i = 0; i < 1; i++) {
125 float dur = baseDuration + baseDuration * (float) Math.random();
126 //float nSize = size * (1f + 0.0f * (float) Math.random());
127 //float nSize = size * (0.75f + 0.5f * (float) Math.random());
128 float nSize = size;
129 Vector2f pt = Misc.getPointWithinRadius(point, nSize * 0.5f);
130 Vector2f v = Misc.getUnitVectorAtDegreeAngle((float) Math.random() * 360f);
131 v.scale(nSize + nSize * (float) Math.random() * 0.5f);
132 v.scale(0.2f);
133 Vector2f.add(vel, v, v);
134
135 float maxSpeed = nSize * 1.5f * 0.2f;
136 float minSpeed = nSize * 1f * 0.2f;
137 float overMin = v.length() - minSpeed;
138 if (overMin > 0) {
139 float durMult = 1f - overMin / (maxSpeed - minSpeed);
140 if (durMult < 0.1f) durMult = 0.1f;
141 dur *= 0.5f + 0.5f * durMult;
142 }
143 engine.addNegativeNebulaParticle(pt, v, nSize * 1f, 2f,
144 0.5f, 0f, dur, c);
145 }
146
147 float dur = baseDuration;
148 float rampUp = 0f;
149 rampUp = 0.5f;
150 c = undercolor;
151 for (int i = 0; i < 2; i++) {
152 Vector2f loc = new Vector2f(point);
153 loc = Misc.getPointWithinRadius(loc, size * 1f);
154 float s = size * 3f * (0.5f + (float) Math.random() * 0.5f);
155 engine.addNebulaParticle(loc, vel, s, 1.5f, rampUp, 0f, dur, c);
156 }
157 }
158
159}
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:49
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
RiftTrailEffect(MissileAPI missile, String loopId)
void advance(float amount, List< InputEventAPI > events)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static Color scaleAlpha(Color color, float factor)
Definition Misc.java:1309
static Vector2f getPointWithinRadius(Vector2f from, float r)
Definition Misc.java:711
void playLoop(String id, Object playingEntity, float pitch, float volume, Vector2f loc, Vector2f vel)
void removePlugin(EveryFrameCombatPlugin plugin)
boolean isEntityInPlay(CombatEntityAPI entity)
void addNegativeNebulaParticle(Vector2f loc, Vector2f vel, float size, float endSizeMult, float rampUpFraction, float fullBrightnessFraction, float totalDuration, Color color)
void addNebulaParticle(Vector2f loc, Vector2f vel, float size, float endSizeMult, float rampUpFraction, float fullBrightnessFraction, float totalDuration, Color color)