# ICM – Week 3 Assignment

PIN

This week my partner, Ashwita, and I expanded on my initial balloon popping game concept. We wanted to expand the concept by being able to generate multiple balloons, have those balloons change colors in a non-monochromatic range, have the balloons be pressable buttons (instead of relying on a general mouseClick function), and to incorporate a popping sound and pop counter.

We ran into the following problems. First, we could not figure out how to make a circular moving button (the balloon). We tried doing so by using the distance function and not having the balloons pop when clicked, but when the mouse hovered over the balloons instead. We also struggled with making each balloon, as individual objects, separate clickable entities.

Pending feedback we look forward to making different levels, turning this exercise into a game. Below is a video of our animation, with a final and test iteration of code.

``````let balloonColor;
let balloonPositionX;
let balloonPositionY;
let s = 'POP lol';
let r,g,b;
let imga, imgb;

function setup() {
createCanvas(800, 600);
balloonColor = random(255);
balloonPositionX = random(0,200);
balloonPositionY = 400;
}

// sound = loadSound('balloon-pop.mp3'); // balloon pop sound
}

function draw() {
background(220);
image(imgb, balloonPositionX, balloonPositionY, 200, 200);
push();
pop();
fill(0);

// pin
ellipse(mouseX, mouseY, 5, 5);
line(mouseX, mouseY, mouseX + 20, mouseY - 10);

//floating balloon waver
balloonPositionX = balloonPositionX ;
balloonPositionY = balloonPositionY - 4;
if (balloonPositionY === 0) {
balloonPositionY = 600;
balloonPositionX = random(0,400);
balloonColor = random(255,0,0);
}
if (mouseIsPressed) {
// text(s, balloonPositionX , balloonPositionY, 80, 80)
balloonPositionY = 600;
balloonPositionX = random(0,800);
balloonColor = random(255);
}
}``````

Below is the code for one of our test iterations

``````let counter1 = 400; // counter for balloon 1
let counter2 = 600; // counter for balloon 2
let xpos1, xpos2; // the horizontal positions for the balloon 1 and 2
// let speed = 1;
let position;
let ypos;
var sound;
var imga, imgb;
let bx1, by1, bx2, by2;

function setup() {
createCanvas(400, 400);
xpos1 = random(0, 400); // setting a random position for balloon 1
xpos2 = random(0, 400); // setting a random position for balloon 2
ypos = random(0, 400); // setting up horizontal pos. differences between Balloon 1&2.
bx1 = random(0, 600);
bx2 = random(0, 600);
by1 = random(0, 400);
by2 = random(0, 400);
}

// sound = loadSound('balloon-pop.mp3'); // balloon pop sound
}

function draw() {
background(255);
strokeWeight(1);
image(imga, xpos1, counter1, 200, 200);
// let ball1 = rect(xpos1,counter1,50, 50) // balloon 1 represented by a square

// to make the balloon float one after the other in a loop
if (counter1 <= -50 && counter2 <= -50) {
counter1 = 400;
counter2 = 600;
xpos1 = random(0, 400);
fill(255); // resets the color every loop

if (dist(mouseX, mouseY, xpos1, counter1) < 200 / 2 ||
dist(mouseX, mouseY, xpos2, counter2) < 200 / 2) {
background(0);
} else {
background(255);
}

// ellipse(bx1, by1, d, d);
// ellipse(bx2, by2, d, d);
}
image(imgb, xpos2, counter2, 200, 200);
// let ball2 = rect(xpos2,counter2,50, 50); // balloon 2 represented by a square
counter1 -= 1;
counter2 -= 1;

ellipse(mouseX, mouseY, 5, 5);
line(mouseX, mouseY, mouseX, mouseY - 15);

// // making the balloon pop sound
// if (mouseIsPressed) {
//   // sound.play();
//  fill(0,0,255);
// }

}``````