/* Type : 0 Gack 1 Boid 2 Bullet 0 normal 1 bigger 2 huge 3 laser 4 wave 3 Ennemy Bullet 4 Object 5 Effect 6 Boid spawn */ Flock flock; Gack gack; ArrayList dmgObject; ArrayList effectObject; ArrayList boidPop; ArrayList floatingItems; ArrayList dmgEffect; ArrayList spriteList; ArrayList bigSplash; ArrayList energySprite; int keyMovement[] = new int[2]; int load; PImage bg; void setup() { load = 0; size(640, 360); colorMode(RGB,255,255,255,100); //PFont font = loadFont("Andalus-15.vlw"); PFont font = loadFont("Consolas-Bold-12.vlw"); textFont(font); spriteList = new ArrayList(); energySprite = new ArrayList(); flock = new Flock(); dmgObject = new ArrayList(); effectObject = new ArrayList(); boidPop = new ArrayList(); floatingItems = new ArrayList(); dmgEffect = new ArrayList(); bigSplash = new ArrayList(); spriteList.add(loadImage("thunderball.png")); // 0 spriteList.add(loadImage("sparklingboid.png")); // 1 spriteList.add(loadImage("explodeice.png")); // 2 spriteList.add(loadImage("frozenboid.png")); // 3 spriteList.add(loadImage("rocket1.png")); // 4 spriteList.add(loadImage("rocket2.png")); // 5 spriteList.add(loadImage("burn1.png")); // 6 spriteList.add(loadImage("burn2.png")); // 7 spriteList.add(loadImage("burn3.png")); // 8 spriteList.add(loadImage("burn4.png")); // 9 spriteList.add(loadImage("burn5.png")); // 10 for (int i = 1; i <= 10; i++) spriteList.add(loadImage("psyload" + i + ".png")); // 11-20 for (int i = 1; i <= 10; i++) spriteList.add(loadImage("psyfire" + i + ".png")); // 21-29 spriteList.add(loadImage("explodepsy.png")); spriteList.add(loadImage("thornball.png")); spriteList.add(loadImage("WindBlast.png")); // 33 energySprite.add(loadImage("thunderenergy.png")); energySprite.add(loadImage("iceenergy.png")); energySprite.add(loadImage("normalenergy.png")); energySprite.add(loadImage("fireenergy.png")); energySprite.add(loadImage("psyenergy.png")); energySprite.add(loadImage("windenergy.png")); bg = loadImage("bg.png"); // Add an initial set of boids into the system for (int i = 0; i < 50; i++) { flock.addBoid(new Boid(new Vector3D(random(0, width), random(0, height)), random(1.5f, 5.f),0.03f)); } gack = new Gack(new Vector3D(width/2,height/2), 3.0f); smooth(); load = 1; } class Entity { Vector3D loc; float r; int type; float life; Entity(Vector3D l, float s, int t) { life = 1; loc = l.copy(); r = s; type = t; } void run() { } }; class Gack extends Entity { Vector3D vel; Vector3D acc; Vector3D dec; float scorePoint; float maxspeed; float lastTime; int currentTimer; float nextAtk; PImage sprite; ShieldEffect dmgShield; // DamageObject defShield; DamageObject rocketReactor; float nextRocket; float rocketTime; boolean isRocket; DamageObject starCrusher; // MINE IS BIGGER Gack(Vector3D l, float ms) { super(l, 6, 0); currentTimer = 0; lastTime = millis(); life = 42; sprite = loadImage("gack2.png"); scorePoint = 0; acc = new Vector3D(0,0); vel = new Vector3D(0,0); dec = new Vector3D(0,0); maxspeed = ms; dmgShield = null; // defShield = null; rocketReactor = null; isRocket = false; starCrusher = new Bullet(new Vector3D(0, 0), new Vector3D(0, 0), 4.0f, 2, 1.5f); nextAtk = starCrusher.atkspeed(); nextRocket = 0; //starCrusher = new BigBullet(new Vector3D(0, 0), new Vector3D(0, 0), 2.0f, 2, 1.0f); //starCrusher = new HugeBullet(new Vector3D(0, 0), new Vector3D(0, 0), 2.0f, 2, 1.0f); } void rocketLaunch() { isRocket = true; nextRocket = 500.f; rocketTime = 300.f; maxspeed = 15.3f; dmgEffect.add(new BurningArea(gack.loc, 24.f, 3, 10f, 800.f)); } void piou() { nextAtk -= millis() - lastTime; if (nextAtk <= 0) { //println(millis() - lastTime + " > " + starCrusher.atkspeed() ); starCrusher.fire(gack.loc, new Vector3D(mouseX, mouseY), /*gack.maxspeed + 1*/2.0f, 2, 1.0f); nextAtk = starCrusher.atkspeed(); //dmgObject.add(new Bullet(gack.loc, new Vector3D(mouseX, mouseY), /*gack.maxspeed + 1*/2.0f, 2, 1.0f)); } } void takeDmg(float dmg) { if (life > 0) { life -= dmg; if (life <= 0) effectObject.add(new GackExplode(loc, 3000.f, 5, 1500.f)); } } void run() { update(); borders(); if (life > 0) { if (dmgShield != null) dmgShield.run(); render(); } lifeScore(); } void lifeScore() { float calc = life / 42f; float redC = 155 + 100 * (1 - calc); float greenC = 155 + 100 * calc; fill(redC, greenC, 0); stroke(0); text("Life : ", 20, 30); rect(68, 20, life * 3, 10); text("Score : " + (int)scorePoint, width - 200, height - 30); int secs = currentTimer / 1000; int mins = secs / 60; int mils = currentTimer - (secs * 1000); secs = secs - (mins * 60); String secZero = ""; String minZero = ""; String milsZero = ""; if (secs < 10) secZero = "0"; if (mins < 10) minZero = "0"; if (mils < 10) milsZero = "00"; else if (mils < 100) milsZero = "0"; text("Time : " + minZero + mins + "\"" + secZero + secs + "\"" + milsZero + mils, width - 200, 30); text("Shield : ", 6, height - 20); float shieldLife = 0; if (dmgShield != null) { shieldLife = dmgShield.runTime / dmgShield.init_time; rect(68, height - 30, shieldLife * 126f, 10); } } void baseMovement() { vel.add(acc); vel.limit(maxspeed); dec.mult(0.9f); vel.add(dec); loc.add(vel); acc.setXYZ(0,0,0); vel.mult(0.98f); } void rocketMovement() { vel.add(acc); vel.mult(100.f); vel.limit(maxspeed); loc.add(vel); } void update() { if (life > 0) currentTimer += millis() - lastTime; if (isRocket == false) baseMovement(); else { nextRocket -= millis() - lastTime; if (nextRocket <= 0) { rocketTime -= millis() - lastTime; dmgEffect.add(new BurningArea(gack.loc, 20.f, 3, 1.5f, 3000.f)); if (rocketTime > 0) rocketMovement(); nextRocket = 0; if (rocketTime <= 0) { isRocket = false; maxspeed = 3.0f; } } } lastTime = millis(); } void borders() { if (loc.x < -r) loc.x = width+r; if (loc.y < -r) loc.y = height+r; if (loc.x > width+r) loc.x = -r; if (loc.y > height+r) loc.y = -r; } void render() { float theta = vel.heading2D() + radians(90); fill(200); stroke(255); pushMatrix(); translate(loc.x,loc.y); rotate(theta); if (isRocket == true && nextRocket <= 0 && rocketTime > 0) { imageMode(CENTER); image((PImage)spriteList.get(4 + (int)random(0, 2)), 0, 0); } imageMode(CORNER); image(sprite, - 13f, -12); // ellipse(0, 0, r*2, r*2); popMatrix(); } }; void keyReleased() { if (key == 'z' || key == 'w' || key == 's') keyMovement[1] = 0; if (key == 'q' || key == 'a' || key == 'd') keyMovement[0] = 0; keyMovement(); if (key == ' ') { gack.dec = gack.vel.copy(); gack.maxspeed = 3.0f; } } void keyMovement() { if (keyPressed) { if (key == 'z' || key == 'w') { keyMovement[1] = -1; } if (key == 'q' || key == 'a') { keyMovement[0] = -1; } if (key == 's') { keyMovement[1] = 1; } if (key == 'd') { keyMovement[0] = 1; } if (key == ' ') gack.maxspeed = 15.0f; } } void restartGame() { flock = new Flock(); dmgObject = new ArrayList(); effectObject = new ArrayList(); boidPop = new ArrayList(); floatingItems = new ArrayList(); dmgEffect = new ArrayList(); bigSplash = new ArrayList(); for (int i = 0; i < 50; i++) { flock.addBoid(new Boid(new Vector3D(random(0, width), random(0, height)), random(1.5f, 5.f),0.03f)); } gack = new Gack(new Vector3D(width/2,height/2), 3.0f); smooth(); load = 1; } void draw() { background(50); imageMode(CORNER); image(bg, 0, 0); if (keyPressed) if (key == 'r') { load = 0; thread("restartGame"); } if (load == 1) { if (gack.life > 0) { for (int i = 0; i < 2; ++i) keyMovement(); Vector3D vel = new Vector3D(keyMovement[0] * 1.0f, keyMovement[1] * 1.0f); effectObject.add(new ReactorParticule(gack.loc, gack.maxspeed * 1.5f, 5, 400.f, vel)); gack.acc.add(vel); } flock.run(); } } /* void mouseReleased() { if (mouseButton == LEFT) { } else if (mouseButton == RIGHT) { gack.dec = gack.vel.copy(); gack.maxspeed = 3.0f; } } */