# Creating a Scoreboard for Simple Game

**URL:** <https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075>\
**Category:** Electronics (Arduino, etc.)\
**Tags:** homework\
**Created:** [October 4, 2022, 1:31pm UTC](https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075 "2022-10-04T13:31:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeydew](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@honeydew](https://discourse.processing.org/u/honeydew)\
**Post date:** [October 4, 2022, 1:31pm UTC](https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075/1 "2022-10-04T13:31:17Z")

</div>

Hi guys, I’m new to this forum so I’m not really sure how to post my code properly. I’m trying to make a game where a character, Steve, runs around and collects food. Whenever he runs over a piece of food, the food reappears somewhere else. How do I make a scoreboard that goes up by 1 every time he runs over the food? Thank you for your help.

```auto
import processing.serial.*;
Serial myPort;

int SteveX = 500;
int SteveY = 500;
int SteveWidth = 30;
int SteveHeight = 30;
int foodWidth = 10;
int foodHeight = 10;
float foodX = random(1000-foodWidth);
float foodY = random(1000-foodHeight);
int buttonVal = 0;
int speed = 5;
color bgcolor = color(255, 204, 100);

void setup(){
  size(1000,1000);
  strokeWeight(4);
  println("Available serial ports:");
  println(Serial.list());
  
  myPort = new Serial(this, "COM13", 9600);
}

void draw(){
  background(bgcolor);
  
  if(myPort.available() > 0){
    buttonVal = myPort.read();
    println(buttonVal);
  }
rect(SteveX, SteveY, SteveWidth, SteveHeight);

if(buttonVal >= 254){
  SteveX = SteveX-speed;
}
else if((buttonVal >= 249) && (buttonVal <= 251)){
  SteveY = SteveY-speed;
}
else if((buttonVal >= 126) && (buttonVal <= 129)){
  SteveX = SteveX+speed;
}
else if((buttonVal < 3) && (buttonVal > 0)){
  SteveY = SteveY+speed;
}

rect(foodX, foodY, foodWidth, foodHeight);

if((foodX > SteveX-foodWidth) && (foodX < SteveX+SteveWidth) && (foodY < SteveY+SteveHeight) && (foodY > SteveY-foodHeight)){
  foodX = random(1000-foodWidth);
  foodY = random(1000-foodHeight);
}

if(SteveX<0){
  SteveX=0;
}
if(SteveX>1000-SteveWidth){
  SteveX=1000-SteveWidth;
}
if(SteveY<0){
  SteveY=0;
}
if(SteveY>1000-SteveHeight){
  SteveY = 1000-SteveHeight;
}
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 9, 2022, 11:45pm UTC](https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075/2 "2022-10-09T23:45:20Z")

</div>

Hi  
Format your code using preformatted text

 ![Screenshot_2022-10-06-21-58-07-752](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/b/6bcf98af246fb323b199ea5ecb5bcbcf9bddaa71.jpeg)

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [October 10, 2022, 2:48am UTC](https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075/3 "2022-10-10T02:48:22Z")

</div>

Hello @honeydew

This previous forum topic may give you some ideas on how to proceed implementing a scoreboard:

> [@Score counter Help](https://discourse.processing.org/t/score-counter-help/11587):
>
> Hi, i have made a program to where balls would enter a basket and for every ball that enters (5 balls) + 10 to the counter and the balls would reset to the start. I made my balls in an array: Ball[] bballs = new Ball[5]; void setup(){ size(640,480); // create balls for(int i = 0; i\<bballs.length; i++) { bballs[i] = new Ball(); } } The problem is that when all the balls are sent into the basket at the same time, the counter would only update by +10 instead of +50. If 1 ball w…

Hope this helps!  
🤓

---

<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:** [October 10, 2022, 2:19pm UTC](https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075/4 "2022-10-10T14:19:32Z")

</div>

First you need an int variable to keep track of the score

Where you increase the score say score++; once

To make a high score you need a separate state to  
Display the High Score

You also need a was to enter a player Name  
(which is also a new state of the program)

When you want to see the old high score when you start the program again/ on the next day, you need to save it on your hard drive (look at saveStrings() command in the reference)

To use it over the web, you need to store it in the web

---

<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:** [October 10, 2022, 2:22pm UTC](https://discourse.processing.org/t/creating-a-scoreboard-for-simple-game/39075/5 "2022-10-10T14:22:13Z")

</div>

> [@honeydew](#):
>
> foodX = random(1000-foodWidth);  
> foodY = random(1000-foodHeight);

Here apparently you want to say  
score++;

Use `fill(150); text(score,17,17);` in the main section (not in the if clause obviously) to display the text throughout

Before setup () ::: `int score=0;`
