-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_game.py
232 lines (177 loc) · 8.13 KB
/
language_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
import pygame
#get more fonts here: https://www.fontsquirrel.com/fonts/list/popular
# pygame setup
pygame.init()
programIcon = pygame.image.load('icon.png')
pygame.display.set_icon(programIcon)
#screen setups
X, Y=1280, 720
screen = pygame.display.set_mode((X, Y))
pygame.display.set_caption('Language Game')
clock = pygame.time.Clock() #keeps track of time (FPs)
running = True
dt = 0 #delta time
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2) #middle
#loading images
cyrillic = pygame.image.load("./images/cyrillic.png").convert()
greek = pygame.image.load("./images/greek.png").convert()
hebrew = pygame.image.load("./images/hebrew.png").convert()
burmese = pygame.image.load("./images/burmese.png").convert()
chinese = pygame.image.load("./images/chinese.png").convert()
japanese = pygame.image.load("./images/japanese.png").convert()
#Displaying something
def display_something(text:str, position_X:int, position_Y:int, is_instruction=False):
text_colour = (100, 150, 200)
if is_instruction:
text_colour = (50, 70, 50)
font = pygame.font.Font('./font/PlayfairDisplay-Regular.otf', 40)
text = font.render(text, True, text_colour, None)
textRect = text.get_rect()
textRect.center = (position_X, position_Y)
return text, textRect
#getting some sprites in the game
class SpriteObject(pygame.sprite.Sprite):
def __init__(self, x, y,text, correction, is_correct = False):
super().__init__()
text_colour = (0, 150, 200)
font = pygame.font.Font('./font/PlayfairDisplay-Bold.otf', 32)
self.original_image = font.render(text, True, text_colour, None)
self.hover_image = font.render(text, True, (255,255,255), None)
if is_correct:
self.click_image = font.render(correction, True, (120, 220, 120), None)
else:
self.click_image = font.render(correction, True, (240,140,140), None)
self.image = self.original_image
self.rect = self.image.get_rect(center=(x, y))
self.hover = False
self.clicked = False
def update(self, event_list):
mouse_pos = pygame.mouse.get_pos()
mouse_buttons = pygame.mouse.get_pressed()
self.hover = self.rect.collidepoint(mouse_pos)
# self.hover = self.rect.collidepoint(mouse_pos) and any(mouse_buttons)
for event in event_list:
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
self.clicked = not self.clicked
self.image = self.click_image if self.clicked else (self.hover_image if self.hover else self.original_image)
instructions=display_something('Which alphabet is this?', X//2, 50, is_instruction=True)
next_question=display_something('To access the next question, just press "n" on your keyboard', X // 2, Y - 50, is_instruction= True)
final_message = display_something('Congratulations, you have completed the game!', X//2, Y//2)
#sprite_object = SpriteObject(*screen.get_rect().center, (128, 128, 0))
group = pygame.sprite.Group([
SpriteObject(X // 2, Y // 2, "Cyrillic","Correct", is_correct=True),
SpriteObject(X // 2, Y // 2 - 100, "Greek","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 100, "Kannada","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 200, "Latin","Incorrect, bouh")
])
group_1 = pygame.sprite.Group([
SpriteObject(X // 2, Y // 2, "Arabic","Incorrect"),
SpriteObject(X // 2, Y // 2 - 100, "Cyrillic","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 100, "Ukrainian Cyrillic","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 200, "Greek","Correct", is_correct=True)
])
group_2 = pygame.sprite.Group([
SpriteObject(X // 2, Y // 2, "Kannada","Incorrect"),
SpriteObject(X // 2, Y // 2 - 100, "Hebrew","Correct", is_correct=True),
SpriteObject(X // 2, Y // 2 + 100, "Georgian","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 200, "Devanagari","Incorrect, bouh")
])
group_3 = pygame.sprite.Group([
SpriteObject(X // 2, Y // 2, "Hindi","Incorrect"),
SpriteObject(X // 2, Y // 2 - 100, "Latin","Incorrect"),
SpriteObject(X // 2, Y // 2 + 100, "Cherokee","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 200, "Burmese","Correct",is_correct=True)
])
group_4 = pygame.sprite.Group([
SpriteObject(X // 2, Y // 2, "Japanese","Correct", is_correct=True),
SpriteObject(X // 2, Y // 2 - 100, "Devanagari","Incorrect"),
SpriteObject(X // 2, Y // 2 + 100, "Armenian","Incorrect, bouh"),
SpriteObject(X // 2, Y // 2 + 200, "Burmese","Incorrect")
])
group_5 = pygame.sprite.Group([
SpriteObject(X // 2, Y // 2, "Cherokee","Incorrect"),
SpriteObject(X // 2, Y // 2 - 100, "Japanese","Incorrect"),
SpriteObject(X // 2, Y // 2 + 100, "Chinese","Correct", is_correct=True),
SpriteObject(X // 2, Y // 2 + 200, "Korean","Incorrect")
])
change_question=False
i = 0
while running:
event_list = pygame.event.get()
# poll for events
# pygame.QUIT event means the user clicked X to close your window
for event in event_list:
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_n:
change_question=True
i += 1
if i == 0:
screen.fill((220,240,240))
screen.blit(cyrillic, (X / 2 - cyrillic.get_width() / 2, Y / 5 - cyrillic.get_height() / 5))
group.update(event_list)
group.draw(screen)
screen.blit(instructions[0], instructions[1])
screen.blit(next_question[0], next_question[1])
elif i == 1:
screen.fill((220, 240, 240))
screen.blit(greek, (X / 2 - greek.get_width() / 2, Y / 5 - greek.get_height() / 5))
group_1.update(event_list)
group_1.draw(screen)
screen.blit(instructions[0], instructions[1])
screen.blit(next_question[0], next_question[1])
pygame.display.flip()
elif i == 2:
screen.fill((220, 240, 240))
screen.blit(hebrew, (X / 2 - hebrew.get_width() / 2, Y / 5 - hebrew.get_height() / 5))
group_2.update(event_list)
group_2.draw(screen)
screen.blit(instructions[0], instructions[1])
screen.blit(next_question[0], next_question[1])
pygame.display.flip()
elif i == 3:
screen.fill((220, 240, 240))
screen.blit(burmese, (X / 2 - burmese.get_width() / 2, Y / 5 - burmese.get_height() / 5))
group_3.update(event_list)
group_3.draw(screen)
screen.blit(instructions[0], instructions[1])
screen.blit(next_question[0], next_question[1])
pygame.display.flip()
elif i == 4:
screen.fill((220, 240, 240))
screen.blit(japanese, (X / 2 - japanese.get_width() / 2, Y / 5 - japanese.get_height() / 5))
group_4.update(event_list)
group_4.draw(screen)
screen.blit(instructions[0], instructions[1])
screen.blit(next_question[0], next_question[1])
pygame.display.flip()
elif i == 5:
screen.fill((220, 240, 240))
screen.blit(chinese, (X / 2 - chinese.get_width() / 2, Y / 5 - chinese.get_height() / 5))
group_5.update(event_list)
group_5.draw(screen)
screen.blit(instructions[0], instructions[1])
screen.blit(next_question[0], next_question[1])
pygame.display.flip()
else:
screen.fill((220, 240, 240))
screen.blit(final_message[0], final_message[1])
#pygame.draw.circle(screen, "blue", player_pos, 20)
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
player_pos.y -= 300 * dt
if keys[pygame.K_s]:
player_pos.y += 300 * dt
if keys[pygame.K_a]:
player_pos.x -= 300 * dt
if keys[pygame.K_d]:
player_pos.x += 300 * dt
# flip() the display to put your work on screen
pygame.display.flip()
# limits FPS to 60
# dt is delta time in seconds since last frame, used for framerate-
# independent physics.
dt = clock.tick(60) / 1000
pygame.quit()