-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.py
65 lines (57 loc) · 1.86 KB
/
engine.py
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
import tcod as libtcod
from graphics.render import Render
from stage.main_menu import MainMenuStage
from stage.game import GameStage
from stage.city import CityMenuStage
def main():
stages = {
'main_menu': MainMenuStage(),
'city': CityMenuStage(),
'game': GameStage()
}
current_stage = stages.get('main_menu')
render = Render()
render.start([
stages.get('main_menu').scene,
stages.get('city').scene,
stages.get('game').scene
])
player = None
entities = []
game_map = None
message_log = None
game_state = None
while True:
key_pressed = None
mouse_moved = None
mouse_clicked = None
next_stage = None
for event in libtcod.event.wait():
if event.type == "QUIT":
raise SystemExit()
if event.type == "KEYDOWN":
key_pressed = event.sym
if event.type == "MOUSEMOTION":
mouse_moved = event
if event.type == "MOUSEBUTTONDOWN":
mouse_clicked = event
result = current_stage.run((key_pressed, mouse_moved, mouse_clicked))
next_stage = result.get('next_stage')
if next_stage is not None:
render.clear()
args = result.get('args')
current_stage = stages.get(next_stage)
if args:
current_stage.load(args)
elif result.get('exit_game'):
raise SystemExit()
def get_names_under_mouse(mouse_moved, entities, fov_map):
if not mouse_moved:
return []
(x, y) = (mouse_moved.tile[0], mouse_moved.tile[1])
names = [entity.name for entity in entities
if entity.x == x and entity.y == y and libtcod.map_is_in_fov(fov_map, entity.x, entity.y)]
names = ', '.join(names)
return names.capitalize()
if __name__ == '__main__':
main()