class DamageEffect extends DamageObject { public float runTime; float lastTime; float init_time; DamageEffect(Vector3D l, float s, int t, float dmg, float time) { super(l, s, t, dmg); runTime = time; init_time = time; lastTime = millis(); } void update() { runTime -= millis() - lastTime; lastTime = millis(); } void render() { } void run() { update(); render(); collision(); } } class ShieldEffect extends DamageEffect { float init_time; ShieldEffect(Vector3D l, float s, int t, float dmg, float time) { super(l, s, t, dmg, time); init_time = time; } } class ThornShield extends ShieldEffect { float shield_rot; float thornSize; ThornShield(Vector3D l, float s, int t, float dmg, float time) { super(l, s, t, dmg, time); thornSize = 6.0f; shield_rot = 0; } void thorn(float x, float y, float rot) { pushMatrix(); translate(loc.x,loc.y); rotate(shield_rot); translate(x,y); rotate(rot); scale(0.4); beginShape(TRIANGLES); vertex(0, -thornSize*2); vertex(-thornSize, thornSize*2); vertex(thornSize, thornSize*2); endShape(); popMatrix(); } void update() { super.update(); loc = gack.loc.copy(); if (runTime <= 0) gack.dmgShield = null; } void render() { float coef = (runTime / init_time); shield_rot += PI/100 * (gack.maxspeed * 0.9f); fill(coef * 205f + 50f); thorn(0, -20, 0); thorn(0, 20, PI); thorn(20, 0, PI/2); thorn(-20, 0, (3.0 * PI)/ 2.0); thorn(15, -15, PI/4.0); thorn(15, 15, (3.0 * PI) / 4.0); thorn(-15, 15, (5.0 * PI) /4.0); thorn(-15, -15, (7.0 * PI)/ 4.0); fill(20f, 20f + coef * 190f, 20f + coef * 90f); pushMatrix(); translate(loc.x,loc.y); rotate(-shield_rot); imageMode(CENTER); PImage thunder = (PImage)spriteList.get(32); image(thunder, 0, 0); ellipse(0, 0, 20, 20); popMatrix(); } } class ThunderBall extends ShieldEffect { float shield_rot; float timeRand; float rotRand[]; ThunderBall(Vector3D l, float s, int t, float dmg, float time) { super(l, s, t, dmg, time); shield_rot = 0; timeRand = 15f; rotRand = new float[3]; rotRand[0] = random(-40, 40); rotRand[1] = random(-40, 40); rotRand[2] = random(-40, 40); } void update() { runTime -= millis() - lastTime; loc = gack.loc.copy(); if (runTime <= 0) gack.dmgShield = null; timeRand -= millis() - lastTime; if (timeRand <= 0) { rotRand[(int)random(0, 3)] = random(-40f, 40f); timeRand = 15f; } lastTime = millis(); } void deadly_ball(float rot, float coef, int rand) { stroke(255,255,145); fill(50f, 50f + coef * 42f, 50f + coef * 205f); pushMatrix(); translate(loc.x,loc.y); rotate(shield_rot); rotate(rot); translate(0, -13); imageMode(CENTER); rotate(rotRand[rand]); PImage thunder = (PImage)spriteList.get(0); image(thunder, 0, 0); ellipse(0, 0, 10, 10); popMatrix(); stroke(255); } void render() { float coef = (runTime / init_time); stroke(255); fill(50f, 50f + coef * 42f, 50f + coef * 205f); ellipse(loc.x, loc.y, 32, 32); stroke(255,255,145); fill(50f + coef * 13f, 50f + coef * 137f, 50f + coef * 189f); ellipse(loc.x, loc.y, 22, 22); shield_rot += PI/120 * (gack.maxspeed * 0.9f); deadly_ball(0, coef, 0); deadly_ball((4 * PI) / 6, coef, 1); deadly_ball((8 * PI) / 6, coef, 2); } 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.electrify(); gack.scorePoint += gack.maxspeed / 5.f; } } } } class FireRocket extends DamageEffect { FireRocket(Vector3D l, float s, int t, float dmg, float time) { super(l, s, t, dmg, time); } void update() { loc = gack.loc; runTime -= millis() - lastTime; lastTime = millis(); } void render() { fill(254, 185, 27); ellipse(loc.x, loc.y, r, r); } } class BurningArea extends DamageEffect { float timeRand; int spriteRand; BurningArea(Vector3D l, float s, int t, float dmg, float time) { super(l, s, t, dmg, time); timeRand = 100f; spriteRand = (int)random(0, 5); } void update() { runTime -= millis() - lastTime; timeRand -= millis() - lastTime; if (timeRand <= 0) { timeRand = 60f; spriteRand += 1; if (spriteRand >= 5) spriteRand = 0; } lastTime = millis(); } void render() { fill(254, 185, 27); ellipse(loc.x, loc.y, r, r); pushMatrix(); translate(loc.x,loc.y); imageMode(CENTER); image((PImage)spriteList.get(6 + spriteRand), 0, 0); popMatrix(); } }