-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvl6.py
272 lines (210 loc) · 8.13 KB
/
lvl6.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
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
import pygame
import sys
def main():
pygame.init()
WIDTH, HEIGHT = 1400, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BROWN = (122, 49, 0)
pygame.display.set_caption("Level 6")
pygame.mixer.music.load('assets/music/lvl6.mp3')
pygame.mixer.music.play(0)
noetebook_sound = pygame.mixer.Sound('assets/music/notebook.mp3')
coin_sound = pygame.mixer.Sound('assets/music/catch.mp3')
shop_sound = pygame.mixer.Sound('assets/music/shop.mp3')
# Player class
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.Surface((32, 32))
self.image.fill(RED)
self.rect = self.image.get_rect()
self.rect.topleft = (685, 715)
self.speed = 5
def updateSpeed(self):
self.speed = 7
def update(self, keys):
dx, dy = 0, 0
if keys[pygame.K_a] and self.rect.x > 0:
dx -= self.speed
if keys[pygame.K_d] and self.rect.x < screen.get_width()-30:
dx += self.speed
if keys[pygame.K_w] and self.rect.y > 80:
dy -= self.speed
if keys[pygame.K_s] and self.rect.y < screen.get_height()-30:
dy += self.speed
self.rect.x += dx
for wall in walls:
if pygame.sprite.collide_rect(self, wall):
if dx > 0:
self.rect.right = wall.rect.left
elif dx < 0:
self.rect.left = wall.rect.right
self.rect.y += dy
for wall in walls:
if pygame.sprite.collide_rect(self, wall):
if dy > 0:
self.rect.bottom = wall.rect.top
elif dy < 0:
self.rect.top = wall.rect.bottom
# Teleporter class
class Teleport(pygame.sprite.Sprite):
def __init__(self, x, y, width, height, exit_x, exit_y):
super().__init__()
self.image = pygame.Surface((width, height))
self.image.fill(BROWN)
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
self.exit_pos = (exit_x, exit_y)
# Wall class
class Wall(pygame.sprite.Sprite):
def __init__(self, x, y, width, height):
super().__init__()
self.image = pygame.Surface((width, height))
self.image.fill(BLACK)
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
player = Player()
exit = pygame.Rect(670, 165, 70, 15)
player_sprites = pygame.sprite.Group()
player_sprites.add(player)
wallmainbottom = Wall(385, 560, 650, 15)
wallmainleft = Wall(385, 80, 15, 480)
wallmainright = Wall(1020, 80, 15, 480)
wallroomonebottom = Wall(0, 385, 400, 15)
wallroomfourbottom = Wall(1020, 385, 400, 15)
wallroomtworight = Wall(190, 400, 15, 480)
wallroomfiveright = Wall(1225, 400, 15, 480)
walls = pygame.sprite.Group()
walls.add(
wallmainbottom,
wallmainleft,
wallmainright,
wallroomonebottom,
wallroomfourbottom,
wallroomtworight,
wallroomfiveright
)
teleporter1a = Teleport(1190, 690, 20, 70, 80, 435)
teleporter1b = Teleport(60, 405, 70, 20, 80, 435)
teleporter2a = Teleport(155, 555, 20, 70, 1080, 115)
teleporter2b = Teleport(1050, 105, 20, 70, 1080, 115)
teleporter3a = Teleport(1050, 280, 20, 70, 505, 305)
teleporter3b = Teleport(480, 290, 20, 70, 505, 305)
teleporter10a = Teleport(905, 287, 20, 70, 685, 615)
teleporter10b = Teleport(665, 585, 70, 20, 685, 615)
teleporter4a = Teleport(1370, 185, 20, 70, 280, 440)
teleporter4b = Teleport(260, 405, 70, 20, 280, 440)
teleporter5a = Teleport(325, 770, 70, 20, 80, 730)
teleporter5b = Teleport(60, 770, 70, 20, 80, 730)
teleporter6a = Teleport(15, 555, 20, 70, 300, 135)
teleporter6b = Teleport(350, 105, 20, 70, 55 , 580)
teleporter7a = Teleport(15, 105, 20, 70, 1300, 450)
teleporter7b = Teleport(1280, 405, 70, 20, 1300, 450)
teleporter8a = Teleport(1280, 775, 70, 20, 180, 310)
teleporter8b = Teleport(160, 355, 70, 20, 180, 310)
teleporter9a = Teleport(1370, 555, 20, 70, 690, 465)
teleporter9b = Teleport(665, 520, 70, 20, 690, 465)
teleports= pygame.sprite.Group()
teleports.add(
teleporter1a,
teleporter1b,
teleporter2a,
teleporter2b,
teleporter3a,
teleporter3b,
teleporter10a,
teleporter10b,
teleporter4a,
teleporter4b,
teleporter5a,
teleporter5b,
teleporter6a,
teleporter6b,
teleporter7a,
teleporter7b,
teleporter8a,
teleporter8b,
teleporter9a,
teleporter9b
)
pygame.time.set_timer(pygame.USEREVENT, 1000)
countdown = 70
times_up = False
bg = pygame.image.load('assets/import/map6.png')
countdown_font = pygame.font.SysFont("comicsansms",40)
countdown_text = countdown_font.render(f"Time left {countdown}", True, (255,255,255))
countdown_rect = countdown_text.get_rect()
countdown_rect.center = (WIDTH // 2, 40)
debug_font = pygame.font.SysFont("comicsansms",20)
debug_text = debug_font.render(f"X: {player.rect.x}, Y: {player.rect.y}", True, (255, 255, 255))
debug_rect = debug_text.get_rect()
debug_rect.topleft = (30, 10)
noetebook = pygame.Rect(35, 290, 25, 30)
coin = pygame.Rect(1125, 430, 15, 15)
transparent_color = RED
alpha = 0
shop = pygame.Surface((200, 100), pygame.SRCALPHA)
shop.fill((transparent_color[0], transparent_color[1], transparent_color[2], alpha))
global noetebook_collected
global coint_collected
global coint_given
done = False
coint_collected = False
coint_given = False
noetebook_collected = False
while not done and times_up == False:
if countdown == 0:
times_up = True
import lvl1
lvl1.main()
done = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.USEREVENT:
countdown -= 1
screen.blit(bg, (0,0))
keys = pygame.key.get_pressed()
player.update(keys)
for teleporter in teleports:
if player.rect.colliderect(teleporter.rect):
player.rect.topleft = teleporter.exit_pos
if not noetebook_collected:
pygame.draw.rect(screen, GREEN, noetebook)
if player.rect.colliderect(noetebook) and noetebook_collected == False:
noetebook_collected = True
noetebook_sound.play()
if not coint_collected:
pygame.draw.circle(screen, (230, 182, 28), (1125, 430), 15)
if player.rect.colliderect(coin) and coint_collected == False:
coint_collected = True
coin_sound.play()
if player.rect.colliderect(pygame.Rect(395, 590, 200, 100)):
if coint_collected and coint_given == False:
coint_given = True
shop_sound.play()
if coint_given:
player.updateSpeed()
if player.rect.colliderect(exit):
if noetebook_collected == True:
import latest
latest.main()
done = True
pygame.draw.rect(screen, GREEN, exit)
player_sprites.draw(screen)
teleports.draw(screen)
walls.draw(screen)
screen.blit(shop, (395, 590))
countdown_text = countdown_font.render(f"Time left {countdown}", True, (255,255,255))
screen.blit(countdown_text, countdown_rect)
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()
if __name__ == "__main__":
main()