# How do I make my score for the game increase by 1 and have it displayed on the bottom corner?

**URL:** <https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160>\
**Category:** Beginners\
**Created:** [May 28, 2022, 9:22am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160 "2022-05-28T09:22:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 9:22am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/1 "2022-05-28T09:22:27Z")

</div>

Hi! I am stuggling with a project I have. I have a game whereby the pedestrian has to pass through lanes without hitting the vehicle and once it does, I need for the scores to go up by 1. I am unsure as to how to do the scores part. Does anyone know how to do that?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 9:58am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/2 "2022-05-28T09:58:37Z")

</div>

It is hard to say without seeing your code

**To Do**

Before setup ()

int score=0;

When the player crossed the street say score++;

To display it:

fill(255,111,3); // or something  
text(score, 20, height-25);

It might be the case that one crossing gives you score 60 or so. In this case you need an if clause where you check the crossing (if (playerY\<10) or something) and then you increase the score and reset playerY so that the if clause no longer applies: playerY=height-25; or so

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 10:05am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/3 "2022-05-28T10:05:34Z")

</div>

This is my coding for displaying the score:  
\<  
// Display score  
textSize(25);  
textAlign(RIGHT, BOTTOM);  
text(“Score:”, width-35, height-10);

> 

I need to use an if statement for the scores. So far I have thought of this:

- pedY is the y value of the pedestrian.
- 0 is the top of my window size

\< if (pedY \< 0); {  
} \>

How do I implement what you said into this. Is there any other codes you need to help you understand my situation better?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 10:08am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/4 "2022-05-28T10:08:26Z")

</div>

??

Just follow the steps I gave you

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 10:08am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/5 "2022-05-28T10:08:55Z")

</div>

New variable score before setup etc.

It’s a to do list for you

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 10:11am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/6 "2022-05-28T10:11:20Z")

</div>

> [@itisti21](#):
>
> if (pedY \< 0); {

No semicolon here!!!

```auto
if (pedY < 0) { //!!!!!
    score++;
    pedY=height-25;
}

```

**And**

`text("Score: "+score, 20, height-25);`

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 10:20am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/7 "2022-05-28T10:20:20Z")

</div>

Thank you so much! Do you know why you put a +score in text? I am trying to understand the code before moving on.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 10:36am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/8 "2022-05-28T10:36:50Z")

</div>

The plus in this context is just joining the fixed word Score within " and " with the variable score so you get

Score: 3

for example

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 10:40am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/9 "2022-05-28T10:40:30Z")

</div>

oh okay thank you heaps for the help! Really helped me out.

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 10:59am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/10 "2022-05-28T10:59:09Z")

</div>

also so sorry to trouble you again. I’m having trouble with the resetting. When my pedestrain hits the vehicle, the pedestrian is meant to reset back to its original position. I made a function for this and it works. However my “game over” screen dissapears and it just resets. I want my screen to reset after the “game over” screen appears. I cannot use the delay statement for this as well as it is a text. I am thinking it is the positioning of my reset function which is not allowing my “game over” to show. Do you know what might be the case?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 11:19am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/11 "2022-05-28T11:19:07Z")

</div>

It would be best to set a variable showGameOverScreen  
When your player hits the screen

Then in draw() evaluate this variable and either show normal game OR the game over screen.

**Then**

Next step would be to use a function keyPressed() and inside it if(showGameOverScreen&&key==’ ') reset();

**Remark**

Remember that draw() runs 60 times per second and a function like game over screen doesn’t wait for something or so. It just runs. Therefore you need a distinction in draw() based on showGameOverScreen variable.

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 11:32am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/12 "2022-05-28T11:32:03Z")

</div>

When i set a showGameOverScreen as a char variable (char showGameOverScreen) , how do I include the fill, size and text font into it? because although i created a variable, it is not connected to the actual coding i have for the game over screen which is:

\<  
fill(255,0,0); //red background  
rect (0,0,1200, 400); // red background

// Game over text  
fill(0);  
textSize(40);  
text(“GAME OVER”, 500,200);

> 

I’m sorry I’m a little new at processing which is why it is taking me a while to understand what you are saying.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 11:36am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/13 "2022-05-28T11:36:18Z")

</div>

> [@itisti21](#):
>
> When i set a showGameOverScreen as a char variable

Okay say before setup ()

boolean showGameOverScreen=false;

Set it to true upon collision

showGameOverScreen=true;

In draw say

```auto
if(showGameOverScreen) {
  //Display game over screen 
  
fill(255,0,0); //red background
rect (0,0,1200, 400); // red background

// Game over text
fill(0);
textSize(40);
text(“GAME OVER”, 500,200);

} else {

// Game 
What you have in draw() now. The entire code inside draw()

}

```

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 11:46am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/14 "2022-05-28T11:46:21Z")

</div>

when you say the entire code inside draw do you mean everything. So like lane coding, vehicle drawings and all of that?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 11:48am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/15 "2022-05-28T11:48:58Z")

</div>

Yes.

Everything that’s not on the game over screen

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 11:51am UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/16 "2022-05-28T11:51:05Z")

</div>

so when i do copy all of that, do i leave the two copies or get rid of the one that is there currently and have it all under this code?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 12:01pm UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/17 "2022-05-28T12:01:06Z")

</div>

You MOVE the existing code in the new section

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 12:01pm UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/18 "2022-05-28T12:01:49Z")

</div>

Just make a copy or  
use menu tools | archive

and then try it

---

<div class="post-metadata">

**Author:** ![itisti21](https://avatars.discourse-cdn.com/v4/letter/i/8edcca/32.png) [@itisti21](https://discourse.processing.org/u/itisti21)\
**Post date:** [May 28, 2022, 12:04pm UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/19 "2022-05-28T12:04:36Z")

</div>

okay i will cut and paste into new section.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 28, 2022, 12:06pm UTC](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160/20 "2022-05-28T12:06:09Z")

</div>

You can just paste the new stuff above it and place  
} after it

[Next page](https://discourse.processing.org/t/how-do-i-make-my-score-for-the-game-increase-by-1-and-have-it-displayed-on-the-bottom-corner/37160.md?page=2)
