This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
344 lines (276 loc) · 11.8 KB
/
game.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import sys
import pygame
from pygame.locals import *
import pandas
import random
import cv2
from discord_webhook import DiscordWebhook
import urllib.request
pygame.init()
clock = pygame.time.Clock()
font = pygame.font.Font("resources/font.ttf", 40)
counterfont = pygame.font.Font("resources/font.ttf", 50)
restriction = 30
def connect(host='http://google.com'):
try:
urllib.request.urlopen(host)
return True
except:
return False
# textwrap
textAlignLeft = 0
textAlignRight = 1
textAlignCenter = 2
textAlignBlock = 3
def drawText(surface, text, color, rect, font, align=textAlignLeft, aa=True, bkg=None):
lineSpacing = -10
spaceWidth, fontHeight = font.size(" ")[0], font.size("Tg")[1]
listOfWords = text.split(" ")
if bkg:
imageList = [font.render(word, 1, color, bkg) for word in listOfWords]
for image in imageList: image.set_colorkey(bkg)
else:
imageList = [font.render(word, aa, color) for word in listOfWords]
maxLen = rect[2]
lineLenList = [0]
lineList = [[]]
for image in imageList:
width = image.get_width()
lineLen = lineLenList[-1] + len(lineList[-1]) * spaceWidth + width
if len(lineList[-1]) == 0 or lineLen <= maxLen:
lineLenList[-1] += width
lineList[-1].append(image)
else:
lineLenList.append(width)
lineList.append([image])
lineBottom = rect[1]
lastLine = 0
for lineLen, lineImages in zip(lineLenList, lineList):
lineLeft = rect[0]
if align == textAlignRight:
lineLeft += + rect[2] - lineLen - spaceWidth * (len(lineImages)-1)
elif align == textAlignCenter:
lineLeft += (rect[2] - lineLen - spaceWidth * (len(lineImages)-1)) // 2
elif align == textAlignBlock and len(lineImages) > 1:
spaceWidth = (rect[2] - lineLen) // (len(lineImages)-1)
if lineBottom + fontHeight > rect[1] + rect[3]:
break
lastLine += 1
for i, image in enumerate(lineImages):
x, y = lineLeft + i*spaceWidth, lineBottom
surface.blit(image, (round(x), y))
lineLeft += image.get_width()
lineBottom += fontHeight + lineSpacing
if lastLine < len(lineList):
drawWords = sum([len(lineList[i]) for i in range(lastLine)])
remainingText = ""
for text in listOfWords[drawWords:]: remainingText += text + " "
return remainingText
return ""
# qnagen
qna = pandas.read_excel("resources/izvucena_pitanja.xlsx", "sheet", usecols = "A,B")
qnad = qna.to_dict('index')
# intro music
music = pygame.mixer.music.load("resources/main/intro.mp3")
pygame.mixer.music.play()
# game window
width = 1280
height = 720
window = pygame.display.set_mode((width,height))
pygame.display.set_caption("КО ЗНА ЗНА - REVAMP")
icon = pygame.image.load('resources/icon.ico')
pygame.display.set_icon(icon)
pygame.display.toggle_fullscreen()
# Game
def Game():
running = True
i = 1
# background image
bg_img = pygame.image.load('resources/game/game.png')
pygame.transform.scale(bg_img,(width,height))
# game buttons
button0 = pygame.image.load('resources/buttons/game/main_button01-0.png')
button1 = pygame.image.load('resources/buttons/game/main_button02-0.png')
button2 = pygame.image.load('resources/buttons/game/main_button03-0.png')
button3 = pygame.image.load('resources/buttons/game/main_button04-0.png')
# game music
music = pygame.mixer.music.load("resources/game/background_music.mp3")
pygame.mixer.music.play(-1)
ba = False
bb = False
spam = True
r = random.randrange(0, len(qnad), 3)
while running:
posm = pygame.mouse.get_pos()
q = qnad[r]["ПИТАЊЕ"]
a = font.render(qnad[r]["ОДГОВОР"], True, "white")
a_rect = a.get_rect(center=(window.get_width()/2, 255))
it = counterfont.render(str(i), True, "white")
it_rect = it.get_rect(center=(128-it.get_width()/2,420))
window.blit(bg_img,(0,0))
window.blit(button0,(601,477))
if bb:
window.blit(button1,(601,477))
if spam:
window.blit(button2,(601,541))
window.blit(button3,(1208,17))
window.blit(it, it_rect) #35
if ba:
window.blit(a, a_rect)
q_rect = pygame.Rect(150, 60, 980, 185)
drawTextRect = q_rect.inflate(-5, -5)
drawText(window, q, "white", drawTextRect, font, textAlignCenter, True)
if restriction+1 == i:
Main()
if posm[0] > 601 and posm[0] < 1101 and posm[1] > 477 and posm[1] < 515:
button0 = pygame.image.load('resources/buttons/game/main_button01-1.png')
else:
button0 = pygame.image.load('resources/buttons/game/main_button01-0.png')
if posm[0] > 601 and posm[0] < 1101 and posm[1] > 477 and posm[1] < 515:
button1 = pygame.image.load('resources/buttons/game/main_button02-1.png')
else:
button1 = pygame.image.load('resources/buttons/game/main_button02-0.png')
if posm[0] > 601 and posm[0] < 1101 and posm[1] > 541 and posm[1] < 579:
button2 = pygame.image.load('resources/buttons/game/main_button03-1.png')
else:
button2 = pygame.image.load('resources/buttons/game/main_button03-0.png')
if posm[0] > 1208 and posm[0] < 1264 and posm[1] > 17 and posm[1] < 73:
button3 = pygame.image.load('resources/buttons/game/main_button04-1.png')
else:
button3 = pygame.image.load('resources/buttons/game/main_button04-0.png')
for event in pygame.event.get():
if event.type == QUIT:
running = False
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
if posm[0] > 601 and posm[0] < 1101 and posm[1] > 477 and posm[1] < 515 and bb == False:
ba = True
bb = True
elif posm[0] > 601 and posm[0] < 1101 and posm[1] > 477 and posm[1] < 515:
i = i + 1
ba = False
bb = False
spam = True
r = random.randint(0, len(qnad))
elif posm[0] > 601 and posm[0] < 1101 and posm[1] > 541 and posm[1] < 579:
if connect() and spam:
webhook = DiscordWebhook(url="https://discord.com/api/webhooks/1039583452892250242/RwRC8T044RmEZlFdeNzzE9iFE2GqUF7aptS5j99cBueD27qwHTV-6M022OsPD-o3Lcds", content=("ПРИЈАВА ГРЕШКЕ:\n```ПИТАЊЕ: %s\n\nОДГОВОР: %s```" % (q, qnad[r]["ОДГОВОР"])))
spam = False
webhook.execute()
elif posm[0] > 1208 and posm[0] < 1264 and posm[1] > 17 and posm[1] < 73:
pygame.mixer.music.pause()
Main()
clock.tick(60)
pygame.display.flip()
pygame.quit()
sys.exit()
# Settings
def Settings():
global restriction
running = True
user_text = "30"
input_rect = pygame.Rect(280, 300, 600, 75)
# background image
bg_img = pygame.image.load('resources/settings/settings.png')
pygame.transform.scale(bg_img,(width,height))
# setting button
button0 = pygame.image.load('resources/buttons/settings/main_button01-0.png')
while running:
posm = pygame.mouse.get_pos()
window.blit(bg_img,(0,0))
window.blit(button0,(326,438))
text = counterfont.render(str(user_text), True, "white")
window.blit(text, (input_rect.x+5, input_rect.y+5))
input_rect.w = max(100, text.get_width()+10)
if posm[0] > 326 and posm[0] < 826 and posm[1] > 438 and posm[1] < 476:
button0 = pygame.image.load('resources/buttons/settings/main_button01-1.png')
else:
button0 = pygame.image.load('resources/buttons/settings/main_button01-0.png')
for event in pygame.event.get():
if event.type == QUIT:
restriction = 30
running = False
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
if posm[0] > 326 and posm[0] < 826 and posm[1] > 438 and posm[1] < 476:
if user_text.isdigit() and int(user_text) <= 999:
restriction = int(user_text)
Main()
if input_rect.collidepoint(event.pos):
active = True
else:
active = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
user_text = user_text[:-1]
elif event.unicode.isdigit():
user_text += event.unicode
clock.tick(60)
pygame.display.flip()
# Transition
def Transition():
music = pygame.mixer.music.load("resources/transition/transition.mp3")
pygame.mixer.music.play()
capture = cv2.VideoCapture("resources/transition/transition.mp4")
success, camera_image = capture.read()
run = success
while run:
for event in pygame.event.get():
if event.type == QUIT:
run = False
if event.type == MOUSEBUTTONDOWN or event.type == pygame.KEYDOWN:
pygame.mixer.music.pause()
Game()
success, camera_image = capture.read()
if success:
camera_surf = pygame.image.frombuffer(camera_image.tobytes(), camera_image.shape[1::-1], "BGR")
else:
run = False
window.blit(camera_surf, (0, 0))
clock.tick(25)
pygame.display.flip()
Game()
# main while loop
def Main():
running = True
# background image
bg_img = pygame.image.load('resources/main/main.png')
pygame.transform.scale(bg_img,(width,height))
# main menu buttons
button0 = pygame.image.load('resources/buttons/main/main_button01-0.png')
button1 = pygame.image.load('resources/buttons/main/main_button02-0.png')
button2 = pygame.image.load('resources/buttons/main/main_button03-0.png')
while running:
posm = pygame.mouse.get_pos()
window.blit(bg_img,(0,0))
window.blit(button0,(140,561))
window.blit(button1,(660,561))
window.blit(button2,(1208,17))
if posm[0] > 140 and posm[0] < 640 and posm[1] > 561 and posm[1] < 599:
button0 = pygame.image.load('resources/buttons/main/main_button01-1.png')
else:
button0 = pygame.image.load('resources/buttons/main/main_button01-0.png')
if posm[0] > 660 and posm[0] < 1160 and posm[1] > 561 and posm[1] < 599:
button1 = pygame.image.load('resources/buttons/main/main_button02-1.png')
else:
button1 = pygame.image.load('resources/buttons/main/main_button02-0.png')
if posm[0] > 1208 and posm[0] < 1264 and posm[1] > 17 and posm[1] < 73:
button2 = pygame.image.load('resources/buttons/main/main_button03-1.png')
else:
button2 = pygame.image.load('resources/buttons/main/main_button03-0.png')
for event in pygame.event.get():
if event.type == QUIT:
running = False
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
if posm[0] > 140 and posm[0] < 640 and posm[1] > 561 and posm[1] < 599:
pygame.mixer.music.pause()
Transition()
elif posm[0] > 660 and posm[0] < 1160 and posm[1] > 561 and posm[1] < 599:
Settings()
elif posm[0] > 1208 and posm[0] < 1264 and posm[1] > 17 and posm[1] < 73:
pygame.quit()
sys.exit()
clock.tick(60)
pygame.display.flip()
Main()