-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp
46 lines (35 loc) · 2.08 KB
/
temp
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
def level_generate(self):
levelObjects = [[Platform("empty") for j in range(30)] for i in range(30)]
pathCurrentDir = os.path.dir(__file__)
pathRelDir = "../level.txt"
pathAbsDir = os.path.join(pathCurrentDir, pathRelDir)
levelFile = open(pathAbsDir, encoding="utf-8")
levelLineNo = 0
for levelLine in levelFile.readLines():
levelLineSplit = list(levelLine)
for i in range(30):
if levelLineSplit[i] == "_": # passage
levelObjects[i][levelLineNo].name = "empty"
elif levelLineSplit[i] == "#": # wall
levelObjects[i][levelLineNo].name = "wall"
elif levelLineSplit[i] == "@": # pacman
levelObjects[i][levelLineNo].name = "empty"
# give the starting coordinate
self.player_character.coordinateRel[0] = i
self.player_character.coordinateRel[1] = levelLineNo
self.player_character.coordinateAbs[0] = i * 4
self.player_character.coordinateAbs[1] = levelLineNo * 4
elif levelLineSplit[i] == "&": # free ghost
levelObjects[i][levelLineNo].name = "empty"
# find an inactive ghost and give the starting coordinate
for n in range(4):
if self.movingObjectGhosts[n].isActive == False:
self.movingObjectGhosts[n].isActive = True
self.movingObjectGhosts[n].isCaged = False
self.movingObjectGhosts[n].coordinateRel[0] = i
self.movingObjectGhosts[n].coordinateRel[1] = levelLineNo
self.movingObjectGhosts[n].coordinateAbs[0] = i * 4
self.movingObjectGhosts[n].coordinateAbs[1] = levelLineNo * 4
break # break current loop (with generator 'n')
levelLineNo += 1 # indicate which line we are
levelFile.close()