Here, we will add some logic to the game such as searching for doors that have goats behind them and the addition of game states for easy management of the code.
First of all, we need to declare a Boolean variable in our
Door class called
isGoat so that we can determine whether a goat is behind the door:
public boolean isGoat = false; // indicates whether a goat is behind the door public Vector2 position =new Vector2(); // position of the door //door dimensions public float height;
Next, we need to set this variable for each door appropriately in the
initDoors() method of the
doors.get(0).openSprite.setRegion(goatTexture); doors.get(0).isGoat= true; doors.get(1).openSprite.setRegion(carTexture); ...