-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.py
78 lines (53 loc) · 1.99 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
69
70
71
72
73
74
75
76
77
78
# The Lantern by Nicholas Achterberg
# 10:51 9/19/2019
#
# This is my first rogue-like game.
# The gameplay is focused around light, puzzles and fighting.
#
# I hope you enjoy :)
import libtcodpy as libtcod
from entity import Entity
from input_handlers import handle_keys
from map_objects.game_map import GameMap
from render_functions import clear_all, render_all
def main():
screen_w = 80
screen_h = 50
map_w = 80
map_h = 45
room_max_size = 10
room_min_size = 5
max_rooms = 35
colors = {
'dark_wall': libtcod.Color(0, 0, 100),
'dark_ground': libtcod.Color(50, 50, 150)
}
player = Entity(int(screen_w / 2), int(screen_h / 2), '@', libtcod.white)
npc = Entity(int(screen_w / 2 - 5), int(screen_h / 2), '@', libtcod.yellow)
entities = [npc, player]
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(screen_w, screen_h, 'The Lantern', False)
con = libtcod.console_new(screen_w, screen_h)
game_map = GameMap(map_w, map_h, circum, radius)
game_map.make_map(max_rooms, room_min_size, room_max_size, map_w, map_h, circum, radius, player)
key = libtcod.Key()
mouse = libtcod.Mouse()
while not libtcod.console_is_window_closed():
libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
render_all(con, entities, game_map, screen_w, screen_h, colors)
libtcod.console_flush()
clear_all(con, entities)
action = handle_keys(key)
move = action.get('move')
exit = action.get('exit')
fullscreen = action.get('fullscreen')
if move:
dx, dy = move
if not game_map.is_blocked(player.x + dx, player.y + dy):
player.move(dx, dy)
if exit:
return True
if fullscreen:
libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
if __name__ == '__main__':
main()