// Define the Box class class Box{ // Variables for Box class color c; float xpos; float ypos; float xsize; float ysize; float boxspeed; // Constructor for the Box class Box(color tempC, float tempXpos, float tempYpos, float tempXsize, float tempYsize, float tempS) { c = tempC; xpos = tempXpos; ypos = tempYpos; xsize = tempXsize; ysize = tempYsize; boxspeed = tempS; } void boxdisplay() { // Rect function to actually draw the things, rectmode center important so clicking outside the boxes won't work fill(c); rectMode(CENTER); rect(xpos,ypos,xsize,ysize); } void boxmove() { // Function to make the Box move and pop back to start when it goes beyond width as well as assign new random x and y values for "respawn" // Also subract a life if the Box moves beyond the sketch width of 800 xpos = xpos + boxspeed; if (xpos > 800) { lives = lives -1; xpos = random(5,10); ypos = random(15,85); boxspeed = boxspeed +0.1; xsize = 20; ysize = 20; } } }