Where is Tori’s mental state right now? You may be asking yourself. Well, last night, I had a dream where everyone just asked me if I was okay and told me to drink water.
So I decided to make a game where you would always win. No matter what. Because that’s the kind of support I need in my life.
The game is pretty basic. A bunch of circles go through the screen, bouncing off the walls like a kid who’s just discovered coffee. Your mission is to click on each ball, thus, vanishing it. There is a counter in the top left corner so you can keep track of how many balls there are left. And there is also a timer running. The catch? You have no idea how long you have. I’ve set the time t be between 10 and 30 seconds, although once you reach that time, you can reset the timer.
I should say that for some of the code, I used Amy’s catching ball game code as a reference to understand how the class may work. But the rest I figured out using my understanding of how it all works.
Here’s the video:
And here’s the main code:
int totBall = 30; float xPos; float yPos; float spd; int counter = 30; boolean timer = true; int x = 1; boolean time = false; Ball Ball[] = new Ball[totBall]; boolean timeIsUp=false; float timeTillOver; void setup() { fullScreen(); noStroke(); for (int i = 0; i < totBall; i++) { Ball[i] = new Ball(5, 100, random(1, 5), random(1, 5)); } timeTillOver=millis()+random(10000,30000); } void draw() { background(0); if (time == false) { for (int i = 0; i < totBall; i++) { Ball[i].run(); } fill(0); rect(0, 0, width, 50); fill(255); textSize(30); text("Number of Balls:", 20, 30); text(counter, 280, 30); text("You Have Limited Time", 1500, 30); textSize(80); if (counter <= 0) { text("YOU WIN!", width/2-150, height/2); timer = false; } } else { textSize(60); text("TIME IS UP", width/2-150, height/2); textSize(30); text("press SPACE to resume", width/2 - 165, height/2 + 60); } if (timer == true) { if (millis() >= timeTillOver) { time = true; } } } void keyPressed(){ if(key==' '){ time=false; timeTillOver=millis()+random(10000,30000); } //maybe make a hard mode where they all turn black? or increase in speed? }
and Ball Class
class Ball { float xPos, yPos, spdX, spdY, size1; color clr; boolean disable = false; Ball(float x, float y, float speedX, float speedY) { xPos = x; yPos = y; spdX = speedX; spdY = speedY; size1 = random(35, 55); clr = color(random(0, 255), random(0, 255), random(0, 255)); } void display() { if (disable == false){ fill(clr); if (mousePressed && dist(mouseX, mouseY, xPos, yPos) <= (size1/2) ){ counter -= 1; disable = true; } ellipse(xPos, yPos, size1, size1); } } void move() { yPos += spdY; if (yPos > height || yPos < 50){ spdY *= -1; } xPos += spdX; if(xPos > width || xPos < 0){ spdX *= -1; } } void run() { move(); display(); } }