-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.py
68 lines (48 loc) · 1.69 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
66
67
68
import tdl
from entity import Entity
from input_handlers import handle_keys
from map_utils import make_map
from render_functions import clear_all, render_all
def main():
screen_width = 80
screen_height = 50
map_width = 80
map_height = 45
colors = {
'dark_wall': (0, 0, 100),
'dark_ground': (50, 50, 150)
}
player = Entity(int(screen_width / 2), int(screen_height / 2), '@', (255, 255, 255))
npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', (255, 255, 0))
entities = [npc, player]
tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)
root_console = tdl.init(screen_width, screen_height, title='Roguelike Tutorial Revised')
con = tdl.Console(screen_width, screen_height)
game_map = tdl.map.Map(map_width, map_height)
make_map(game_map)
while not tdl.event.is_window_closed():
render_all(con, entities, game_map, root_console, screen_width, screen_height, colors)
tdl.flush()
clear_all(con, entities)
for event in tdl.event.get():
if event.type == 'KEYDOWN':
user_input = event
break
else:
user_input = None
if not user_input:
continue
action = handle_keys(user_input)
move = action.get('move')
exit = action.get('exit')
fullscreen = action.get('fullscreen')
if move:
dx, dy = move
if game_map.walkable[player.x + dx, player.y + dy]:
player.move(dx, dy)
if exit:
return True
if fullscreen:
tdl.set_fullscreen(not tdl.get_fullscreen())
if __name__ == '__main__':
main()