-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·63 lines (53 loc) · 1.65 KB
/
Copy pathmain.py
File metadata and controls
executable file
·63 lines (53 loc) · 1.65 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
#!/usr/bin/env python
"""Main script entry point."""
import logging
import sys
import warnings
import tcod.context
import tcod.tileset
import g
import game.monsters
import game.state
import game.states
import game.world_logic
import game.world_tools
def handle_state(result: game.state.StateResult) -> None:
"""Apply StateResult effects."""
match result:
case game.state.Push(state):
g.state.append(state)
case game.state.Pop():
g.state.pop()
case game.state.Reset(state):
g.state = [state]
case None:
pass
case _:
raise AssertionError()
if hasattr(g, "world"):
game.world_logic.until_player_turn(g.world)
def main() -> None:
"""Program entry point."""
tileset = tcod.tileset.load_tilesheet("data/dejavu16x16_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD)
with tcod.context.new(
tileset=tileset,
width=1280,
height=720,
title=None,
vsync=True,
) as g.context:
g.world = game.world_tools.new_world()
g.state = [game.states.MainMenu()]
while True:
console = g.context.new_console(30, 20)
g.state[-1].on_draw(console)
g.context.present(console, keep_aspect=True, integer_scaling=True)
for event_pixels in tcod.event.wait():
event_tiles = g.context.convert_event(event_pixels)
handle_state(g.state[-1].on_event(event_tiles))
if __name__ == "__main__":
if __debug__:
logging.basicConfig(level=logging.DEBUG)
if not sys.warnoptions:
warnings.simplefilter("default")
main()