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.awt.Color;
4import java.util.List;
5
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
10import com.fs.starfarer.api.combat.CombatEngineAPI;
11import com.fs.starfarer.api.combat.MissileAPI;
12import com.fs.starfarer.api.input.InputEventAPI;
13import com.fs.starfarer.api.util.IntervalUtil;
14import com.fs.starfarer.api.util.Misc;
15
16public class RiftTrailEffect extends BaseEveryFrameCombatPlugin {
17
18 protected IntervalUtil interval = new IntervalUtil(0.1f, 0.3f);
19
20 protected MissileAPI missile;
21 protected String loopId;
22
23
24 public RiftTrailEffect(MissileAPI missile, String loopId) {
25 this.missile = missile;
26 this.loopId = loopId;
27 }
28
29 @Override
30 public void advance(float amount, List<InputEventAPI> events) {
31 if (Global.getCombatEngine().isPaused()) return;
32
33 if (loopId != null) {
34 Global.getSoundPlayer().playLoop(loopId, missile, 1f, missile.getBrightness(),
35 missile.getLocation(), missile.getVelocity());
36 }
37
38 interval.advance(amount);
39 if (interval.intervalElapsed()) {
41 }
42
43 if (missile.isExpired() || missile.didDamage() || !Global.getCombatEngine().isEntityInPlay(missile)) {
44 Global.getCombatEngine().removePlugin(this);
45 }
46 }
47
48
49 public void addParticles() {
50 CombatEngineAPI engine = Global.getCombatEngine();
52 // subtracting the standard color looks better, makes the red a bit purplish
53 // inverting red to substract doesn't look as good for the trails
54// MissileSpecAPI spec = missile.getSpec();
55// c = spec.getExplosionColor();
56
57 Color undercolor = RiftCascadeEffect.EXPLOSION_UNDERCOLOR;
58
59 float b = missile.getCurrentBaseAlpha();
60 c = Misc.scaleAlpha(c, b);
61 undercolor = Misc.scaleAlpha(undercolor, b);
62
63 float baseDuration = 4f;
64 float size = 30f;
65 size = missile.getSpec().getGlowRadius() * 0.5f;
66
67 Vector2f point = new Vector2f(missile.getLocation());
68 Vector2f pointOffset = new Vector2f(missile.getVelocity());
69 pointOffset.scale(0.1f);
70 Vector2f.add(point, pointOffset, point);
71
72 Vector2f vel = new Vector2f();
73
74 for (int i = 0; i < 1; i++) {
75 float dur = baseDuration + baseDuration * (float) Math.random();
76 //float nSize = size * (1f + 0.0f * (float) Math.random());
77 //float nSize = size * (0.75f + 0.5f * (float) Math.random());
78 float nSize = size;
79 Vector2f pt = Misc.getPointWithinRadius(point, nSize * 0.5f);
80 Vector2f v = Misc.getUnitVectorAtDegreeAngle((float) Math.random() * 360f);
81 v.scale(nSize + nSize * (float) Math.random() * 0.5f);
82 v.scale(0.2f);
83 Vector2f.add(vel, v, v);
84
85 float maxSpeed = nSize * 1.5f * 0.2f;
86 float minSpeed = nSize * 1f * 0.2f;
87 float overMin = v.length() - minSpeed;
88 if (overMin > 0) {
89 float durMult = 1f - overMin / (maxSpeed - minSpeed);
90 if (durMult < 0.1f) durMult = 0.1f;
91 dur *= 0.5f + 0.5f * durMult;
92 }
93 engine.addNegativeNebulaParticle(pt, v, nSize * 1f, 2f,
94 0.5f, 0f, dur, c);
95 }
96
97 float dur = baseDuration;
98 float rampUp = 0f;
99 rampUp = 0.5f;
100 c = undercolor;
101 for (int i = 0; i < 2; i++) {
102 Vector2f loc = new Vector2f(point);
103 loc = Misc.getPointWithinRadius(loc, size * 1f);
104 float s = size * 3f * (0.5f + (float) Math.random() * 0.5f);
105 engine.addNebulaParticle(loc, vel, s, 1.5f, rampUp, 0f, dur, c);
106 }
107 }
108
109}
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:43
static CombatEngineAPI getCombatEngine()
Definition Global.java:63
RiftTrailEffect(MissileAPI missile, String loopId)
void advance(float amount, List< InputEventAPI > events)
void playLoop(String id, Object playingEntity, float pitch, float volume, Vector2f loc, Vector2f vel)