/* Tim Lee "Baloon Pop Game" Colourful Baloons will bounce around the screen. Hover your cursor above the Baloons, and left click to pop them. Have fun! */ //set global variables //size of the balloon ellipse float bsize = random(40, 80); float bvar = (bsize/2); //positioning of balloons float bx = random(80, 320); float by = random(80, 320); //variable for movement float movex = 4; float movey = 4; //colour of balloons float bred = random(0, 255); float bgreen = random(0, 255); float bblue = random(0, 255); //game rules (all balloons popped + keep track of # of popped) boolean unpopped = true; float popnum = 0; //main setup void setup() { //general setup size(400, 400); frameRate(30); } //main game void draw() { drawBalloon(); } //main code for balloon void drawBalloon() { if (unpopped) { //set background + nostroke noStroke(); background(254, 239, 255); //draw the balloon mapBalloon(); //move balloon moveBalloon(); } } //code for movement void moveBalloon() { //local variable for size float bvar = (bsize/2); //movement bx+=movex; by+=movey; //bouncing float hbox1x = (bx+bvar); float hbox1y = (by+bvar); float hbox2x = (bx-bvar); float hbox2y = (by-bvar); if (hbox1x > width) { movex *= -1; } else if (hbox1y > height) { movey *= -1; } else if (hbox2x < 0) { movex *= -1; } else if (hbox2y < 0) { movey *= -1; } } void mousePressed() { if (mouseX < bx+bvar && mouseY < by+bvar && mouseX > bx-bvar && mouseY > by-bvar) { unpopped = false; println("Pop!!!!"); background(254, 239, 255); fill(255, 82, 2); triangle(mouseX-10, mouseY+10, mouseX, mouseY+30, mouseX+10, mouseY+10); triangle(mouseX, mouseY+10, mouseX+20, mouseY+20, mouseX+10, mouseY); triangle(mouseX+10, mouseY+10, mouseX+30, mouseY, mouseX+10, mouseY-10); triangle(mouseX, mouseY-10, mouseX+20, mouseY-20, mouseX+10, mouseY); triangle(mouseX+10, mouseY-10, mouseX, mouseY-30, mouseX-10, mouseY-10); triangle(mouseX, mouseY-10, mouseX-20, mouseY-20, mouseX-10, mouseY); triangle(mouseX-10, mouseY-10, mouseX-30, mouseY, mouseX-10, mouseY+10); triangle(mouseX, mouseY+10, mouseX-20, mouseY+20, mouseX-10, mouseY); ellipse(mouseX, mouseY, 20, 20); } } void mapBalloon() { //local variables for bottom portion of balloon //variables for the triangle float btri1x = (bx-bvar+2); float btri1y = (by+10); float btri2x = (bx+bvar-2); float btri2y = (btri1y); float btri3x = (bx); float btri3y = (by+bvar+20); //variables for the tie-off portion (not included in hitbox) float btag1x = (bx); float btag1y = (by+bvar+20); float btag2x = (bx+bsize/4); float btag2y = (btag1y+bsize/4); float btag3x = (bx-bsize/4); float btag3y = (btag2y); //draw the circle part of the balloon fill(bred, bgreen, bblue); ellipse(bx, by, bsize, bsize); //lower portion triangle(btri1x, btri1y, btri2x, btri2y, btri3x, btri3y); //tie-off, not counted portion fill(bred, bgreen+80, bblue+80); triangle(btag1x, btag1y, btag2x, btag2y, btag3x, btag3y); }