Enum in PyGame
Import Enum
Before you can use Enums in python or pygame we need to import the correct module, so you will need to add:
from enum import Enum
Declaring Enum
Enum is used has a base class for your Enum:
class State(Enum):
ONE = 1
TWO = 2
THREE = 3
Using Your Enum
You can create a variable and assign it one of your Enum states, you will also be able to access the name and value:
GAMESTATE = State.ONE
print(GAMESTATE.name)
print(GAMESTATE.value)
Within your game loop you can actually check your GAMESTATE and run the appropriate code:
if GAMESTATE == State.ONE:
print('State ONE')
elif GAMESTATE == State.TWO:
print('State TWO')
elif GAMESTATE == State.THREE:
print('State THREE')