-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtile_map_generator.py
95 lines (88 loc) · 3.9 KB
/
tile_map_generator.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#Stew work on procedural geneartion of tile map
from stew_work import *
def gen_line(line_num, level, room_size):
"""Given a line_number of the current dungeon level returns the tile_map notation line
at that line num as a string"""
out_str = ''
for room in level:
if room:
if line_num != 0 and line_num != room_size - 1 and line_num != room_size // 2 and line_num != (room_size // 2) + 1:
out_str += '1' + ('.' * (room_size -2)) + '1'
if line_num == 0:
if room[4]:
out_str += '1' * (room_size // 2) + '..' + ('1' * (room_size - (room_size//2)-2))
else:
out_str += '1' * room_size
if line_num == (room_size -1):
if room[6]:
out_str += '1' * (room_size // 2) + '..' + ('1' * (room_size - (room_size//2)-2))
else:
out_str += '1' * room_size
if line_num == (room_size // 2) or line_num == ((room_size // 2)+1):
if room[7] == 'Room 1' and line_num == (room_size //2): #starting room
if room[3]:
if room[5]:
out_str += '.' * (room_size - 10) + '.P........'
else:
out_str += '.' * (room_size -10) + '.P.......1'
elif room[5]:
out_str += '1.........P........'
else:
out_str += '1' + ('.' * (room_size-11)) + '.P.......1'
elif room[7] == 'Boss Room' and line_num == (room_size //2): #boss room
if room[3]:
if room[5]:
out_str += '.' * (room_size - 10) + '.B........'
else:
out_str += '.' * (room_size -10) + '.B.......1'
elif room[5]:
out_str += '1.........B........'
else:
out_str += '1' + ('.' * (room_size-11)) + '.B.......1'
elif line_num == (room_size //2): #regular room, M for monster
if room[3]:
if room[5]:
out_str += '.' * (room_size - 10) + '.M........'
else:
out_str += '.' * (room_size -10) + '.M.......1'
elif room[5]:
out_str += '1.........M........'
else:
out_str += '1' + ('.' * (room_size-11)) + '.M.......1'
else:
if room[3]:
if room[5]:
out_str += '.' * room_size
else:
out_str += '.' * (room_size-1) + '1'
elif room[5]:
out_str += '1' + ('.' * (room_size-1))
else:
out_str += '1' + ('.' * (room_size-2)) + '1'
else:
out_str += ' ' * room_size
return out_str
def create_dungeon(room_size, room_number):
dungeon = Dungeon(room_number)
# room_size = 19 # this is the number of lines that make up a room, also num of character across a room
file = open('dungeonw.txt', 'w')
dung = dungeon.map[::-1]
first_time = True
for level in dung:
write_line = True
if write_line:
for line_num in range(room_size):
if not first_time:
file.write("\n")
first_time = False
file.write(gen_line(line_num, level, room_size))
file.write('\n' + ("..................." * 8))
file.close()
f1 = open('dungeonw.txt')
f2 = open('dungeon.txt', 'w')
tada = []
for level in range(8*19):
tada.append(f1.readline())
tada[:] = tada[::-1]
f2.writelines(tada)
#file.write()