Game Development in Android using Libgdx Part X

In this tutorial we will be updating the different game states depending on time/enemy collision/star collections. We will edit the LevelManager class to handle changes.

public class LevelManager{
      public Boolean IsPaused;
      Boolean levelWon;
      Boolean gameOver;
      public void Update(float dt){
               if(!isPaused && !gameOver){
      public void Reset(){
               //Init all the game variables like mobs/stars etc
      public void SetTime(float timeLimit){
      public void Resume(){
      public void Pause(){
      public Boolean IsGameOver(){
           return gameOver;
      public Boolean IsLevelWon(){
           return levelWon;

So when we parse levels we can set the stars values and time limit for the level in this class’s object and call its update in game’s update function. In every frame we check for gameOver in main update funciton. If it is true then we check if level is Won or not and depending on that we generate a pause/restart/next level popup/screen.

Temporary Invincibility:

This was a feature we added to the protagonist, so that when it hits the laser or other enemies it doesn’t get hurt in a short span twice. This feature is usually present in many games and it is a really simple feature to add. Here is a snippet of how we applied it in our game.

public Timer InvincibleTimer;
public void AddDamage(){
            //Add damage to hero

So if hero collides in a span shorter then the invincibleTimer time limit then it won’t add damage to the hero.

Next Tutorial:

Next tutorial would be short one on how to handle the back key event in android.

Let us know any of your doubts/suggestions; please put them in the comments section and we would try to answer them.

Thank you for the patience.

Tagged with: , , , ,
Posted in Tutorials
2 comments on “Game Development in Android using Libgdx Part X
  1. Kevin says:

    Method Resume should not set isPaused to false? (it’s set to true in both Resume() and Pause() )

    • Rahul Srivastava says:

      Thanks for pointing out the typo. Yes in Resume isPaused should be set to false. Updated it in the post.

Try our games

Error: Twitter did not respond. Please wait a few minutes and refresh this page.