-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.py
327 lines (286 loc) · 14.2 KB
/
levels.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import pygame
from random import randint
from settings import *
class Level:
def __init__(self):
self.background = pygame.image.load('assets/level-bg.png').convert_alpha()
self.font = pygame.font.Font(LEVEL_FONT, 45)
self.small_font = pygame.font.Font(LEVEL_FONT, 20)
self.med_font = pygame.font.Font(MEDIEVAL_FONT, 150)
self.seg_font = pygame.font.Font(SEGMENT_FONT, 90)
self.input = pygame.image.load('assets/text-bg.png').convert_alpha()
self.submit = pygame.image.load('assets/go-btn.png').convert_alpha()
self.submit_rect = self.submit.get_rect(topleft=((620,610)))
self.wrong = pygame.image.load('assets/wrong.png').convert_alpha()
self.wrong = pygame.transform.scale(self.wrong, (OBJECT_WIDTH-80, OBJECT_HEIGHT-80))
self.next_lvl = pygame.image.load('assets/next-lvl.png').convert_alpha()
self.next_lvl_rect = self.next_lvl.get_rect(topleft= (110, 290))
self.key_sound = pygame.mixer.Sound(KEYBOARD_SOUND)
self.wrong_sound = pygame.mixer.Sound(WRONG_SOUND)
self.correct_sound = pygame.mixer.Sound(CORRECT_SOUND)
self.completed = False
def run(self, screen):
screen.blit(self.background, (110,100))
screen.blit(self.input, (336,600))
screen.blit(self.submit, self.submit_rect)
def update(self, event, screen):
screen.blit(self.input, (336,600))
screen.blit(self.submit, (620,610))
class SortTheDate(Level):
def __init__(self):
super().__init__()
self.objects = [pygame.image.load('assets/cup.png').convert_alpha(),
pygame.image.load('assets/elephant.png').convert_alpha(),
pygame.image.load('assets/ring.png').convert_alpha(),
pygame.image.load('assets/snake.png').convert_alpha(),
]
self.objects = [pygame.transform.scale(_, (OBJECT_WIDTH, OBJECT_HEIGHT)) for _ in self.objects]
self.codes = [32,53,75,15]
self.codes = [self.small_font.render(str(_), False, (255,255,255)) for _ in self.codes]
self.clue = [self.small_font.render(text, True, (0, 0, 0)) for text in ['To solve this riddle,','you must arrange,','key is the father,','when he first breathe,']]
self.objects_rendered = False
self.message = 'PASSCODE'
self.user_text = self.small_font.render(self.message, True, (0,0,0))
self.instruction = self.small_font.render("Enter the passcode below then press submit button", True, (0,0,0))
def run(self, screen):
if self.objects_rendered is False:
super().run(screen)
screen.blit(self.user_text, (359,658))
y = 110
for c in self.clue:
screen.blit(c, (338,y))
y+=25
cordinates = ((205,237), (353,430), (512,273), (706,331))
for object, coordinate, code in zip(self.objects, cordinates, self.codes):
screen.blit(object, coordinate)
screen.blit(code, (coordinate[0]+90, coordinate[1]+75))
screen.blit(self.instruction, (280,220))
self.objects_rendered = True
def update(self, event, screen):
if not self.completed:
if event.type == pygame.KEYDOWN:
channel = self.key_sound.play()
channel.fadeout(300)
if event.key == pygame.K_BACKSPACE:
self.message = self.message[:-1]
else:
if len(self.message) <= 8 and event.unicode.isnumeric(): self.message += event.unicode
super().update(event, screen)
self.user_text = self.small_font.render(self.message, True, (0,0,0))
screen.blit(self.user_text, (359,658))
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
if self.submit_rect.collidepoint(pos):self.check_win(screen)
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.completed:
pos = pygame.mouse.get_pos()
if self.next_lvl_rect.collidepoint(pos): return True
return False
def check_win(self, screen):
if self.message == '32157553':
screen.blit(self.next_lvl, self.next_lvl_rect)
self.completed = True
self.correct_sound.play()
else:
screen.blit(self.wrong, (730,170))
self.wrong_sound.play()
class GetTheColor(Level):
def __init__(self):
super().__init__()
self.objects = [
pygame.Surface((50,50)) for i in range(5) ]
for i, color in enumerate([ (255,255,255),(0,0,255), (255,0,0), (0,255,0), (0,0,0)]):
self.objects[i].fill(color)
switch_on = pygame.image.load('assets/on.png')
switch_off = pygame.image.load('assets/off.png')
self.switch_on = pygame.transform.scale(switch_on, (45,45))
self.switch_off = pygame.transform.scale(switch_off, (45,45))
self.swich_board = pygame.Rect((340, 250), (150*3,70*5))
self.grid = [[False for _ in range(3)] for _ in range(5)]
self.objects_rendered = False
self.clue = [self.small_font.render(text, True, (0, 0, 0)) for text in ['To solve this riddle,','think about color,','only two values,','max and min,']]
self.instruction = self.small_font.render("Tap on the switch to toggle ", True, (0,0,0))
def run(self, screen):
if self.objects_rendered is False:
super().run(screen)
self.draw_switches(screen)
for object, y in zip(self.objects, range(250, 250+(70*5), 70)):
screen.blit(object, (220, y))
y = 110
for c in self.clue:
screen.blit(c, (338,y))
y+=25
screen.blit(self.instruction, (280,220))
self.objects_rendered = True
def draw_switches(self, screen):
for i in range(5):
y = (self.swich_board.y) + (i*70)
for j in range(3):
x = (self.swich_board.x) + (j*150)
screen.blit(self.switch_off, (x,y))
def update(self, event, screen):
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.completed:
pos = pygame.mouse.get_pos()
if self.next_lvl_rect.collidepoint(pos): return True
if not self.completed:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
x,y = (pos[0] - 340) // 150 , (pos[1] - 250) // 70
if x in range(3) and y in range(5):
self.grid[y][x] = not self.grid[y][x]
pos_x, pos_y = 340 + (x*150), 250 + (y*70)
if self.grid[y][x]:
screen.blit(self.switch_on, (pos_x, pos_y))
else:
screen.blit(self.switch_off, (pos_x, pos_y))
self.check_win(screen)
return False
def check_win(self, screen):
valid = [[True, True, True], [False, False, True], [True, False, False], [False, True, False], [False, False, False]]
if self.grid == valid:
screen.blit(self.next_lvl, self.next_lvl_rect)
self.completed = True
self.correct_sound.play()
class CeaserCipher(Level):
def __init__(self):
super().__init__()
self.coded_msg = self.med_font.render("BRX ZRQ", True, ("#252422"))
self.message = "DECRYPT MESSAGE HERE"
self.user_text = self.small_font.render(self.message, True, (0,0,0))
self.instruction = self.small_font.render("Think and Decrypt", True, (0,0,0))
self.clue = [self.small_font.render(text, True, (0, 0, 0)) for text in ['A famous cryptography,','back in time,','when friend stabbed']]
self.objects_rendered = False
self.completed = False
def run(self, screen):
if not self.objects_rendered:
super().run(screen)
y = 110
for c in self.clue:
screen.blit(c, (338,y))
y+=25
screen.blit(self.instruction, (280,220))
screen.blit(self.coded_msg, (180, 360))
screen.blit(self.user_text, (370,650))
self.objects_rendered = True
def update(self, event, screen):
if not self.completed:
if event.type == pygame.KEYDOWN:
self.key_sound.play()
if event.key == pygame.K_BACKSPACE:
self.message = self.message[:-1]
else:
if len(self.message) < 8 and not event.unicode.isnumeric(): self.message += event.unicode.upper()
super().update(event, screen)
self.user_text = self.small_font.render(self.message, True, (0,0,0))
screen.blit(self.user_text, (370,650))
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
if self.submit_rect.collidepoint(pos):self.check_win(screen)
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.completed:
pos = pygame.mouse.get_pos()
if self.next_lvl_rect.collidepoint(pos): return True
return False
def check_win(self, screen):
if self.message == 'YOU WON':
screen.blit(self.next_lvl, self.next_lvl_rect)
self.completed = True
self.correct_sound.play()
else:
screen.blit(self.wrong, (730,170))
self.wrong_sound.play()
class ThinkBinary(Level):
def __init__(self):
super().__init__()
switch_on = pygame.image.load('assets/on.png')
self.switch_on = pygame.transform.scale(switch_on, (60,60))
switch_off = pygame.image.load('assets/off.png')
self.switch_off = pygame.transform.scale(switch_off, (60,60))
self.swich_board = pygame.Rect((190, 260), (80*8,80*4))
self.grid = [[False for _ in range(8)] for i in range(4)]
self.objects_rendered = False
self.completed = False
self.instruction = self.small_font.render("Flip Switches to solve.", True, (0,0,0))
self.clue = [self.small_font.render(text, True, (0, 0, 0)) for text in ['answEr is simple,','each rOw is a letter,','coNvert the letter','to approPriate form,']]
def run(self, screen):
if not self.objects_rendered:
super().run(screen)
self.draw_switches(screen)
screen.blit(self.instruction, (280,220))
y = 110
for c in self.clue:
screen.blit(c, (338,y))
y+=25
self.objects_rendered = True
def draw_switches(self, screen):
for i in range(4):
y = (self.swich_board.y) + (i*80)
for j in range(8):
x = (self.swich_board.x) + (j*80)
screen.blit(self.switch_off, (x,y))
def update(self, event, screen):
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.completed:
pos = pygame.mouse.get_pos()
if self.next_lvl_rect.collidepoint(pos): return True
if not self.completed:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
x,y = (pos[0] - 190) // 80 , (pos[1] - 260) // 80
if x in range(8) and y in range(4):
self.grid[y][x] = not self.grid[y][x]
pos_x, pos_y = 190 + (x*80), 260 + (y*80)
if self.grid[y][x]:
screen.blit(self.switch_on, (pos_x, pos_y))
else:
screen.blit(self.switch_off, (pos_x, pos_y))
self.check_win(screen)
return False
def check_win(self, screen):
valid = [
[False, True, False, False, True, True, True, True],
[False, True, False, True, False, False, False, False],
[False, True, False, False, False, True, False, True],
[False, True, False, False, True, True, True, False]
]
if self.grid == valid:
screen.blit(self.next_lvl, self.next_lvl_rect)
self.completed = True
self.correct_sound.play()
class ThinkAscii(Level):
def __init__(self):
super().__init__()
self.nums = self.seg_font.render("0 1 2 3 4 5 6 7 8 9", True, (200,0,0))
num_rect = self.nums.get_rect()
num_rect.inflate_ip(20, 20)
self.bg_surf = pygame.Surface((num_rect.width, num_rect.height))
print(num_rect.width, num_rect.height)
self.bg_surf.fill((0,0,0))
self.mover = pygame.image.load("assets/Dragon.png")
self.completed = False
self.instruction = self.small_font.render("Use Left-Right Arrows to move and Space to select", True, (0,0,0))
self.clue = [self.small_font.render(text, True, (0, 0, 0)) for text in ['answEr is simple,','each rOw is a letter,','coNvert the letter','to approPriate form,']]
self.objects_rendered = False
self.mover_rect = self.mover.get_rect()
self.text = ""
def run(self, screen):
if not self.objects_rendered:
super().run(screen)
screen.blit(self.bg_surf, (180, 340))
screen.blit(self.nums, (190,350))
screen.blit(self.instruction, (280,220))
screen.blit(self.mover, (180,380))
self.objects_rendered = True
pass
def update(self, event, screen):
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.completed:
pos = pygame.mouse.get_pos()
if self.next_lvl_rect.collidepoint(pos): return True
if not self.completed:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT and self.mover_rect.x > 247:
print("Das")
screen.blit(self.mover, (self.mover_rect.x + 67, 380))
if event.key == pygame.K_LEFT:
print("Dass")
screen.blit(self.mover, (self.mover_rect.x - 67, 380))
return False
def check_win(self):
pass