-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.py
48 lines (40 loc) · 1.51 KB
/
text.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
import pygame
import pygame.freetype
pygame.mixer.init()
pygame.freetype.init()
ans = ""
keysdown = set()
key = pygame.mixer.Sound("assets/keyuc.wav")
returnkey = pygame.mixer.Sound("assets/returnuc.wav")
class Text:
pass
class Answer(Text):
def __init__(self, x, y, RES):
self.x = x
self.y = y
self.RES = RES
self.fontsize = int(RES[0]/30)
def update(self, pressedkeys, questions_set, window, zombies, active_zombies):
global ans, keysdown
for event in pressedkeys:
if event.type == pygame.KEYDOWN:
key.play()
if event.key not in keysdown:
keysdown.add(event.key)
if event.key == pygame.K_RETURN:
returnkey.play()
for i in active_zombies:
if not i.rock:
i.check(questions_set, ans)
ans = ""
elif event.key == pygame.K_BACKSPACE:
ans = ans[0:-1]
else:
ans = ans + event.unicode
if event.type == pygame.KEYUP:
keysdown.discard(event.key)
font = pygame.font.Font(None, self.fontsize)
answer = font.render(ans + "|", 0, (255,255,255))
window.blit(answer,(self.x,self.y))
typeheretext = font.render("Type answer below >", 0, (255,255,255))
window.blit(typeheretext,(self.x - self.fontsize,self.y-self.fontsize))