xxxxxxxxxx
/*
Annie Wu
Reaction time game. Originally I wanted something like a rhythm game but I haven't found a non time consuming way to find a songs beat map and time it perfectly.
Instead, I made a game where it tests the players reactions.
*/
let x, y;
let xspeed;
let yspeed;
let value; // these values are used to tell a player has hit key 'a'
let value2; // key 's'
let value3; // key 'd'
let value4; // key 'f'
var early_counter = 0; // the misses counter
var score_counter = 0;
var hitagain = true;
var endscreen = false;
//times are the numbers of which marks milliseconds passed.
//stuff1 marks the y coordinates it begins from.
var times1 = [0, 3000, 3500, 6000]
var stuff1 = [1600, 2200, 2800, 3400, 4000];
var times2 = [0, 2000, 5400, 7000]
var stuff2 = [1600, 2200, 2800, 3400, 4000];
var times3 = [0, 4000, 6600, 8900]
var stuff3 = [1600, 2200, 2800, 3400, 4000];
var times4 = [0, 1300, 3500, 9000]
var stuff4 = [1600, 2200, 2800, 3400, 4000];
var isplaying = false;
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
//ellipse(windowWidth/2,windowHeight/2,150,150)
x = width / 2
iy = height / 2
y = iy;
}
function draw() {
background(0);
if (!isplaying) // STARTUP SCREEN
{
fill(255);
textSize(30);
textAlign(CENTER);
textWrap(WORD);
text('Reaction test game. There will be circles moving at various speeds, hit the appropriate key in time to gain points. Ex. For the A circle, hit the A key. Also set windowscreen to 67% and then refresh the page ', 500, windowHeight / 3, 1500);
}
if (isplaying) // MAIN GAME LOOP
{
background(0);
textSize(40);
strokeWeight(10);
stroke(255);
// Written Letters
fill(208, 78, 243)
text('A', 990, 250);
fill(78, 228, 243)
text('S', 1190, 250);
fill(70, 238, 103)
text('D', 1390, 250);
fill(238, 70, 106)
text('F', 1590, 250);
fill(182, 182, 182)
ellipse(1000, 100, 150, 150)
fill(182, 182, 182)
ellipse(1200, 100, 150, 150)
fill(182, 182, 182)
ellipse(1400, 100, 150, 150)
fill(182, 182, 182)
ellipse(1600, 100, 150, 150)
let j = 0; //this
for (let i = 0; i < stuff1.length; i++) {
if (millis() > times1[j] || millis() > times2[j] || millis() > times3[j] || millis() > times4[j]) { // if the time exceeds the number in the time array...
noStroke();
fill(208, 78, 243)
ellipse(1000, stuff1[i], 150, 150)
stuff1[i] = stuff1[i] - 10;
noStroke();
fill(78, 228, 243)
ellipse(1200, stuff2[i], 150, 150)
stuff2[i] = stuff2[i] - 15;
noStroke();
fill(70, 238, 103)
ellipse(1400, stuff3[i], 150, 150)
stuff3[i] = stuff3[i] - 20;
noStroke();
fill(238, 70, 106)
ellipse(1600, stuff4[i], 150, 150)
stuff4[i] = stuff4[i] - 27;
}
if (value == true) { //key 'a' is hit
textSize(50)
fill(255);
if (stuff1[i] > 120 ||stuff2[i] > 120 ||stuff3[i] > 120 ||stuff4[i] > 120 ) { //if the y coordinates of the moving circle do not reach the end yet
noStroke();
text(early_counter + 'MISS', 1200, 500);
}
if (stuff1[i] < 120 && stuff1[i] > 80) { //if the circle is within the y range
noStroke();
text('PERFECT', 500, 500);
score_counter++;
early_counter = ini_counter;
hitagain = false;
fill(247, 235, 55)
ellipse(1000, stuff1[i], 160, 160)
}
}
if (value2 == true) {
textSize(50)
fill(255);
if (stuff1[i] > 120 ||stuff2[i] > 120 ||stuff3[i] > 120 ||stuff4[i] > 120 ) {
noStroke();
text(early_counter + 'MISS', 1200, 500);
}
if (stuff2[i] < 120 && stuff2[i] > 80) {
noStroke();
text('PERFECT', 500, 500);
score_counter++;
early_counter = ini_counter;
hitagain = false;
fill(247, 235, 55)
ellipse(1200, stuff2[i], 160, 160)
}
}
if (value3 == true) {
textSize(50)
fill(255);
if (stuff1[i] > 120 ||stuff2[i] > 120 ||stuff3[i] > 120 ||stuff4[i] > 120 ) {
noStroke();
text(early_counter + 'MISS', 1200, 500);
}
if (stuff3[i] < 120 && stuff3[i] > 80) {
noStroke();
text('PERFECT', 500, 500);
score_counter++;
early_counter = ini_counter;
hitagain = false;
fill(247, 235, 55)
ellipse(1400, stuff3[i], 160, 160)
}
}
if (value4 == true) {
textSize(50)
fill(255);
if (stuff1[i] > 120 ||stuff2[i] > 120 ||stuff3[i] > 120 ||stuff4[i] > 120 ) {
noStroke();
text(early_counter + 'MISS', 1200, 500);
}
if (stuff4[i] < 120 && stuff4[i] > 80) {
noStroke();
text('PERFECT', 500, 500);
score_counter++;
early_counter = ini_counter;
hitagain = false;
fill(247, 235, 55)
ellipse(1600, stuff4[i], 160, 160)
}
}
noStroke();
text(score_counter + ' SCORE', windowWidth / 2, 800);
if (value == false||value2 == false||value3 == false||value4 == false) { //if the key is not hit
textSize(50)
fill(0);
text('MISS', windowWidth / 2, 600);
}
j++; //moving to the next time
ihit = false;
}
if(millis()>10000){
textSize(40);
fill(255);
text('Play again? (y/n)', 500, 700);
if(endscreen==true){
textSize(90);
fill(255);
text('Okay BYE', 500, 900);
}
}
}
}
function keyTyped() {
isplaying = true;
if (key === 'a') {
ini_counter = early_counter;
early_counter++;
score_counter--;
value = true;
} else if (key === 's') {
ini_counter = early_counter;
early_counter++;
value2 = true;
} else if (key === 'd') {
ini_counter = early_counter;
early_counter++;
value3 = true;
} else if (key === 'f') {
ini_counter = early_counter;
early_counter++;
value4 = true;
} else if (key === 'y') {
isplaying=false;
} else if (key === 'n') {
endscreen=true;
}
else {
value = false;
value2 = false;
value3 = false;
value4 = false
}
}