-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacMan.py
More file actions
287 lines (220 loc) · 8.13 KB
/
PacMan.py
File metadata and controls
287 lines (220 loc) · 8.13 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import pygame
# Define some colors
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)
PATHS = (204 ,155 , 120)
GRASSWALL= (69 , 201, 54)
Stone = (204 , 204, 204)
pygame.init()
# Set the width and height of the screen [width, height]
size = (800, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Darudernauts")
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
pygame.mixer.music.load('darude.mp3')
pygame.mixer.music.set_endevent(pygame.constants.USEREVENT)
pygame.mixer.music.play()
#player_image = pygame.image.load("C:\Users\Mark\Documents\player.gif").convert()
#shroom_image = pygame.image.load("C:\Users\Mark\Documents\shroom.gif").convert()
# Hide the mouse cursor
pygame.mouse.set_visible(0)
# Speed in pixels per frame
x_speed = 0
y_speed = 0
x = 350
y = 200
shroom_list_x = [150,150,150,150,150,150,150,150,150,150,600,600,600,600,600,600,600,600,600,600,200,250,300,350,400,450,500,550, 0, 50,100,650,700,750, 0, 50,100,650,700,750,200,250,300,350,400,450,500,550,300,350,400,450,250,250,250,250,250,250,500,500,500,500,500,500,350,400,350,400,400,-50]
shroom_list_y = [ 0, 50,100,150,200,250,300,350,400,450, 0, 50,100,150,200,250,300,350,400,450, 50, 50, 50, 50, 50, 50, 50, 50,100,100,100,100,100,100,350,350,350,350,350,350,400,400,400,400,400,400,400,400,300,300,300,300,100,150,200,250,300,350,100,150,200,250,300,350,100,100,150,150,200,-50]
score = 0
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
move_horizontally = 0
move_vertically = 0
if event.type == pygame.KEYDOWN:
# Figure out if it was an arrow key. If so
# adjust speed.
if event.key == pygame.K_LEFT:
move_horizontally = -50
if event.key == pygame.K_RIGHT:
move_horizontally = 50
if event.key == pygame.K_UP:
move_vertically = -50
if event.key == pygame.K_DOWN:
move_vertically = 50
# --- Game logic should go here
#side tps
if x < -50:
x = 750
if x > 800:
x = -50
#top/bot tps
if y < -50:
y = 450
if y > 500:
y = -50
#midtop
if x == 150 and y == 0:
move_horizontally = 0#left
if x == 600 and y == 0:
move_horizontally = 0#right
if x == 150 and y == 450:
move_horizontally = 0#left
if x == 600 and y == 450:
move_horizontally = 0#right
if x == 150 and y == 50:
if move_horizontally < 0:
move_horizontally = 0
if x == 600 and y == 50:
if move_horizontally > 0:
move_horizontally = 0
if x == 600 and y == 400:
if move_horizontally > 0:
move_horizontally = 0
if x >= 200 and x <= 550 and y == 50:
if move_vertically < 0:
move_vertically = 0
if x == 200 or x == 300 or x == 450 or x == 550:
if y == 50:
move_vertically = 0
if x == 150:
if y >= 0 and y <= 450:
if y != 100 and y != 350:
if move_horizontally < 0:
move_horizontally =0
if x == 200 and y == 400:
move_vertically = 0
if x == 550 and y == 400:
move_vertically = 0
if x == 300 or x == 350 or x == 400 or x == 450:
if y == 400:
move_vertically = 0
#topleft path
if x >= 0 and x <= 100 and y == 100:
move_vertically = 0
#botright path
if x >= 0 and x <= 100 and y == 350:
move_vertically = 0
#topright path
if x >= 650 and x <= 800 and y == 100:
move_vertically = 0
#botright path
if x >= 650 and x <= 800 and y == 350:
move_vertically = 0
if x == 150:
if y == 150 or y == 200 or y == 250 or y == 300:
move_horizontally = 0
if x == 600:
if y == 150 or y == 200 or y == 250 or y == 300:
move_horizontally = 0
if y == 100 and x == 150:
if move_horizontally >= 0:
move_horizontally = 0
if y == 350 and x == 150:
if move_horizontally >= 0:
move_horizontally = 0
if y == 100 and x == 600:
if move_horizontally <= 0:
move_horizontally = 0
if y == 350 and x == 600:
if move_horizontally <= 0:
move_horizontally = 0
if x == 250 and y == 400:
if move_vertically > 0:
move_vertically = 0
if x == 500 and y == 400:
if move_vertically > 0:
move_vertically = 0
if x == 250 and y == 350:
move_horizontally = 0
if x == 500 and y == 350:
move_horizontally = 0
if x < 0 or x > 800:
move_vertically = 0
if y < 0 or y == 500:
move_horizontally = 0
if y == 300:
if x == 300 or x == 350 or x == 400 or x == 450:
move_vertically = 0
if y == 300 and x == 250:
if move_horizontally < 0:
move_horizontally = 0
if y == 300 and x == 500:
if move_horizontally > 0:
move_horizontally = 0
if x == 250 or x == 500:
if y == 100 or y == 150 or y == 200 or y == 250:
move_horizontally = 0
if x == 350:
if y == 100 or y == 150:
if move_horizontally < 0:
move_horizontally = 0
if x == 400:
if y == 100 or y == 150:
if move_horizontally > 0:
move_horizontally = 0
if x == 350 and y == 200:
if move_horizontally < 0:
move_horizontally = 0
elif move_vertically > 0:
move_vertically = 0
if x == 400 and y == 200:
if move_horizontally > 0:
move_horizontally = 0
elif move_vertically > 0:
move_vertically = 0
x = x + move_horizontally
y = y + move_vertically
if score == 69:
print ("VICTORY!!! YOU'VE COLLECTED 69 MUSHROOMS!!!")
# --- Drawing code should go here
# First, clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
screen.fill(Stone)
pygame.draw.rect(screen,GRASSWALL,[0,0,150,100])#TOPLEFT
pygame.draw.rect(screen,GRASSWALL,[0,150,150,200])#MIDLEFT
pygame.draw.rect(screen,GRASSWALL,[0,400,150,100])#BOTLEFT
pygame.draw.rect(screen,GRASSWALL,[650,0,150,100])#TOPRIGHT
pygame.draw.rect(screen,GRASSWALL,[650,150,150,200])#MIDRIGHT
pygame.draw.rect(screen,GRASSWALL,[650,400,150,100])#BOTRIGHT
pygame.draw.rect(screen,GRASSWALL,[200,0,400,50])#MIDTOP
pygame.draw.rect(screen,GRASSWALL,[200,450,400,50])#MIDBOT
pygame.draw.rect(screen,GRASSWALL,[200,100,50,300])#JUNGLEFT
pygame.draw.rect(screen,GRASSWALL,[550,100,50,300])#JUNGRIGHT
pygame.draw.rect(screen,GRASSWALL,[300,350,200,50])#JUNGBOT
pygame.draw.rect(screen,GRASSWALL,[300,250,200,50])#BASEBOT
pygame.draw.rect(screen,GRASSWALL,[300,100,50,150])#BASELEFT
pygame.draw.rect(screen,GRASSWALL,[450,100,50,150])#BASERIGHT
# player_image = pygame.image.load("C:\Users\Mark\Documents\player.gif").convert()
# shroom_image = pygame.image.load("C:\Users\Mark\Documents\shroom.gif").convert()
# --- Go ahead and update the screen with what we've drawn.
# Get the current mouse position. This returns the position
# as a list of two numbers.
x += x_speed
y += y_speed
## print x
## print y
# Copy image to screen:
screen.blit(player_image, [x, y])
for shrm in range(0, len(shroom_list_x)-1):
if x == shroom_list_x[shrm] and y == shroom_list_y[shrm]:
shroom_list_x.pop(shrm)
shroom_list_y.pop(shrm)
score += 1
print ("SCORE:",score,"mushrooms")
screen.blit(shroom_image, [shroom_list_x[shrm], shroom_list_y[shrm]])
pygame.display.flip()
# --- Limit to 7 frames per second
clock.tick(10)
# Close the window and quit.
# If you forget this line, the program will 'hang'
# on exit if running from IDLE.
pygame.quit()