-
Notifications
You must be signed in to change notification settings - Fork 0
/
cLevel.py
96 lines (75 loc) · 1.93 KB
/
cLevel.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
96
from pygame import Rect
import random
import cMaze
import colors as COLOR
class cLevel():
def __init__(self):
sqw = 32
sqh = 32
nobstacles = 5
ow = 25
oh = 25
self.MAZERECTS = []
self.START = Rect(0,0,sqw,sqh)
#self.END = Rect(800-sqw*3,600-sqh*3,sqw*3,sqh*3)
#self.OBSTACLES = self.generate_obstacles(nobstacles,ow,oh)
maze = cMaze.cMaze(19,25)
#self.MAZE = maze.maze
maze.maze[0][0] = 0
self.MAZERECTS = self.maze_to_rects(maze.maze,1)
self.VISITED = []
self.CHECKPOINTS = self.generate_checkpoints(maze.maze,6)
#the last selected checkpoint is the exit
self.END = self.CHECKPOINTS.pop()
self.fgcolor = COLOR.white
self.bgcolor = COLOR.random_color()
self.right = True
def get_start(self):
return self.START
def get_start(self):
return self.END
def generate_obstacles(self,num,ow,oh):
obstacles = []
for o in range(num):
px = random.randint(0+ow,800-ow*2)
py = random.randint(50,600)
rect = Rect(px,py,ow,oh)
obstacles.append(rect)
return obstacles
def maze_to_rects(self,MAZE,val):
w = 32
h = 32
result = []
for x,r in enumerate(MAZE):
for y,c in enumerate(r):
if MAZE[x][y] == val:
result.append(Rect(x*w,y*h,w,h))
return result
def update_obstacles_logic(self,width,height):
for o in self.OBSTACLES:
if self.right:
o.move_ip(1,0)
else:
o.move_ip(-1,0)
def update_logic():
"""
Update General logic of the level
"""
if len(self.CHECKPOINTS) == 0:
print "Now you can go to the ending"
def generate_checkpoints(self,maze,num):
"""
Generates a random list of places to visit
"""
possibles = self.maze_to_rects(maze,0) #possible visitable places
result = []
while len(result) < num:
random.shuffle(possibles)
result.append(possibles.pop())
return result
def reset(self):
"""
Just reset the checkpoints
"""
while len(self.VISITED) > 0:
self.CHECKPOINTS.append(self.VISITED.pop())