-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
70 lines (54 loc) · 2.27 KB
/
core.py
File metadata and controls
70 lines (54 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pygame
from engine.game_manager import GameManager
from engine.states.state_machine import StateMachine
from engine.states.state_ids import StateID
from engine.utils.exceptions import GameExitException
# Import all state classes
from engine.states.main_menu_state import MainMenuState
from engine.states.campaign_select_state import CampaignSelectState
from engine.states.load_game_state import LoadGameState
from engine.states.settings_state import SettingsState
from engine.states.campaign_state import CampaignState
from engine.states.gameplay_state import GameplayState
from engine.states.victory_state import VictoryState
def launch_game():
"""Main entry point with State Machine"""
game_manager = GameManager()
config = game_manager.get_config()
clock = pygame.time.Clock()
state_machine = StateMachine(game_manager)
# Register States
state_machine.register_state(StateID.MAIN_MENU, MainMenuState)
state_machine.register_state(StateID.CAMPAIGN_SELECT, CampaignSelectState)
state_machine.register_state(StateID.LOAD_GAME, LoadGameState)
state_machine.register_state(StateID.SETTINGS, SettingsState)
state_machine.register_state(StateID.CAMPAIGN, CampaignState)
state_machine.register_state(StateID.GAMEPLAY, GameplayState)
state_machine.register_state(StateID.VICTORY, VictoryState)
# Start with Main Menu
state_machine.change_state(StateID.MAIN_MENU)
running = True
print("Game started")
while running:
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
break
try:
state_machine.handle_event(event)
except GameExitException:
running = False
break
if not running:
break
# Update
time_delta = clock.tick(60) / 1000.0
state_machine.update(time_delta)
# Render
# TODO: Currently the render method is superflous, and could just be called from the update method, but it's theoretically nice to be able to call them independantly.
state_machine.render(time_delta)
pygame.display.flip()
pygame.quit()
if __name__ == "__main__":
launch_game()