// Experimental Interaction Assignment 1: Shoot Circles & Boxes Extinction game by Jakob Fischer Jørgensen // *** To-do list *** // - Add sound/music if time and abilites allow it // - Enable pressing spacebar or some other key to start over // - * DONE * Make and endstate gameover when boxes reach screen x width and have it show score // - * DONE * Make it so the mouse cannot be held down but you have to actively click each object. // - * DONE * Make a second class of some sort, moving boxes from middle to sides and top or bottom or faster growing circles with a later spawn // - * DONE * Make a scorecount float integer or something that updates on screen each time circle or box is clicked // - * DONE * Text for a few seconds like "shoot the circles and boxes! fast!" Make text go away again after x seconds. // - * DONE * Replace the cursor with a crosshair // - * DONE * Make all circles and the boxes clickable with mousepressed -> respawn // - * DONE * Add a score penalty when circles reach a certain size and make them respawn // - * DONE * Add an extra box or circle at timer intervals to make the game more challenging over time // - * DONE * Make boxes move faster each respawn, some kind of speed increase // - * DONE * Organise code to be less messy and start commenting, adding white spaces and inlets // - * DONE * Move the Box and Circle class to seperate tabs and get organised // Declare four Circle objects as global variables Circle myCircle1; Circle myCircle2; Circle myCircle3; Circle myCircle4; Circle myCircle5; Circle myCircle6; // Declare eight Box objects as global variables Box myBox1; Box myBox2; Box myBox3; Box myBox4; Box myBox5; Box myBox6; Box myBox7; Box myBox8; // Global variable to keep count of the score declared and set to zero // Integer, not float, as we don't want decimal numbers displayed inside text in draw int score = 0; // Global variable to keep track of lives, set to 10 at start int lives = 10; // Some kind of boolean to make the damn thing restart boolean restart = true; void setup() { // THE GREAT SETUP: The stuff we do only ONCE at the start of the program size(800,100); // Sketch x and y size frameRate(60); // Sketch framerate // Initialize Circle objects by calling the Circle constructor myCircle1 = new Circle(color(255,0,0),random(100,700),random(10,90),1,1); myCircle2 = new Circle(color(255,80,0),random(100,700),random(10,90),1,1); myCircle3 = new Circle(color(255,160,0),random(100,700),random(10,90),1,1); myCircle4 = new Circle(color(255,240,0),random(100,700),random(10,90),1,1); myCircle5 = new Circle(color(255,40,0),random(100,700),random(10,90),1,1); myCircle6 = new Circle(color(255,200,0),random(100,700),random(10,90),1,1); // Initialize Box objects by calling the Box constructor myBox1 = new Box(color(255,40,0),random(5,10),random(15,85),20,20,0.5); myBox2 = new Box(color(255,120,0),random(5,10),random(15,85),20,20,0.5); myBox3 = new Box(color(255,200,0),random(5,10),random(15,85),20,20,0.5); myBox4 = new Box(color(255,40,0),random(5,10),random(15,85),20,20,0.5); myBox5 = new Box(color(255,200,0),random(5,10),random(15,85),20,20,0.5); myBox6 = new Box(color(255,120,0),random(5,10),random(15,85),20,20,0.5); myBox7 = new Box(color(255,40,0),random(5,10),random(15,85),20,20,0.5); myBox8 = new Box(color(255,200,0),random(5,10),random(15,85),20,20,0.5); } // setup over // THE GREAT DRAW: The stuff we do OVER and OVER void draw() { // Replace the normal cursor with a cross cursor(CROSS); // Set black background background(0,0,0); // If they player has run out of lives display that he lost and what his score was if (lives < 1) { fill(255,0,0); text("You lost! Your final score was:",300,50); text (score,470,50); text("Press any key to start over!",320,70); // if (restart == true); } else { // Make the score count green // Place score text in upper right corner // Place score integer next to score text in upper right corner fill(0,255,0); text("Score:",720,20); text(score,760,20); // Make the life count red // Place score text in upper right corner // Place lives integer next to score text in upper right corner fill(255,0,0); text("Lives:",667,20); text(lives,700,20); // Draw green text in upper left corner after 0.5 seconds // After eight seconds make the text go away again if (millis() > 500 && millis() < 8000){ fill(0,255,0); text("Shoot the circles before they grow too big!",10,20); } // Draw green text in the upper left corner after 9.5 seconds // After 17 seconds make the text go away again if (millis() > 9500 && millis() < 17000){ fill(0,255,0); text("Shoot the boxes before they reach the other side!",10,20); } // Spawm the boxes and make them move, each Box object calls the object method using dot syntax // Interval between each box spawn is 10 seconds, done by checking how long since applet started float boxm = millis(); if (boxm > 10000) { myBox1.boxmove(); myBox1.boxdisplay(); } if (boxm > 20000) { myBox2.boxmove(); myBox2.boxdisplay(); } if (boxm > 30000) { myBox3.boxmove(); myBox3.boxdisplay(); } if (boxm > 40000) { myBox4.boxmove(); myBox4.boxdisplay(); } if (boxm > 50000) { myBox5.boxmove(); myBox5.boxdisplay(); } if (boxm > 60000) { myBox6.boxmove(); myBox6.boxdisplay(); } if (boxm > 70000) { myBox7.boxmove(); myBox7.boxdisplay(); } if (boxm > 80000) { myBox8.boxmove(); myBox8.boxdisplay(); } // Spawn circles and make them grow, each Circle object calls the object method using dot syntax // Time since applet start checked to make Circles spawn at specific time intervals float m = millis(); if (m > 3000) { myCircle1.grow(); myCircle1.display(); } if (m > 8000) { myCircle2.grow(); myCircle2.display(); } if (m > 13000) { myCircle3.grow(); myCircle3.display(); } if (m > 18000) { myCircle4.grow(); myCircle4.display(); } if (m > 35000) { myCircle5.grow(); myCircle5.display(); } if (m > 75000) { myCircle6.grow(); myCircle6.display(); } } } // draw over // Some sort of stuff to restart the applet/reset variables if keypressed to be called in the if inside lost in draw void keyPressed() { boolean restart = true; } // Start of what happens when mouse is pressed down once. // This is checked each time the mouse is pressed, not released, not held down either. void mousePressed(){ // Create float variables for the distance between mouse position and the position of the circles with dot syntax float distance1 = dist(mouseX, mouseY, myCircle1.xpos, myCircle1.ypos); float distance2 = dist(mouseX, mouseY, myCircle2.xpos, myCircle2.ypos); float distance3 = dist(mouseX, mouseY, myCircle3.xpos, myCircle3.ypos); float distance4 = dist(mouseX, mouseY, myCircle4.xpos, myCircle4.ypos); float distance5 = dist(mouseX, mouseY, myCircle5.xpos, myCircle5.ypos); float distance6 = dist(mouseX, mouseY, myCircle6.xpos, myCircle6.ypos); // Create float variables for the distance between mouse position and the position of boxes with dot syntax float bdist1 = dist(mouseX, mouseY, myBox1.xpos, myBox1.ypos); float bdist2 = dist(mouseX, mouseY, myBox2.xpos, myBox2.ypos); float bdist3 = dist(mouseX, mouseY, myBox3.xpos, myBox3.ypos); float bdist4 = dist(mouseX, mouseY, myBox4.xpos, myBox4.ypos); float bdist5 = dist(mouseX, mouseY, myBox5.xpos, myBox5.ypos); float bdist6 = dist(mouseX, mouseY, myBox6.xpos, myBox6.ypos); float bdist7 = dist(mouseX, mouseY, myBox7.xpos, myBox7.ypos); float bdist8 = dist(mouseX, mouseY, myBox8.xpos, myBox8.ypos); // If mouse is within the box when clicked make new box instance with values indicated and add 1 to score integer // Also make sure the boxes continually move faster after click/respawn by adding to boxspeed using dot syntax if (bdist1 < myBox1.xsize/2){ myBox1 = new Box(color(255,40,0),random(5,10),random(15,85),20,20,myBox1.boxspeed); myBox1.boxspeed = myBox1.boxspeed +0.1; score = score +1; } if (bdist2 < myBox2.xsize/2){ myBox2 = new Box(color(255,120,0),random(5,10),random(15,85),20,20,myBox2.boxspeed); myBox2.boxspeed = myBox2.boxspeed +0.1; score = score + 1; } if (bdist3 < myBox3.xsize/2){ myBox3 = new Box(color(255,200,0),random(5,10),random(15,85),20,20,myBox3.boxspeed); myBox3.boxspeed = myBox3.boxspeed +0.1; score = score + 1; } if (bdist4 < myBox4.xsize/2){ myBox4 = new Box(color(255,40,0),random(5,10),random(15,85),20,20,myBox4.boxspeed); myBox4.boxspeed = myBox4.boxspeed +0.1; score = score + 1; } if (bdist5 < myBox5.xsize/2){ myBox5 = new Box(color(255,200,0),random(5,10),random(15,85),20,20,myBox5.boxspeed); myBox5.boxspeed = myBox5.boxspeed +0.1; score = score + 1; } if (bdist6 < myBox6.xsize/2){ myBox6 = new Box(color(255,120,0),random(5,10),random(15,85),20,20,myBox6.boxspeed); myBox6.boxspeed = myBox6.boxspeed +0.1; score = score + 1; } if (bdist7 < myBox7.xsize/2){ myBox7 = new Box(color(255,40,0),random(5,10),random(15,85),20,20,myBox7.boxspeed); myBox7.boxspeed = myBox7.boxspeed +0.1; score = score + 1; } if (bdist8 < myBox8.xsize/2){ myBox8 = new Box(color(255,200,0),random(5,10),random(15,85),20,20,myBox8.boxspeed); myBox8.boxspeed = myBox8.boxspeed +0.1; score = score + 1; } // If mouse is within the circle when clicked make new circle instance with the values indicated and add 1 to score integer if (distance1 < myCircle1.xgrowth/2){ myCircle1 = new Circle(color(255,0,0),random(100,700),random(10,90),1,1); score = score + 1; } if (distance2 < myCircle2.xgrowth/2){ myCircle2 = new Circle(color(255,80,0),random(100,700),random(10,90),1,1); score = score + 1; } if (distance3 < myCircle3.xgrowth/2){ myCircle3 = new Circle(color(255,160,0),random(100,700),random(10,90),1,1); score = score + 1; } if (distance4 < myCircle4.xgrowth/2){ myCircle4 = new Circle(color(255,240,0),random(100,700),random(10,90),1,1); score = score + 1; } if (distance5 < myCircle5.xgrowth/2){ myCircle5 = new Circle(color(255,40,0),random(100,700),random(10,90),1,1); score = score + 1; } if (distance6 < myCircle6.xgrowth/2){ myCircle6 = new Circle(color(255,200,0),random(100,700),random(10,90),1,1); score = score + 1; } } // mousePressed over