time stop with key pressed
in
Programming Questions
•
2 years ago
hello
I have a problem, I would like to stop the timer when I press a key.
I know I need to use the function "keyPressed" but I can't do it... Can you please help me?
Thanks!
I have a problem, I would like to stop the timer when I press a key.
I know I need to use the function "keyPressed" but I can't do it... Can you please help me?
Thanks!
- //timer
int l; - //time
int seconde = 0; - //display score and attempts's number
void score() {
fill(255);
//results display
text(score, -0.25*width_size, 0.565*height_size);
text(essais, 0.12*width_size, 0.565*height_size);
}
//controls if a fiduciary is on the right planet or not and flash in green or in red
void flashing() {
//-1 for the loop "for"
int myObjSize=myObj.size();
int planetsPropsSize=planetsProps.size();
//time in milliseconds
int timer = millis();
int a=timer/1000;
//time is seconds
float k=timer/1000;
//yellow rectangle to follow a fiducial
fill(255, 255, 0, 100);
//rect(objectPositionX, (objectPositionY-50), 80, 80);
rect(objectPositionX-30, objectPositionY-30, 60, 60);
//initializing score
score=0;
//for each PLANET
for (int j = 0; j < planetsPropsSize; j++) {
//table with planets properties
tobj0 = (ArrayList)planetsProps.get(j);
// An ArrayList doesn't know what it is storing so we have
// to cast the object coming out
//center of the planet X and Y
Float planetX = (Float) tobj0.get(0);
Float planetY = (Float)tobj0.get(1);
//width of the planet
Float planetW=(Float)tobj0.get(2);
//height of the planet
Float planetH=(Float)tobj0.get(3);
//status of the fiducial moving on the table
String statusP = (String)tobj0.get(5);
String statusNew = "none";
//go through each object and check if there is any on the planet
//for ( int i=0; i < myObjSize; i++) {
for ( int i=0; i < myObj.size(); i++) {
//chosen object
currentObjectOnTable = (TuioObject)myObj.get(i);
//object's position
objPosition = currentObjectOnTable.getPosition();
objectPositionX = ((objPosition.getX()+tx)*width_size*scaleFact)-330; // <==
objectPositionY = ((objPosition.getY()+ty)*height_size*scaleFact)-300; // <==
//check if the object is on the planet
//if (sqrt(((objectPositionX+40)-planetX)*((objectPositionX+40)-planetX) + ((objectPositionY-40)-planetY)*((objectPositionY-40)-planetY)) <= planetW/2 ) {
if (sqrt(((objectPositionX)-planetX)*((objectPositionX)-planetX) + ((objectPositionY)-planetY)*((objectPositionY)-planetY)) <= planetW/2 ) {
//don't fill the ellipse j
noFill();
//check fiducial's number and it's the good one
if (currentObjectOnTable.getSymbolID()==j) {
statusNew = "correct";
//modify the status to "correct"
if (!statusP.equals("correct"))
{
tobj0.set(5, "correct");
//println("planet " + j + " is " + (String)tobj0.get(5));
}
//increment score
score+=1;
//display a green circle
stroke(174, 221, 60); //outine green
ellipse(planetX, planetY, planetW, planetH);
break;
}
//check fiducial's number and it's not the good one
else {
statusNew = "false";
//display a red circle
stroke(254, 0, 0); //outine red
ellipse(planetX, planetY, planetW, planetH);
//changes the status of discovery of planet to "false"
if (!statusP.equals("false"))
{
//println("last frame was " + statusP);
essais+=1;
tobj0.set(5, "false");
//println("planet " + j + " is " + (String)tobj0.get(5));
break;
}
break;
}
}
} //endfor each object
//check if no object was found on the planet
if (statusNew.equals("none")) {
tobj0.set(4, "0");
tobj0.set(5, "none");
//println("planet " + j + " is " + (String)tobj0.get(5));
}
} //endfor each planet
//display score and attempts's number
score();
//time
if (k>=0) {
l=timer/1000;
//text(l, 0.5*width_size, 0.565*height_size);
text(l, 0.5*width_size, 0.565*height_size);
}
//sound when the time is finished
if (timer/1000==60) {
if (ping.isPlaying()==false) {
ping.play();
}
}
}
1