Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
LibGDX Game Development By Example

You're reading from   LibGDX Game Development By Example Learn how to create your very own game using the libGDX cross-platform framework

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781785281440
Length 280 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
James Cook James Cook
Author Profile Icon James Cook
James Cook
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting to Know LibGDX FREE CHAPTER 2. Let's Get These Snakes Out of This Book! 3. Making That Snake Slick 4. What the Flap Is the Hype About? 5. Making Your Bird More Flightworthy 6. Onto the Next Platform...Game 7. Extending the Platform 8. Why Are All the Birds Angry? 9. Even Angrier Birds! 10. Exporting Our Games to the Platforms 11. Third-party Services Index

The state of the game

We now have our Snake game at the point where it is almost a complete game; we just need to add a few more things to achieve this. Currently, our game stops when the snake collides with itself. What we need to add is a way to restart the game if this happens, so the player can have another go!

To do this, we will do the following:

  • Adding a game state
  • Displaying game-over text
  • Restarting the game

Adding a state

When you think about it, a game can have many states. Seriously, pick one of your favorite games and consider the states the game could be in. Let's list some out:

  • Start
  • Playing
  • Paused
  • Game over
  • Restart

It could be argued that start and restart are the same thing, but that really depends on the game and what you, as the game developer, would like to achieve. For our little Snake game, we are only going to focus on two states for now: playing and game over.

Let's first start off by creating an enumeration of our states, and let's create a member of GameScreen...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime