class Bubble {
float x, y=500, r, vx, vy, forBounce;
color c;
boolean canHurt = true;
Bubble() {
if(waveNum < 5)
r = 1+random(2);
}
void resetVars() {
r += random(1+3*meR*waveNum/100) + meR*waveNum/75+waveNum/20;
x = r + random(width+1-2*r);
y = -2*r;
vx = 0;
vy = (float)(Math.random()*7);
c = color(colorBank[(int)random(colorBank.length)],190);
forBounce = sqrt(vx*vx + vy*vy);
canHurt = true;
}
void moveMe() {
y += vy-grav/2;
vy += grav;
x+=vx;
if (y > height+2*r && ((int)random(20)) == 0)
resetVars();
}
void drawMe() {
fill(c);
ellipse(x, y, r*2, r*2);
}
}
PFont f;
PImage b;
PImage main;
void setup() {
b = loadImage("instructions.jpg");
main = loadImage("mainMenu.jpg");
size(500, 600);
frameRate(30);
smooth();
for (int i = 0; i < myB.length; i++)
myB[i] = new Bubble();
for (int i = 0; i < myP.length; i++)
myP[i] = new Popper();
stroke(255);
f = loadFont("Purisa-48.vlw");
}
int myPN = 0;
Popper[] myP = new Popper[100];
color[] colorBank = {
#53FE56, #C4FE53, #FBFF3C, #FFA647, #FF79E2, #CD71FF, #71FFF7
};
float grav = .07;
float meX = -100, meY = -100, meVX, meVY, meR = 10, meV = 8;
int health = 3;
float meOX, meOY;
color meC = 128;
int bubbleNum = 70;
Bubble[] myB = new Bubble[bubbleNum];
//Keys
int rr, ll, uu, dd, space;
//The amount of random idk that the bubble grows
float sizeGrower = .05;
void draw() {
background(#2DC1E0);
if (menu == 0) {
mainMenu();
}
else if (menu == 1) {
if (meR > 110 || oneWaveAdvance == 0) { //changes wave when radius is > 100
nextWave();
}
else {
moveAndDrawMe();
startsBubbleSuck();
//popper
for (int i = 0; i < myP.length; i++)
myP[i].moveAndDraw();
meOX = meX;
meOY = meY;
}
}
else if (menu == 2) {
image(b, 0, 0);
fill(0);
textFont(f, 30);
text("Play!", (width-width/3.4), height/6.5,30);
noFill();
rect((width-width/2.5)/1.05, height/10, width/2.5, height/14);
if (space == 1 || mouseX - (width-width/2.5)/1.05 < width/2.5 && (width-width/2.5)/1.05 + width/2.5 - mouseX < width/2.5 && mouseY - height/10 < height/14 && height/10 +height/14 - mouseY < height/14 && mousePressed) {
menu = 1;
fill(#FFC831);
rect((width-width/2.5)/1.05, height/10, width/2.5, height/14);
restart();
}
}
}
void moveAndDrawMe() {
//kills me
if (health <= 0)
menu = 0;
//moves me
if (uu == 1)
meY -= meV;
if (dd == 1)
meY += meV;
if (rr == 1)
meX += meV;
if (ll == 1)
meX -= meV;
//keeps me in the boundries
if (meX - meR <= 0) meX = meR;
else if (meX + meR >= width) meX = width - meR;
if (meY - meR <= 0) meY = meR;
else if (meY + meR >= height) meY = height - meR;
//draws me
fill(255/3*health);
ellipse(meX, meY, meR*2, meR*2);
}
void startsBubbleSuck() {
//bubbles
for (int i = 0; i < myB.length; i++) {
myB[i].moveMe();
if (myB[i].y>-myB[i].r && dist(meX, meY, myB[i].x, myB[i].y)<myB[i].r+meR && myB[i].r <= meR) {
collide(i);
}
else if (myB[i].y>-myB[i].r && dist(meX, meY, myB[i].x, myB[i].y)<myB[i].r+meR && myB[i].r > meR) {
myB[i].vx = myB[i].forBounce*cos(atan2((myB[i].y-meY), (myB[i].x - meX)));
myB[i].vy = myB[i].forBounce*sin(atan2((myB[i].y-meY), (myB[i].x - meX)));
if (myB[i].canHurt && health != 0)
health --;
myB[i].canHurt = false;
}
myB[i].drawMe();
}
}
void collide(int i) {
float t = atan2(meY-myB[i].y, meX-myB[i].x);
//cheap move?
while (dist (meX, meY, myB[i].x, myB[i].y)<meR+myB[i].r) {
myB[i].x-=.2*cos(t);
myB[i].y-=.2*sin(t);
}
myP[myPN].setVars(myB[i].x, myB[i].y, myB[i].r, myB[i].c, i);
myPN++;
if (myPN>=myP.length)
myPN = 0;
myB[i].resetVars();
}
void keyPressed() {
if (keyCode == UP) {
uu = 1;
meVY = -6;
}
else if (keyCode == DOWN) {
dd = 1;
meVY = 6;
}
else if (keyCode == LEFT) {
ll = 1;
meVX = -6;
}
else if (keyCode == RIGHT) {
rr = 1;
meVX = 6;
}
if (key == 'x') {
meR += 30;
}
if (key == 'p'){
menu = 0;
}
if (key == ' ')
space = 1;
}
void keyReleased() {
if (keyCode == UP) {
uu = 0;
}
else if (keyCode == DOWN) {
dd = 0;
}
else if (keyCode == LEFT) {
ll = 0;
}
else if (keyCode == RIGHT) {
rr = 0;
}
if (key == ' ')
space = 0;
}
//Class Controller
/*this class should hold the menu and the switching of waves
etc.
*/
int menu = 0;
void restart() {
health = 3;
meX = width/2;
meY = height*.9;
meR = 10;
for (int i = 0; i < bubbleNum; i++) {
myB[i].resetVars();
myB[i]. r = 2+random(10);
}
for (int i = 0; i < myP.length; i++) {
myP[i].go = 5;
}
waveTime = 0;
}
void mainMenu() {
for (int i = 0; i < myB.length; i++) {
myB[i].moveMe();
myB[i].drawMe();
myB[i].r = 6;
}
image(main, 0, 0);
fill(#2DC1E0, 230);
rect((width-width/2.5)/2, height/5, width/2.5, height/14);
rect((width-width/2.5)/2, height/3, width/2.5, height/14);
textFont(f, 30);
fill(255);
text("Play!", width/2.25, height/4);
text("Instructions", width/3.25, height/2.55);
textFont(f, 15);
fill(0);
text("Click play or hit the Space Bar", width/3.5, height/3.3);
if (waveNum>=13) {
textFont(f, 30);
text("Gratz! You Win!", width/4.4, height/2);
textFont(f, 15);
text("You can keep going, but \nI don't know if its even \npossible to beat anymore waves...\n\n\n\n\n\nHope you had fun!", width/2.6, height/1.5);
}
textFont(f, 30);
text("Current Wave: " + (int)waveNum, width/2.4, height/1.7);
if (space == 1 || mouseX - (width-width/2.5)/2 < width/2.5 && (width-width/2.5)/2 + width/2.5 - mouseX < width/2.5 && mouseY - height/5 < height/14 && height/5 +height/14 - mouseY < height/14 && mousePressed) {
menu = 1;
fill(#FFC831);
rect((width-width/2.5)/2, height/5, width/2.5, height/14);
restart();
}
if (mouseX - (width-width/2.5)/2 < width/2.5 && (width-width/2.5)/2 + width/2.5 - mouseX < width/2.5 && mouseY - height/3 < height/14 && height/3 +height/14 - mouseY < height/14 && mousePressed) {
menu = 2;
fill(#FFC831);
rect((width-width/2.5)/2, height/3, width/2.5, height/14);
}
}
int waveTime = 0;
float waveNum = 1;
int oneWaveAdvance = 1;
int nextWaveAni = 0;
int onceWaveThing = 1;
void nextWave() {
if (oneWaveAdvance == 1) {
waveNum++;
oneWaveAdvance = 0;
}
textFont(f, 20);
if (waveNum == 13 && onceWaveThing == 1){
menu = 0;
onceWaveThing = 0;
}
uu = 0;
dd = 0;
ll = 0;
rr = 0;
if (meR > 10) {
meR -= 2;
for (int i = 0; i < myB.length; i++) {
if (myB[i].r > 0)
myB[i].r -= 2;
else
myB[i].x = 2000;
}
}
if (dist(meX, meY, width/2, height*.9) < 8) {
meX = width/2;
meY = height*.9;
}
else {
if (meX < width/2 && width/2 - meX > 8) meX+=8;
else if (meX > width/2 && meX - width/2 > 8) meX-=8;
if (meY < height*.9 && height*.9 - meY > 8) meY += 8;
else if (meY > height*.9 && meY - height*.9 > 8) meY -= 8;
}
if (waveTime < 100) {
fill(255);
text("Wave " + (int)waveNum, width/2.25, height/4);
}
else if (waveTime < 130) {
fill(255);
text("Start!", width/2.25, height/4);
}
else if (waveTime > 130) {
restart();
sizeGrower += .2;
oneWaveAdvance = 1;
}
for (int i = 0; i < myB.length; i++) {
myB[i].drawMe();
}
waveTime++;
moveAndDrawMe();
}
class Popper {
float cx, cy, r, v, t;
float[] x = new float[20], y = new float[20];
color c;
int go;
float cxx, cyy;
int whichB;
void setVars(float cx, float cy, float r, color c, int pp) {
this.cx = cx;
this.cy = cy;
this.r = r;
this.c = c;
for (int i = 0; i < 20; i++) {
x[i] = cx+ r*cos(2*PI*i/20);
y[i] = cy+r*sin(2*PI*i/20);
}
go = 1;
whichB = pp;
cxx = meX;
cyy = meY;
}
float d=10;
//sucking engine!
void moveAndDraw() {
fill(c);
float k = 0;
if (go == 1) {
for (int i = 0; i < 20; i++) {
x[i] += (meX - meOX);
y[i] += (meY - meOY);
}
beginShape();
for (int i = 0; i < 20; i++) {
d = dist(x[i], y[i], meX, meY);
t = atan2(meY-y[i], meX-x[i]);
d -=8;
// d-=.08;
x[i] =meX - d*cos(t);
y[i] = meY- d*sin(t);
vertex(x[i], y[i]);
if (dist(x[i], y[i], meX, meY)<5)
k++;
if (k == 8)
go = 2;
}
endShape(CLOSE);
}
if (go == 2) {
for (int i = 0; i < 5; i++) {
x[i]=meX;
y[i]=meY;
}
go = 3;
t = random(360)*PI/180;
v = 0;
}
if (go == 3) {
for (int i = 0; i < 5; i++) {
//me
v+=.5;
x[i]= meX + v*cos(t+(2*PI*i/5));
y[i]= meY+v*sin(t+(2*PI*i/5));
if (dist(x[i], y[i], meX, meY)>=meR-2) {
go = 4;
meR+= myB[whichB].r/50 + .006;
meC = c;
if (health < 3) {
health++;
}
break;
}
ellipse(x[i], y[i], 4, 4);
}
}
}
}
INSTRUCTIONS THAT I LEFT OUT: Use the arrow keys to move around.... >.<
Here is my first contribution to Open Processing!
Please play this game and tell me what you think! The code is admittedly sloppy and pretty nasty to try to figure out... but hope this was a worthwhile upload. I think its pretty fun.
Also, beat wave 12 and I'll be impressed! I have played this game for hours and I still haven't beaten wave 12. So yeah... you can brag about it in the comments if you do it.
Anyway yeah... enjoy! :D
-Karl F