class Sphere { float radius; PVector pos; color c; color base_c; int hp; Sphere(PVector p) { radius = DEFAULT_SPHERE_RADIUS; c = color(160, 255, 0); pos = new PVector(p.x, p.y); hp = SPHERE_HP; } Sphere(float x, float y) { this(new PVector(x, y)); } void tick() { if(pos.x < 0) pos.x = 0; if(pos.y < 0) pos.y = 0; if(pos.x > width) pos.x = width; if(pos.y > height) pos.y = height; } void draw() { color faded = blendColors(color(190), c, hp*1.0/SPHERE_HP); stroke(c); fill(blendColors(color(0),faded, 0.4)); ellipse(pos.x, pos.y, radius, radius); noStroke(); fill(blendColors(color(0),faded, 0.35)); ellipse(pos.x - radius/8, pos.y - radius/8, radius*3/4, radius*3/4); fill(blendColors(blendColors(color(0),faded, 0.35), color(255), 0.2)); ellipse(pos.x - radius/3, pos.y - radius/3, radius/3, radius/3); } void addBlast(float angle, float speed) { PVector svel = new PVector(cos(angle)*speed, sin(angle)*speed); shrapnel.add(new Blast(pos, svel, c, radius)); } void die() { int bits = 12; for(int i = 0; i < bits; i++) addBlast(TWO_PI/bits*i, radius/BLAST_LIFE * 2); } } class YSphere extends Sphere { YSphere(PVector p) { super(p); c = color(0, 160, 255); } YSphere(float x, float y) { super(x, y); c = color(0, 160, 255); } void draw() { super.draw(); stroke(c); line(pos.x, pos.y-radius, pos.x, pos.y+radius); } void die() { int bits = 15; for(int i = 0; i < bits; i++) addBlast(HALF_PI, (bits/2 - i)*1.5); } } class XSphere extends Sphere { XSphere(PVector p) { super(p); c = color(255, 160, 0); } XSphere(float x, float y) { super(x, y); c = color(255, 160, 0); } void draw() { super.draw(); stroke(c); line(pos.x-radius, pos.y, pos.x+radius, pos.y); } void die() { int bits = 15; for(int i = 0; i < bits; i++) addBlast(0, (bits/2 - i)*1.5); } } class CrossSphere extends Sphere { float angle; CrossSphere(float x, float y) { super(x, y); c = color(160, 0, 255); hp = 1; } void draw() { super.draw(); stroke(c); pushMatrix(); translate(pos.x, pos.y); line(cos(angle)*radius, sin(angle)*radius, -cos(angle)*radius, -sin(angle)*radius); line(cos(angle+HALF_PI)*radius, sin(angle+HALF_PI)*radius, -cos(angle+HALF_PI)*radius, -sin(angle+HALF_PI)*radius); popMatrix(); } void tick() { super.tick(); angle += SPHERE_SPIN_RATE; } void die() { int bits = 15; for(int i = 0; i < bits; i++) { addBlast(angle, (bits/2 - i)*1.5); addBlast(angle + HALF_PI, (bits/2 - i)*1.5); } } } class RSphere extends Sphere { RSphere(PVector p) { super(p); c = color(255, 0, 160); } RSphere(float x, float y) { super(x, y); c = color(255, 0, 16); } void draw() { super.draw(); stroke(c); noFill(); ellipse(pos.x, pos.y, radius *1/2, radius * 1/2); } void die() { int bits = 16; for(int i = 0; i < bits; i++) addBlast(TWO_PI/bits*i, 5); } } class Blast extends Particle { color c; float max_radius; float radius; Blast(PVector p, PVector v, color col, float r) { super(p, v, BLAST_LIFE); max_radius = r * 1.5; c = col; } void tick() { super.tick(); radius = max_radius * life / maxlife; if(player_alive && inRadius(player_pos, pos, radius)) { player_alive = false; death_countdown = DEATH_DURATION; if(!muted) dieSound.trigger(); } Iterator si = spheres.iterator(); while(si.hasNext()) { Sphere s = (Sphere) si.next(); if(inRadius(s.pos, pos, s.radius + radius)) { s.hp = 0; //life = 0; //TODO hit sound break; } } } void draw() { noStroke(); fill(blendColors(c, color(255), 1.0*life/maxlife)); ellipse(pos.x, pos.y, radius, radius); } } class Shot { PVector pos; float angle; Shot(PVector p, float a) { pos = new PVector(p.x, p.y); angle = a; } void tick() { pos.x += cos(angle)*SHOT_SPEED; pos.y += sin(angle)*SHOT_SPEED; } boolean out() { if(pos.x < 0) return true; if(pos.x > width) return true; if(pos.y < 0) return true; if(pos.y > height) return true; return false; } void draw() { fill(255); stroke(255, 255, 0); strokeWeight(1); pushMatrix(); translate(pos.x, pos.y); beginShape(); vertex(cos(angle)*10, sin(angle)*10); vertex(cos(angle+HALF_PI)*2, sin(angle+HALF_PI)*2); vertex(cos(angle+PI)*10, sin(angle+PI)*10); vertex(cos(angle-HALF_PI)*2, sin(angle-HALF_PI)*2); endShape(CLOSE); popMatrix(); } }