Click as many times as you can in the span of 5 seconds to determine your CPS (clicks per second). Good luck!
xxxxxxxxxx
let mode = "startingScreen";
let clicks = 0;
let time = 0;
let circleAlpha = 255;
let radius = 10;
let showCircle = "false";
let cps = 0;
let highscore = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
button1 = createButton("Start");
button2 = createButton("Try Again");
rectMode(CENTER);
}
function draw() {
background("black");
switch (mode) {
case "startingScreen":
button1.show()
button1.position(windowWidth / 2.2, 0 + windowHeight / 6);
button1.size(100, 50);
button1.mouseClicked(() => {
mode = "gameMode";
});
button2.hide();
push();
fill("green");
textAlign(CENTER, CENTER);
textSize(windowWidth / 10);
text("CPS Test", windowWidth / 2, windowHeight / 2);
pop();
break;
case "gameMode":
button1.hide();
button2.hide();
if (showCircle == "true") {
push();
fill(0, 128, 0, circleAlpha);
circle(mouseX, mouseY, radius);
pop();
circleAlpha -= 30;
radius += 20;
}
time++;
if (time >= 300) {
time = 0;
mode = "endScreen";
cps = clicks / 5;
if (cps >= highscore) {
highscore = cps;
}
}
break;
case "endScreen":
push();
fill("green");
textAlign(CENTER, CENTER);
textSize(windowWidth / 10);
translate(windowWidth / 2, windowHeight / 2);
text("Your CPS is " + cps, 0, -20);
textSize(windowWidth / 20);
if (clicks != 1) {
text("You clicked " + clicks + " times in 5 seconds", 0, windowHeight / 6);
} else if (clicks == 1) {
text("You clicked " + clicks + " time in 5 seconds", 0, windowHeight / 6);
}
text("Your best CPS ever is " + highscore, 0, windowHeight / 6 * 2);
pop();
button2.show()
button2.position(windowWidth / 2.2, 0 + windowHeight / 6);
button2.size(100, 50);
button2.mouseClicked(() => {
mode = "startingScreen";
clicks = 0;
});
break;
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function mouseClicked() {
if (mode == "gameMode"){
clicks++
showCircle = "true"
}
}
function mouseReleased() {
if (mode == "gameMode") {
circleAlpha = 255;
radius = 10;
}
}