class EffectObject extends Entity { public float runTime; float lastTime; EffectObject(Vector3D l, float s, int t, float time) { super(l, s, t); runTime = time; lastTime = millis(); } void run() { update(); render(); } void update() { runTime -= millis() - lastTime; lastTime = millis(); } void render() { } } class GackExplode extends EffectObject { float init_time; GackExplode(Vector3D l, float s, int t, float time) { super(l, s, t, time); init_time = time; } void render() { stroke(125); pushMatrix(); translate(loc.x,loc.y); float coef = 1 - (runTime / init_time); fill(40 + (int)(160 * (runTime / init_time))); ellipse(0, 0, gack.r + r * coef, gack.r + r * coef); popMatrix(); } } class FreezingBoid extends EffectObject { Boid boid; float rotRand; FreezingBoid(Vector3D l, int s, int t, float time, Boid b) { super(l, s, t, time); rotRand = random(-40, 40); boid = b; } void update() { if (boid == null || boid.life <= 0) runTime = 0; } void render() { pushMatrix(); translate(loc.x,loc.y); imageMode(CENTER); rotate(rotRand); PImage ice = (PImage)spriteList.get(3); image(ice, 0, 0); popMatrix(); } } class SparklingBoid extends EffectObject { float damage; Boid boid; float randTime; float rotRand; SparklingBoid(Vector3D l, int s, int t, float time, float dmg, Boid b) { super(l, s, t, time); damage = dmg; boid = b; randTime = 40f; } void run() { update(); render(); collision(); } void update() { runTime -= millis() - lastTime; randTime -= millis() - lastTime; if (randTime <= 0) { rotRand = random(-40, 40); randTime = 40f; } if (runTime <= 0) { boid.life -= damage; gack.scorePoint += gack.maxspeed; } lastTime = millis(); } void render() { pushMatrix(); translate(loc.x,loc.y); imageMode(CENTER); rotate(rotRand); PImage thunder = (PImage)spriteList.get(1); image(thunder, 0, 0); popMatrix(); } void collision() { for (int i = flock.boids.size() - 1; i >= 0; i--) { Boid other = (Boid) flock.boids.get(i); float d = loc.distance(loc,other.loc); if (d >= 0 && d <= r && other.stuckingEffect == null) { other.elecChain(); } } } } class PsyExplode extends EffectObject { float firstEffect; float duration; float randRot; float randTime; float scaleSize; PsyExplode(Vector3D l, float s, int t, float time) { super(l, s, t, time); firstEffect = 300f; runTime = time; randRot = 35f; randRot = random(-40, 40); scaleSize = 0; } void run() { collision(); render(); } void render() { pushMatrix(); translate(loc.x,loc.y); imageMode(CENTER); randTime -= millis() - lastTime; if (randTime <= 0) { randRot = 35f; randRot = random(-40, 40); } if (firstEffect > 0) { firstEffect -= millis() - lastTime; scaleSize = 1f - (firstEffect / 300f); scale(scaleSize); } else { runTime -= millis() - lastTime; } rotate(randRot); PImage ice = (PImage)spriteList.get(31); image(ice, 0, 0); popMatrix(); lastTime = millis(); } void collision() { for (int i = flock.boids.size() - 1; i >= 0; i--) { Boid other = (Boid) flock.boids.get(i); float d = loc.distance(loc,other.loc); if (d >= 0 && d <= r * scaleSize) { other.life -= 10; effectObject.add(new BulletImpact(new Vector3D(other.loc.x, other.loc.y), 4, 5, 100.0f)); gack.scorePoint += gack.maxspeed / 5.f; } } } } class IceExplode extends EffectObject { float firstEffect; float duration; float randRot; float scaleSize; IceExplode(Vector3D l, float s, int t, float time) { super(l, s, t, time); firstEffect = 200f; duration = 2500f; runTime = time; randRot = random(-40, 40); scaleSize = 0; } void run() { render(); } void render() { pushMatrix(); translate(loc.x,loc.y); imageMode(CENTER); if (firstEffect > 0) { firstEffect -= millis() - lastTime; scaleSize = 1f - (firstEffect / 200f); scale(scaleSize); collision(); } else if (duration > 0) { duration -= millis() - lastTime; } else { runTime -= millis() - lastTime; scaleSize = runTime / 400f; scale(scaleSize); } rotate(randRot); PImage ice = (PImage)spriteList.get(2); image(ice, 0, 0); popMatrix(); lastTime = millis(); } void collision() { for (int i = flock.boids.size() - 1; i >= 0; i--) { Boid other = (Boid) flock.boids.get(i); float d = loc.distance(loc,other.loc); if (d >= 0 && d <= r * scaleSize) other.freeze(); } } } class ReactorParticule extends EffectObject { float init_time; Vector3D dir; ReactorParticule(Vector3D l, float s, int t, float time, Vector3D vel) { super(l, s, t, time); dir = vel.copy(); dir.normalize(); loc.sub(dir); init_time = time; } void render() { float theta = gack.vel.heading2D() + radians(90); pushMatrix(); translate(loc.x,loc.y); float coef = 1 - (runTime / init_time); fill(50); stroke(125); rotate(theta); ellipse(0, 0, r * coef, 4); popMatrix(); } } class BulletImpact extends EffectObject { BulletImpact(Vector3D l, int s, int t, float time) { super(l, s, t, time); } void render() { fill(255, 255, 0); pushMatrix(); translate(loc.x,loc.y); ellipse(0, 0, r, r); popMatrix(); } } class BoidPop extends EffectObject { float init_r; float init_time; BoidPop(Vector3D l, int s, int t, float time) { super(l, s, t, time); init_r = r; init_time = runTime; } void update() { super.update(); r = init_r * (runTime / init_time); } void render() { fill(20); stroke(20); pushMatrix(); translate(loc.x,loc.y); ellipse(0, 0, r, r); popMatrix(); } } class BoidDie extends EffectObject { float init_time; BoidDie(Vector3D l, int s, int t, float time) { super(l, s, t, time); init_time = time; } void render() { float coef = (1.0f - (runTime / init_time)); float redC = 75f * coef; float greenC = 200f * coef; fill(125 + redC, greenC, 0); pushMatrix(); int a = 150 + (int)(105f * (runTime / init_time)); alpha(a); translate(loc.x,loc.y); ellipse(0, 0, 2f + r * coef, 2f + r * coef); popMatrix(); } }