├── balloon_rescue_screenshot_main.png ├── README.md ├── Timer.pde ├── Roof.pde ├── Balloon.pde └── balloon_rescue.pde /balloon_rescue_screenshot_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelkolesidis/balloon-rescue/HEAD/balloon_rescue_screenshot_main.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # balloon-rescue 2 | Rescue the balloons from touching the spikes. 3 | 4 | 5 | 6 | Version: 0.0.1 7 | 8 | Known issues: 9 | The first balloon you click on, gets stuck with the mouse pointer. 10 | -------------------------------------------------------------------------------- /Timer.pde: -------------------------------------------------------------------------------- 1 | class Timer { 2 | int savedTime; // When timer started 3 | int totalTime; // How long timer should last 4 | 5 | Timer (int tempTotalTime) { 6 | totalTime = tempTotalTime; 7 | } 8 | 9 | // Starting the timer 10 | void start() { 11 | savedTime = millis(); 12 | } 13 | 14 | boolean isFinished() { 15 | // Check how much time has passed 16 | int passedTime = millis() - savedTime; 17 | if (passedTime > totalTime) { 18 | return true; 19 | } else { 20 | return false; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Roof.pde: -------------------------------------------------------------------------------- 1 | class Roof { 2 | int brickX, brickY; // Brick positions 3 | int brickW, brickH; // Brick dimensions 4 | int brickNum; // Number of bricks 5 | 6 | int spikeX; // Spike position 7 | int spikeW, spikeH; // Spike dimensions 8 | int spikeNum; // Number of spikes 9 | 10 | Roof() { 11 | //brickX calculated in loop 12 | brickY = 0; 13 | brickW = 105; // If brickW,brickH and brickNum are changed, spikes are generated accordingly automatically 14 | brickH = 40; 15 | brickNum = 4; 16 | //spikeX calculated in loop 17 | spikeW = 20; // If spikeW is changed, spikes are generated accordingly automatically 18 | spikeH = 30; 19 | spikeNum = (brickNum*brickW)/spikeW; 20 | } 21 | 22 | void display() { 23 | for (spikeX = 0; spikeX < spikeNum*spikeW; spikeX += spikeW) { // Display the spikes 24 | strokeWeight(3); 25 | fill(140); 26 | stroke(50); 27 | triangle(spikeX, brickH, spikeX+spikeW, brickH, spikeX+(spikeW/2), brickH+spikeH); 28 | } 29 | 30 | for (brickX = 0; brickX < brickNum*brickW; brickX += brickW) { // Display the bricks 31 | strokeWeight(4); 32 | stroke(100, 60, 30); 33 | fill(150, 90, 50); 34 | rect(brickX, brickY, brickW, brickH); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Balloon.pde: -------------------------------------------------------------------------------- 1 | class Balloon { 2 | float x, y; // Balloon positions 3 | float w, h; // Balloon dimensions 4 | float r; // Balloon radius 5 | float speedX; // Balloon horizontal speed 6 | float speedY; // Balloon vertical speed 7 | 8 | Balloon() { 9 | x = random(2*r, width-2*r); // Balloons start at a random position 10 | y = height+4*r; // Balloon start below screen 11 | r = 30; 12 | speedX = random(-0.5, 0.5); 13 | speedY = random(-1, -4); 14 | } 15 | 16 | // Check if balloon is popped 17 | boolean popped() { 18 | // If it touches the spikes 19 | if (x <= roof.brickNum*roof.brickW+r && y == roof.brickH + roof.spikeH*2) { 20 | return true; 21 | } else { 22 | return false; 23 | } 24 | } 25 | 26 | // Pop the balloon 27 | void pop() { 28 | speedX = 0; 29 | speedY = 0; 30 | x = width/2; 31 | y = 2*height; 32 | } 33 | 34 | // Display the balloon 35 | void display() { 36 | strokeWeight(2); 37 | stroke(10); 38 | line(x, y, x, y+r*3.5); 39 | strokeWeight(3); 40 | stroke(125, 0, 0); 41 | fill(255, 0, 0); 42 | circle(x, y, 2*r); 43 | triangle(x, y+r, x+r/4, y+r+r/3, x-r/4, y+r+r/3); 44 | noStroke(); 45 | fill(255); 46 | ellipseMode(CENTER); 47 | ellipse(x-r+r/4, y, r/4, r/2); 48 | } 49 | 50 | // Move the balloon up 51 | void move() { 52 | x += speedX; 53 | y += speedY; 54 | x = constrain(x, r, width-r); // Keep the balloons in screen 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /balloon_rescue.pde: -------------------------------------------------------------------------------- 1 | // =============== 2 | // Balloon Rescue 3 | // Version: 0.0.1 4 | // =============== 5 | 6 | Roof roof; // One roof object 7 | Timer timer; // One timer object 8 | Balloon[] balloons; // An array of balloon objects 9 | 10 | int totalBalloons = 0; // Total number of balloons 11 | boolean drag = false; 12 | boolean release = false; 13 | 14 | void setup() { 15 | size(600, 400); // Set the size of the window 16 | roof = new Roof(); // Create the roof 17 | balloons = new Balloon[10]; // Create a number of spots in the array 18 | timer = new Timer(1000); // Create a timer that goes off every 1 second 19 | timer.start(); // Starting the timer 20 | } 21 | 22 | void draw() { 23 | background(100, 205, 255); // Display the sky 24 | roof.display(); // Display the roof 25 | 26 | // Check the timer 27 | if (timer.isFinished()) { 28 | 29 | // Initialize one balloon 30 | balloons[totalBalloons] = new Balloon(); 31 | // Increment totalBalloons 32 | totalBalloons++; 33 | // If totalBalloons hit the end of the array 34 | if (totalBalloons >= balloons.length) { 35 | totalBalloons = 0; // Start over 36 | } 37 | timer.start(); 38 | } 39 | 40 | // Move and display all ballooms 41 | for (int i = 0; i < totalBalloons; i++) { 42 | if (balloons[i].popped()) { 43 | balloons[i].pop(); 44 | } 45 | balloons[i].display(); 46 | balloons[i].move(); 47 | } 48 | 49 | if (drag) { 50 | for (int i = 0; i < totalBalloons; i++) { 51 | if (dist(mouseX, mouseY, balloons[i].x, balloons[i].y) >= +balloons[i].r) 52 | balloons[i].x = mouseX; 53 | balloons[i].y = mouseY; 54 | return; 55 | } 56 | } 57 | } 58 | 59 | 60 | void mouseDragged() { 61 | drag = true; 62 | } 63 | 64 | void mouseReleased() { 65 | release = true; 66 | } 67 | --------------------------------------------------------------------------------