If you want to draw your score every frame, then move the call that draws the score outside the if statement.
As for the ball, can you please be more specific? What exactly are you trying to do? Can you write out a series of steps, in English, that you want the ball to follow? Then think about implementing those steps in code.
Thankyou, yes I've tried any for some reason it still doesn't show. As for the ball, on my page number two I am going to continue with the loop, however this time I want it to enter the screen at random times to be unexpected. I presume this would be random number generating? But I'm clueless as to how to do that.
Thankyou Chrisir, the score is now showing at all times, but (1) still has some problems as the score keeps rising on its own even when the button isn't being pressed.
Thankyou Chrisir! This worked for the first part so that section is now up and running. (1) is now the first page, now I've added a second page where I want to bring in the timer for the loop to make it more difficult (next level etc), however I'm struggling to understand which parts of (2) I need to add into the second page to make it work? Apologies again for any misunderstanding.
The variable timerIsOn is dictating this behaviour of making the ball wait before it re-appears.
When we wait for the ball to appear timerIsOn is true: which is written as if (timerIsOn) { which means the same as if (timerIsOn==true) {.
Now, let's see, we have two situations:
timerIsOn is true (we wait and show no ball) and
timerIsOn is false, we run and show the ball.
When does timerIsOn change?
As soon as the ball leaves the screen, we set timerIsOn to true, saying the program: wait and don't show the ball. We do some preparations here, e.g. set the variables wait and timer and we say circX=0;.
When the random time stored in wait has passed, we start the the next ball by saying timerIsOn=false;.
Because of the imporance of timerIsOn the code below falls in two parts:
if (timerIsOn) {
// wait for the ball
} else {
// ball runs !!! timerIsOn==false
}
You need :
if (timerIsOn) {
// wait for the ball
// display the scene (red circle etc.)
fill(255);
textSize(45);
text (score, 267, 146);
fill (194, 49, 49);
ellipse (301, 300, 255, 255);
if (millis()-timer>wait) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
timerIsOn=false;
}
} else {
// ball runs !!! timerIsOn==false
// normal stuff: display ball etc.
if (circX > 500) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
circX=0;
timerIsOn=true; // !!!!!!!!!!!!!!!!!!!!
timer=millis();
wait=int(random(90, 4900)); // these are millis
}
}//else timer
Is the code from 'you need:' ^ the only code I need within page 2?
??
No, not at all. Above is a full sketch that shows the entire thing (from January 4th).
the code from 'you need' is only the core idea regarding the timer. I shortened it to make it easier for you to read. Especially I deleted the section with normal stuff: display ball etc.
You really need to read and learn my code please. Not only copy it....
Answers
If you want to draw your score every frame, then move the call that draws the score outside the
if
statement.As for the ball, can you please be more specific? What exactly are you trying to do? Can you write out a series of steps, in English, that you want the ball to follow? Then think about implementing those steps in code.
you can hit ctrl-t to get better indents automatically
Thankyou, yes I've tried any for some reason it still doesn't show. As for the ball, on my page number two I am going to continue with the loop, however this time I want it to enter the screen at random times to be unexpected. I presume this would be random number generating? But I'm clueless as to how to do that.
this should give you (1)
this shows (2)
a timer with a random value let's the ball wait before it starts at 0 again
(I deleted the arduino stuff to be able to run the sketch)
post your entire sketch when asking something please
Thankyou Chrisir, the score is now showing at all times, but (1) still has some problems as the score keeps rising on its own even when the button isn't being pressed.
For (1): This line:
score++;
belongs into the if-clause and not outside of it then.Thankyou Chrisir! This worked for the first part so that section is now up and running. (1) is now the first page, now I've added a second page where I want to bring in the timer for the loop to make it more difficult (next level etc), however I'm struggling to understand which parts of (2) I need to add into the second page to make it work? Apologies again for any misunderstanding.
The variable
timerIsOn
is dictating this behaviour of making the ball wait before it re-appears.When we wait for the ball to appear
timerIsOn
is true: which is written asif (timerIsOn) {
which means the same asif (timerIsOn==true) {
.Now, let's see, we have two situations:
When does timerIsOn change?
As soon as the ball leaves the screen, we set timerIsOn to true, saying the program: wait and don't show the ball. We do some preparations here, e.g. set the variables
wait
andtimer
and we saycircX=0;
.When the random time stored in
wait
has passed, we start the the next ball by sayingtimerIsOn=false;
.Because of the imporance of timerIsOn the code below falls in two parts:
You need :
you also need some vars:
Ok thank you I really appreciate the detail. Is the code from 'you need:' ^ the only code I need within page 2?
you wrote:
??
No, not at all. Above is a full sketch that shows the entire thing (from January 4th).
the code from 'you need' is only the core idea regarding the timer. I shortened it to make it easier for you to read. Especially I deleted the section with normal stuff: display ball etc.
You really need to read and learn my code please. Not only copy it....