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);
fill(0);
textAlign(LEFT, TOP);
textSize(20);
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

Posted by digulla