26public class CryoblasterEffect extends BaseCombatLayeredRenderingPlugin implements OnFireEffectPlugin,
32 public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point,
boolean shieldHit, ApplyDamageResultAPI damageResult, CombatEngineAPI engine) {
33 Color color = projectile.getProjectileSpec().getFringeColor();
34 color = Misc.setAlpha(color, 100);
36 Vector2f vel =
new Vector2f();
37 if (target instanceof ShipAPI) {
38 vel.set(target.getVelocity());
41 float sizeMult = Misc.getHitGlowSize(100f, projectile.getDamage().getBaseDamage(), damageResult) / 100f;
43 for (
int i = 0; i < 7; i++) {
45 float size = 40f * (0.75f + (float) Math.random() * 0.5f);
50 Color c = Misc.scaleAlpha(color, projectile.getBrightness());
51 engine.addNebulaParticle(point, vel, size, 5f + 3f * sizeMult,
52 rampUp, 0f, dur, c,
true);
56 public void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine) {
58 CombatEntityAPI e = engine.addLayeredRenderingPlugin(trail);
59 e.getLocation().set(projectile.getLocation());
63 public static class ParticleData {
64 public SpriteAPI sprite;
65 public Vector2f offset =
new Vector2f();
66 public Vector2f vel =
new Vector2f();
67 public float scale = 1f;
68 public DamagingProjectileAPI proj;
69 public float scaleIncreaseRate = 1f;
70 public float turnDir = 1f;
71 public float angle = 1f;
74 public Vector2f origVel;
75 public FaderUtil fader;
76 public Vector2f dirVelChange;
78 public ParticleData(DamagingProjectileAPI proj) {
82 float i = Misc.random.nextInt(4);
83 float j = Misc.random.nextInt(4);
84 sprite.setTexWidth(0.25f);
85 sprite.setTexHeight(0.25f);
86 sprite.setTexX(i * 0.25f);
87 sprite.setTexY(j * 0.25f);
88 sprite.setAdditiveBlend();
90 angle = (float) Math.random() * 360f;
92 maxDur = proj.getWeapon().getRange() / proj.getWeapon().getProjectileSpeed();
93 scaleIncreaseRate = 2.5f / maxDur;
96 turnDir = Math.signum((
float) Math.random() - 0.5f) * 30f * (
float) Math.random();
99 float driftDir = proj.getFacing() + 180f + ((float) Math.random() * 30f - 15f);
100 vel = Misc.getUnitVectorAtDegreeAngle(driftDir);
102 vel.scale(80f / maxDur * (0f + (
float) Math.random() * 3f));
104 origVel =
new Vector2f(vel);
105 dirVelChange = Misc.getUnitVectorAtDegreeAngle(proj.getFacing() + 180f);
109 fader =
new FaderUtil(0f, 0.25f, 0.05f);
113 public void advance(
float amount) {
114 scale += scaleIncreaseRate * amount;
121 offset.x += vel.x * amount;
122 offset.y += vel.y * amount;
124 if (!proj.didDamage()) {
125 float speed = vel.length();
127 float speedIncrease = proj.getMoveSpeed() / maxDur * 0.5f;
128 Vector2f dir =
new Vector2f(dirVelChange);
129 dir.scale(speedIncrease * amount);
130 Vector2f.add(vel, dir, vel);
134 angle += turnDir * amount;
136 fader.advance(amount);
140 protected List<ParticleData>
particles =
new ArrayList<ParticleData>();
142 protected DamagingProjectileAPI
proj;
152 for (
int i = 0; i < num; i++) {
159 p.offset = Misc.getPointWithinRadius(p.offset, 20f);
169 protected EnumSet<CombatEngineLayers>
layers = EnumSet.of(CombatEngineLayers.ABOVE_SHIPS_AND_MISSILES_LAYER);
175 public void init(CombatEntityAPI entity) {
183 entity.getLocation().set(
proj.getLocation());
188 max = Math.max(max, p.offset.lengthSquared());
193 if (
proj.getElapsed() < 0.1f) {
197 projLoc.x += projVel.x * amount;
198 projLoc.y += projVel.y * amount;
200 if (
proj.didDamage()) {
203 Vector2f.add(p.vel,
projVel, p.vel);
209 float dist = p.offset.length();
210 p.vel.scale(Math.min(1f, dist / 100f));
221 public void render(CombatEngineLayers layer, ViewportAPI viewport) {
227 Color color =
proj.getProjectileSpec().getFringeColor();
228 color = Misc.setAlpha(color, 30);
229 float b =
proj.getBrightness();
230 b *= viewport.getAlphaMult();
241 Vector2f loc =
new Vector2f(x + p.offset.x, y + p.offset.y);
243 float alphaMult = 1f;
248 p.sprite.setAngle(p.angle);
249 p.sprite.setSize(size, size);
250 p.sprite.setAlphaMult(b * a * p.fader.getBrightness());
251 p.sprite.setColor(color);
252 p.sprite.renderAtCenter(loc.x, loc.y);