PART TEN
STATES
TITLE
Add a Title Gamestate
As you did in Screensaver previously, you'll want to make another game state. This consists of two steps:
Create class Title which extends BasicGameState
Edit class Main to include Title state
Priority
We want to make our program start on the title
In Main
Set GAME_ID to 1 and TITLE_ID to 0
In initStatesList(), add title BEFORE adding game.
Make Your Title
Find or design a title screen image.
Add that image to your program and render it in Title.
This is a good time to come up with a proper name for your own game, rather than simply "FarmSim"
State Transitions
In the Title class, in the keyPressed method, if the user presses any key...
Switch the active state to Game
Some recommendations:
Your image should have your game's title as part of the image, rather than drawing it using code.
Your image should not have buttons drawn onto it. Later on, we'll add in Button objects that can be clicked.
CHECKPOINT
Run your code and see...
Move from the title state to Gameplay to make sure that it can transition
SHOP
Add a Shop Gamestate
Repeat this process creating a new state for Shop
SHOP_ID should be 2
Find a simple background for your shop and render it in the Shop state.
Don't stress about this too much, you will almost certainly change this later once we add in text and buttons and the UI gets more complicated.
State Transitions
In class Game, in the keyPressed method, if the user presses E...
Switch the active state to Shop
Tell your items to clearSelection() and setCursor()
This keeps us from having active tools in the shop
In class Shop, in the keyPressed method, if the user presses E...
Switch the active state to Game
CHECKPOINT
Run your code and see...
Your program should be able to go from Gameplay to Shop and back