-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.py
More file actions
155 lines (142 loc) · 6.99 KB
/
map.py
File metadata and controls
155 lines (142 loc) · 6.99 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from map_obj import *
from funcs import *
from settings import default_player_pos
from menu import start_menu
quitting = False
def start_map(gfx, text, choice, top_lf, btm_rt, size, objects, player):
main_map = area = Map(size[0], size[1], objects)
y_now, x_now = 0, 0
forbidden = {}
step_event = {}
doors = {}
triggers = {}
for o in main_map.obj:
if o.block:
for y in range(o.start_y, o.start_y + len(o.string_shown.split('\n'))):
for x in range(o.start_x, o.start_x + len(o.string_shown.split('\n')[0])):
if o.door and (y - o.start_y, x - o.start_x) == o.door['pos']:
doors[(y, x)] = (o.door['map'], o.door['exit'], o.door['transport'],
(o.door['pos'][0] + o.start_y + 1, o.door['pos'][1] + o.start_x))
else:
forbidden[(y, x)] = o
if isinstance(o, Interactive) and o.detect:
is_x = o.detect[0] == 'x'
main_axis = eval("o.start_%s" % o.detect[0])
other_axis = eval("o.start_%s" % {'x': 'y', 'y': 'x'}[o.detect[0]])
for i in range(main_axis, main_axis + o.detect[1]):
triggers[(other_axis, i) if is_x else (i, other_axis)] = o
elif isinstance(o, Interactive):
for y in range(o.start_y, o.start_y + len(o.string_shown.split('\n')) - 1):
for x in range(o.start_x, o.start_x + len(o.string_shown.split('\n')[0])):
step_event[(y, x)] = o
main_map.pd.erase()
for o in main_map.obj:
for i, line in enumerate(o.string_shown.split('\n')):
main_map.pd.addstr(o.start_y + i, o.start_x, line)
main_map.pd.addstr(player.start_y, player.start_x, player.string_shown)
main_map.pd.refresh(y_now, x_now, top_lf[0], top_lf[1], btm_rt[0], btm_rt[1])
def quit_game():
global quitting
quitting = True
def check_trigger():
if (player.start_y, player.start_x) in triggers:
triggers[(player.start_y, player.start_x)]\
.on_interacted_with(player, gfx, text, choice)
elif (player.start_y, player.start_x) in step_event:
step_event[(player.start_y, player.start_x)]\
.on_interacted_with(player, gfx, text, choice)
def refresh_map():
main_map.pd.erase()
for map_obj in main_map.obj:
for line_num, line_content in enumerate(map_obj.string_shown.split('\n')):
main_map.pd.addstr(map_obj.start_y + line_num, map_obj.start_x, line_content)
main_map.pd.addstr(player.start_y, player.start_x, player.string_shown)
main_map.pd.refresh(y_now, x_now, top_lf[0], top_lf[1], btm_rt[0], btm_rt[1])
looking_at = None
while True:
refresh_map()
gfx.refresh()
ch = gfx.getch()
if ch in (c.KEY_UP, 450):
if y_now > 0 and (player.start_y - 1, player.start_x) not in forbidden:
y_now -= 1
refresh_map()
check_trigger()
if player.start_y > 0:
if (player.start_y - 1, player.start_x) in forbidden:
looking_at = forbidden[(player.start_y - 1, player.start_x)]
else:
looking_at = None
player.start_y -= 1
elif ch in (c.KEY_DOWN, 456):
if default_player_pos[0] <= player.start_y < main_map.height - 2\
and (player.start_y + 1, player.start_x) not in forbidden:
y_now += 1
refresh_map()
check_trigger()
if player.start_y < main_map.height - 2:
if (player.start_y + 1, player.start_x) in forbidden:
looking_at = forbidden[(player.start_y + 1, player.start_x)]
else:
looking_at = None
player.start_y += 1
elif ch in (c.KEY_LEFT, 452):
if x_now > 0 and (player.start_y, player.start_x - 1) not in forbidden:
x_now -= 1
refresh_map()
check_trigger()
if player.start_x > 0:
if (player.start_y, player.start_x - 1) in forbidden:
looking_at = forbidden[(player.start_y, player.start_x - 1)]
else:
looking_at = None
player.start_x -= 1
elif ch in (c.KEY_RIGHT, 454):
if default_player_pos[1] <= player.start_x < main_map.width - 2\
and (player.start_y, player.start_x + 1) not in forbidden:
x_now += 1
refresh_map()
check_trigger()
if player.start_x < main_map.width - 2:
if (player.start_y, player.start_x + 1) in forbidden:
looking_at = forbidden[(player.start_y, player.start_x + 1)]
else:
looking_at = None
player.start_x += 1
elif ch in (c.KEY_ENTER, 10):
if isinstance(looking_at, Interactive):
looking_at.on_interacted_with(player, gfx, text, choice)
elif ch == ord('x'):
start_menu((1, 64), (12, 78), {'q': 'CREAGRAMS', 'w': 'BAG', 'e': 'QUIT GAME'},
{'q': lambda: cg_menu(gfx, text, choice, player),
'w': lambda: item_menu(gfx, text, choice, player),
'e': quit_game})
global quitting
if quitting:
break
if (player.start_y, player.start_x) in doors:
to_go = doors[(player.start_y, player.start_x)]
main_map = to_go[0]
player.start_y, player.start_x = to_go[2]
y_now, x_now = 0, 0
gfx.erase()
forbidden = {}
doors = {(to_go[1]): (area, None, to_go[3], None)}
for o in main_map.obj:
if o.block:
for y in range(o.start_y, o.start_y + len(o.string_shown.split('\n'))):
for x in range(o.start_x, o.start_x + len(o.string_shown.split('\n')[0])):
if o.door and (y - o.start_y, x - o.start_x) == o.door['pos']:
doors[(y, x)] = (o.door['map'], o.door['exit'], o.door['transport'],
(o.door['pos'][0] + o.start_y + 1,
o.door['pos'][1] + o.start_x))
else:
forbidden[(y, x)] = o
triggers = {}
for o in main_map.obj:
if isinstance(o, Interactive) and o.detect:
is_x = o.detect[0] == 'x'
main_axis = eval("o.start_%s" % o.detect[0])
other_axis = eval("o.start_%s" % {'x': 'y', 'y': 'x'}[o.detect[0]])
for i in range(main_axis, main_axis + o.detect[1]):
triggers[(other_axis, i) if is_x else (i, other_axis)] = o