-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMazeFunctions.py
More file actions
165 lines (139 loc) · 4.15 KB
/
MazeFunctions.py
File metadata and controls
165 lines (139 loc) · 4.15 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
156
157
158
159
160
161
162
163
164
165
#classes and functions
import turtle
import math
class Pen(turtle.Turtle):
def __init__(self):
turtle.Turtle.__init__(self)
self.shape("square")
self.color("white")
self.penup()
self.speed(0)
class Player(turtle.Turtle):
def __init__(self):
turtle.Turtle.__init__(self)
self.shape("circle")
self.color("blue")
self.penup()
self.speed(0)
self.gold=0
def go_up(self):
move_to_x=player.xcor()
move_to_y=player.ycor()+24
if(move_to_x,move_to_y)not in walls:
self.goto(move_to_x,move_to_y)
def go_down(self):
move_to_x=player.xcor()
move_to_y=player.ycor()-24
if(move_to_x,move_to_y)not in walls:
self.goto(move_to_x,move_to_y)
def go_left(self):
move_to_x=player.xcor()-24
move_to_y=player.ycor()
if(move_to_x,move_to_y)not in walls:
self.goto(move_to_x,move_to_y)
def go_right(self):
move_to_x=player.xcor()+24
move_to_y=player.ycor()
if(move_to_x,move_to_y)not in walls:
self.goto(move_to_x,move_to_y)
def is_collision(self,other):
a=self.xcor()-other.xcor()
b=self.ycor()-other.ycor()
distance=math.sqrt((a**2)+(b**2))
return distance < 5
# Class Treasure
class Treasure(turtle.Turtle):
def __init__(self, x, y):
turtle.Turtle.__init__(self)
self.shape("circle")
self.color("gold")
self.penup()
self.speed(0)
self.gold = 100
self.goto(x, y)
def destroy(self):
self.goto(2000, 2000)
self.hideturtle()
# Creating Level Lists
global levels
levels= [""]
level_1 = [
"BBBBBBBBBBBBBBBBBBBBBBBBB",
"BP BBBBBBBBBBBBBBBBBBBBBB",
"B BBBBBB BBBBBBBB",
"B T TBB BB BBB",
"BBBB BB BB BB BBB",
"BBBB BB BB BB BBB",
"BBBB BB BB BBBBBBBB",
"BBBB BB BB",
"BBBBBB BBBBBBBBBBB BB",
"BBBBBB BBBBBBBBBBB BB",
"BBBBBB BBBBB BB",
"B BBBB BBBBBBBBB BB",
"B BBBB BBBBBBBBBBBBBB",
"B BBBB BBBB",
"B BBBBBBBBBBBBBB",
"BBBBBBBBB BBBBBBBBBBBBBB",
"BBBB BBBB",
"BBBBBBBBBBBBBBBB BBBBBB",
"BBBBBBBBBBBBBBBB BBBBBB",
"BB BBBBBBBBBBB BBBBBB",
"BB BBB BBBBBB",
"BB BBBBBBBBB BBBBBB",
"BB BBBBBB",
"BBBBBBBBB BBBBBBBBBBBBB",
"BBBBBBBBB BBBBBBB",
"BBBBBBBBBBBBBBBBBBBBBBBBB"
]
level_2 = [
"BBBBBBBBBBBBBBBBBBBBBBBBB",
"BP T BB TBBB",
"BB BBBBBBBBB BBB BB",
"BB BBBBBB BBB BB",
"BB BBB BBB BB",
"BB BBBBBBBBBBBBBBBB BBB",
"BB BBBB BBB",
"BBBBBBBBBB BBB BBBBBBB",
"BBBBBBBBB BB BBBBBBBB",
"BB BBBBBBB BB",
"BB BBBBBBBBBBBBB BBBBB",
"BB BBBBB",
"BBBBBBB BBBBBBBBBBBBBBB",
"BB BBB BBBB B",
"BB BBBBBBB BBB B",
"BBBB BB BBB B",
"BBBB BBBBBB BBBBBBBB B",
"B BBB B",
"BBB BBBB BBBBBBBBBBBBB",
"BBB BBBB BBBBBBBB BB",
"BB BBB",
"BB BBBBBBBBBBBBB BBBBB",
"BB BB BB B",
"BB BB BBBBBBBBBBBB B",
"BB BB",
"BBBBBBBBBBBBBBBBBBBBBBBBB"
]
# List of Treasures
treasures = []
# Add maze to maze list
levels.append(level_1)
levels.append(level_2)
# Create level Setup Function
def setup_maze(level):
for y in range(len(level)):
for x in range(len(level[y])):
character = level[y][x]
screen_x = -288 + (x * 24)
screen_y = 288 - (y * 24)
if character == 'B':
pen.goto(screen_x, screen_y)
pen.stamp()
walls.append((screen_x, screen_y))
if character == 'P':
player.goto(screen_x, screen_y)
if character == 'T':
treasures.append(Treasure(screen_x, screen_y))
# Creating Pen object
pen = Pen()
player = Player()
walls = []