Writing Games with Processing: Highscore!

22. December, 2013

What’s a game without a score? Boring!

Luckily, adding scoring to our game is a piece of cake. We just count the number of moves that Platty survives.

For this, we need another global variable:

int tileSize = 20;
int score = 0;

Then in the collision check, we increment the score:

  score ++;
  if(notFighting == 0) {

and lastly, we display score in drawBackground():

void drawBackground() {
  fill(174, 204, 27);
  rect(0, 0, width, height);
  textAlign(LEFT, TOP);
  text("Scrore: "+score, 2, 2);

That’s it. Can you beat my high score?


That’s it. Complete game in 210 lines of code.

Next: Time to clean up.

Previous: Winning
First post: Getting Started