PVector calcAttraction(PVector pos) { PVector dir = PVector.sub(player_pos, pos); float amt = PULL_MULT / (dir.mag() + PULL_DENOM_ADD); dir.normalize(); dir.mult(amt); return dir; } class ScoreParticle extends Particle { int points; ScoreParticle(int p, PVector pos) { super(pos, new PVector(0, 0), 360); points = p; } void draw() { textFont(font, 8); fill(255, life); if(points == combo) { textFont(font, 16); fill(255, life*2); } textAlign(LEFT, TOP); text(""+points, (int)pos.x - 4, (int)pos.y - 4); } } class GravityObject extends GameObject { PVector vel; float drag; GravityObject() { pos = randomVector(450); pos.x += width/2; pos.y += width/2; vel = new PVector(0, 0); drag = WORLD_DRAG; } void tick() { if(shock_radius < SHOCK_DESTROY_RADIUS) { if(inRadius(pos, shock_pos, shock_radius)) { //TODO poof //if(!muted) pointSound.trigger(); removal_flag = true; combo++; particles.add(new ScoreParticle(combo, pos)); score += combo; } } vel.mult(drag); if(!gameover) vel.add(PVector.mult(calcAttraction(pos), GRAVITY_MULT)); vel.add(randomVector(JIGGLE)); pos.add(vel); if(shock_radius < SHOCK_MAX) { if(!inRadius(pos, shock_pos, shock_radius) && inRadius(pos, shock_pos, shock_radius + SHOCK_GROWTH)) { PVector away = PVector.sub(player_pos, pos); away.normalize(); //vel.mult(0.5); vel.add(PVector.mult(away, -1)); } } } void draw() { noStroke(); fill(random(255), 128+random(127), 255); ellipse(pos.x, pos.y, 5, 5); } } class Target extends GravityObject { void tick() { super.tick(); if(!gameover && inRadius(pos, player_pos, PLAYER_RADIUS)) { removal_flag = true; damage_timer += 128; if(damage_timer > 256) { damage_timer = 256; gameover = true; } //TODO penalty stuff if(!muted) hitSound.trigger(); } } } class Bomb extends GravityObject { Bomb() { super(); drag = BOMB_DRAG; } void tick() { super.tick(); if(!gameover && inRadius(pos, player_pos, PLAYER_RADIUS)) { shock_pos = new PVector(player_pos.x, player_pos.y); shock_radius = 0; removal_flag = true; combo = 0; //TODO explosion stuff if(!muted) bombSound.trigger(); } } void draw() { noStroke(); fill(255, random(255), random(128)); ellipse(pos.x, pos.y, 5, 5); } } class BGDot extends GameObject { PVector home; PVector vel; BGDot() { float x = random(width * 1.5) - width*0.25; float y = random(height * 1.5) - height * 0.25; pos = new PVector(x, y); home = new PVector(x, y); vel = new PVector(0, 0); } void tick() { vel.mult(BG_DAMP_MULT); vel.add(PVector.mult(PVector.sub(home, pos), BG_SPRING_STR)); if(!gameover) vel.add(PVector.mult(calcAttraction(pos), BG_ATTRACT_MULT)); if(shock_radius < SHOCK_MAX) if(!inRadius(pos, shock_pos, shock_radius) && inRadius(pos, shock_pos, shock_radius + SHOCK_GROWTH)) { PVector away = PVector.sub(player_pos, pos); away.normalize(); vel.mult(0.5); vel.add(PVector.mult(away, -2)); } pos.add(vel); } void draw() { float v = vel.mag(); strokeWeight(1); fill(v*200, v*100, v*400+48); noStroke(); rect(pos.x-v*0.5-1, pos.y-v*0.5-1, v*1+2, v*1+2); stroke(v*200, v*100, v*400+48); // point(pos.x, pos.y); //line(pos.x, pos.y, (home.x + pos.x) * 0.5, (home.y + pos.y) * 0.5); ellipseMode(RADIUS); fill(255, 0, 255); //ellipse((home.x + pos.x) * 0.5, (home.y + pos.y) * 0.5, 1.5, 1.5); //ellipse(pos.x, pos.y, 1.5, 1.5); } }