Use of keyPressed to call new sates?
in
Programming Questions
•
5 months ago
Hi,
I'm pretty much a complete noob when it comes to processing. I've worked through a quite a few tutorials and now I'm working on a reaction test game.
My aim is to have:
My aim is to have:
An "opening screen"
-then any key pressed changes to-
-then any key pressed changes to-
A "ready screen" appears
-Then a mouse click changes to-
-Then a mouse click changes to-
A "steady screen" appears and at the same time, a random timer set to between 3-6 seconds starts counting down.
-when the timer reaches 0-
A "go screen" appears and at the same time a timer begins. The user has to click on the screen as quickly as possible
-when the mouse is clicked: the times stops-
A "result screen" appears displaying the reaction time of the user between the "go screen" appearing and the user clicking the mouse.
Further to this,
It would be good to have the program store the 5 quickest times and display them on the "opening screen".
Here's what I'm working with so far. Each red header is a different tab in processing.
Here's what I'm working with so far. Each red header is a different tab in processing.
work_in_progress---
OpenScreen oScr;
ReadyScreen rScr;
SteadyScreen sScr;
GoScreen gScr;
FinishScreen fScr;
boolean[]scrState;
int numStates=4;
void setup() {
size(600, 600);
scrState=new boolean[numStates];
for (int i = 0; i < numStates; i++) {
scrState[i]=false;
}
smooth();
}
void keyPressed() {
if (key=='r')
scrState[0]=true;
else if (key== 'v')
scrState[1]=true;
}
void draw() {
if (scrState==0)
oScr=new OpenScreen();
oScr.run();
else if (scrState==1)
rScr=new ReadyScreen();
rScr.run();
}
A_OpenScreen:
class OpenScreen {
//***local variables
PFont main_font;
PFont title_font;
//***constructor
OpenScreen() {
main_font=loadFont("v_font.vlw");
title_font=loadFont("titleText.vlw");
textAlign(CENTER);
background(0);
}
//***function
void run() {
display();
bottomText();
titleText();
}
void display() {
fill(255);
rectMode(CENTER);
//bottom rect
rect(width/2, height-height/8, width-width/4, height/10);
}
void bottomText() {
fill(255, 15, 10);
textFont(main_font, 14);
text("Test your reation skills and be the best on the laederboard.", width/2, height-12-height/8);
text("--PRESS ANY KEY TO CONTINUE--", width/2, height+12-height/8);
}
void titleText() {
fill(255, 157, 0);
textFont(title_font, 42);
text("VELOCE-REACTOR", width/2, height/6);
}
}
B_ReadyScreen
class ReadyScreen {
//***local variables
PFont main_font;
// ***constructor
ReadyScreen(){
smooth();
background(0);
main_font=loadFont("v_font.vlw");
textAlign(CENTER);
rectMode(CENTER);
}
//***functions
void run(){
indicate();
indicateText();
instructText();
}
void indicate(){
fill(255,0,0);
rect(width/2,height/2, width-width/8,height/4);
}
void indicateText(){
fill(255);
textFont(main_font, 32);
text("READY?", width/2, height/6);
}
void instructText(){
fill(255);
textFont(main_font, 20);
text("Feeling alert? Click anywhere to Start!", width/2, height-12-height/8);
}
}
C_SteadyScreen
class SteadyScreen {
//***local variables
PFont main_font;
// ***constructor
SteadyScreen(){
background(0);
smooth();
main_font=loadFont("v_font.vlw");
textAlign(CENTER);
rectMode(CENTER);
}
//***functions
void run(){
indicate();
indicateText();
instructText();
}
void indicate(){
fill(240,132,0);
rect(width/2,height/2, width-width/8,height/4);
}
void indicateText(){
fill(255);
textFont(main_font, 32);
text("STEADY!!", width/2, height/6);
}
void instructText(){
fill(255);
textFont(main_font, 20);
text("When the light goes green, click fast!", width/2, height-12-height/8);
}
}
D_GoScreen
class GoScreen {
//***local variables
PFont main_font;
// ***constructor
GoScreen(){
background(0);
smooth();
main_font=loadFont("v_font.vlw");
textAlign(CENTER);
rectMode(CENTER);
}
//***functions
void run(){
indicate();
indicateText();
instructText();
}
void indicate(){
fill(11,240,0);
rect(width/2,height/2, width-width/8,height/4);
}
void indicateText(){
fill(255);
textFont(main_font, 32);
text("GO! GO! GO!", width/2, height/6);
}
void instructText(){
fill(255);
textFont(main_font, 20);
text("CLICK NOW!", width/2, height-12-height/8);
}
}
I would HUGELY appreciate any help at all with this as I've got into a bit of a rabbit hole and keep trying the same things that just don't work. Sorry if it's something really obvious and I've missed something wildly obvious that's been mentioned on another thread.
1