Skip to Content
LibGDX Game Development By Example
book

LibGDX Game Development By Example

by James Cook
August 2015
Intermediate to advanced content levelIntermediate to advanced
280 pages
5h 31m
English
Packt Publishing
Content preview from LibGDX Game Development By Example

High scores

One of the final pieces is still missing from our Snake game; we don't have, or keep track of, any scoring! How is the player supposed to know how well they did when the game finishes?

The first step to solve this is to add a member to the GameScreen class called score, which we will add to the following:

private int score = 0;

But how much should we add? It is completely up to you, the game designer, how many points you want to give to the player. For the sake of simplicity, let's just say 20 points per apple collected. Feel free to change this later to whatever you like. Let's create a constant member:

private static final int POINTS_PER_APPLE = 20;

Next, let's create a method that can be called every time a player makes the snake collide ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering LibGDX Game Development

Mastering LibGDX Game Development

Patrick Hoey
Learning LibGDX Game Development- Second Edition

Learning LibGDX Game Development- Second Edition

Suryakumar B Nair, Andreas Oehlke

Publisher Resources

ISBN: 9781785281440Supplemental Content