# Adding collisions and a scoreboard

**URL:** <https://discourse.processing.org/t/adding-collisions-and-a-scoreboard/15584>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 17, 2019, 4:07pm UTC](https://discourse.processing.org/t/adding-collisions-and-a-scoreboard/15584 "2019-11-17T16:07:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snyke123](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@snyke123](https://discourse.processing.org/u/snyke123)\
**Post date:** [November 17, 2019, 4:07pm UTC](https://discourse.processing.org/t/adding-collisions-and-a-scoreboard/15584/1 "2019-11-17T16:07:41Z")

</div>

Hey for a school project I am making a little game where you control a spaceship with your mouse and you have to go between the walls. If you hit one of the walls you fail. (It is like a flappy bird game)  
But the problem is that I cannot find how to put a scoreboard and I am also struggling with making a collision detector on the walls that are moving.

Here is my code:

```auto
PImage arriereplan;
PImage oiseau;
PImage comete;
PImage depart;

PFont dream;
PFont BebasNeue;

int gamestate = 1;
int score = 0;
int highScore =0;
int x= -200, y;
int[] wx= new int[2];
int[] wy= new int[2];

void setup() {
  size(852,480);
  fill(255);
  textSize(40);
  frameRate(60);
  oiseau = loadImage("Sans titre-1.png");
  arriereplan = loadImage("28592983256_79fcee4451_b.jpg");
  depart = loadImage("depart.jpg");
  comete = loadImage("Sans titre-3.jpg");
  dream = createFont("Dream MMA.ttf",50);
  BebasNeue = createFont("Dream MMA.ttf",50);
}

void draw() { //runs 60 times a second
  if(gamestate == 0) {
    text("Space Rocket" , width/2, height/2);
    imageMode(CORNER);
    image(arriereplan, 0, 0);
    image(oiseau, width/2, y);
    x = mouseX;
    y = mouseY;
    for(int i = 0 ; i < 2; i++) {
      imageMode(CENTER);
      image(comete, wx[i], wy[i] - (comete.height/2+75));
      image(comete, wx[i], wy[i] + (comete.height/2+75));
      if(wx[i] < 0) {
        wy[i] = (int)random(50,height-50);
        wx[i] = 852;
      }
      wx[i] -= 5;
      if(wx[i] == 0) highScore = max(++score, highScore);
      if(y>height||y<0||(abs(width/2-wx[i])<25 && abs(y-wy[i])>100)) gamestate=1;
        text(""+score, 780, 460);
    }
}

  else {
    imageMode(CENTER);
    image(depart, width/2,height/2);
    textFont(dream);
    text("space rocket", 160, 190);
        textSize(35);
    text("play", 160, 270);
      textSize(35);
    text("high score: "+highScore, 350, 270); //display the score
    rect(145, 230, 170, 55);
        noFill();
        stroke(255);
  }
}
void mousePressed() {
  if(gamestate==1) {
    wx[0] = 600;
    wy[0] = y = height/2;
    wx[1] = 900;
    wy[1] = 600;
    x = gamestate = 0;
  }
}

```

---

<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:** [November 17, 2019, 6:12pm UTC](https://discourse.processing.org/t/adding-collisions-and-a-scoreboard/15584/2 "2019-11-17T18:12:51Z")

</div>

Hello and welcome to the forum!

Nice to have you here!

For collision you can check whether the y pos of the bird is \> than the upper side of the wall and \< its lower side

Also the x must be near the wall x - 10 or so

So it’s if(birdX\>…

**Score**

(You have this already I see)

You can have a lives counter or so and set your gameState to 1

In draw() add

```auto
else if (gameState==1) {

//Show a score screen 

}

```
