forked from sirvaulterscoff/darktower-rl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·78 lines (62 loc) · 1.83 KB
/
main.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
#! /usr/bin/env python
from critters import *
from dungeon_generators import *
import game_input
from gui import LibtcodGui
from game_input import *
from features import *
from map import Map
def main_loop():
while gl.__game_state__ == "playing" and not gui.window_closed():
gui.render_all(map, player)
if gl.__show_chapter__:
gui.render_intro(gl.__chapter_text__)
gl.__show_chapter__ = None
gui.clear_all(map.map_critters)
gui.render_ui(player)
key = game_input.readkey()
handle_key(key)
for critter in map.map_critters:
if gl.__game_state__ == "died":
break
critter.take_turn()
game_input.readkey()
def handle_key(key):
command = parse_key(key)
if command is None: return
if isinstance(command, str):
globals()["handle_" + command]()
else:
name, args = command
globals()["handle_" + name](*args)
def handle_move(dx, dy):
if gl.__game_state__ == "playing":
if player.move(dx, dy):
gl.__fov_recompute__ = True
gl.__turn_count__ += 1
def handle_quit():
gl.__game_state__ = "quit"
def handle_wizard():
gl.__wizard_mode__ = True
def handle_wait():
if gl.__game_state__ == "playing":
gl.__turn_count__ += 1
#TODO handle wait properly
if __name__ == "__main__":
gui = LibtcodGui()
player = Player()
critters = [player]
dg = CaveGenerator(40, 25)
dg.generate()
#map = dg.finish()
#map = Map(dg.finish())
# dg = RoomsCoridorsGenerator(80, 40)
# dg.generate()
# map = Map(dg.finish())
# dg = StaticGenerator()
# dg.generate()
map = Map(dg.finish(), player)
map.place_monsters()
map.init_fov()
player.x, player.y = find_passable_square(map.map)
main_loop()