-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjareds.py
More file actions
322 lines (246 loc) · 11.4 KB
/
jareds.py
File metadata and controls
322 lines (246 loc) · 11.4 KB
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
import pygame
from pygame.mouse import get_pos
import pygame_gui
import random
pygame.init()
pygame.font.init() # you have to call this at the start,
# if you want to use this module.
# myfont = pygame.font.SysFont('jokerman', 65) #jokerman, showcardgothic, magneto, franklingothicheavy, impact
titleFont = pygame.font.SysFont('Cooper Black', 65)
width = 800
pygame.display.set_caption('Quick Start')
window_surface = pygame.display.set_mode((width, 600),0,32)
gameTitle = titleFont.render('Spanglish Matching!', False, (0, 0, 0))
#Denis Changes
bg_img = pygame.image.load('worldmap1024.jpg')
bg = pygame.transform.scale(bg_img, (width, 600))
####
mainScreenManager = pygame_gui.UIManager((width, 600))
first_sound = pygame.mixer.Sound("crash.mp3")
backgroundMusic = pygame.mixer.music.load("background.mp3")
pygame.mixer.music.set_volume(0.06)
pygame.mixer.music.play(-1)
# dictionary with the spanish and english words
d = {'english':['T-shirt','pants','skirt','socks','coat','shoes','boots',
'love','happy','tired','ready','box','wheel','can','wallet',
'screen','keyboard','bed','belt','glove','year','day','time',
'time(period of)','life','part','government','country','word',
'state','yes','no','maybe',"I don't know",'how','I','you',
'place','the','she'],
'spanish':['la camiseta','los pantalones','la falda','los calcetines','el abrigo',
'los zapatos','las botas','amor','feliz','consado','listo','cajón','rueda','lata',
'billetera','pantalla','teclado','cama','cinturón','guante','año','día','vez',
'tiempo','vida','parte','gobierno','país','mundo','estado','si','no','talvez',
'nose','cómo','yo','tu','lugar','el/la','ella']}
# Select 12 indeces for english and spanish words
randomSample = random.sample(list(range(len(d['english']))), 12)
# i had to create a list of just strings because the other one used "render" functions and wouldnt pass into class objects correctly
engList = []
spanList = []
englishWords=[]
spanishWords=[]
# Every word that's not header
studyFont = pygame.font.SysFont('Cooper Black', 40)
#Generate english/spanish lists, with corresponding indeces
for x in randomSample:
engList.append(d['english'][x])
spanList.append(d['spanish'][x])
englishWords.append(studyFont.render(d['english'][x], False, (0, 0, 0)))
spanishWords.append(studyFont.render(d['spanish'][x], False, (0, 0, 0)))
class word:
def __init__(self, palabra, cosa):
self.palabra = palabra
self.cosa = cosa
self.x = random.randrange(1,790,1) #creates a random position for x and y within the screen range for the object
self.y = random.randrange(1,790,1)
self.vx = 0#random.randrange(-3,3,1) #creats random direction and speed for the object
self.vy = 0#random.randrange(-3,3,1)
def draw(self):
thing = pygame.font.SysFont('Cooper Black', 20).render(self.palabra, False, (105,105,105))
self.cosa.blit(thing, (self.x, self.y))
def mover(self):
self.x += self.vx
self.y += self.vy
if self.x >= 790:
self.vx *= -1
self.x = 790
if self.x <= 0:
self.vx *= -1
self.x = 0
if self.y >= 600:
self.vy *= -1
self.y = 600
if self.y <= 0:
self.vy *= -1
self.y = 0
def mainScreen():
start_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((330, 275), (150, 50)),
text='Start!',
#Place it in main manager
manager=mainScreenManager)
show_words_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((330, 375), (150, 50)),
text='Study Words',
#Place it in main manager
manager=mainScreenManager)
exit_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((330, 475), (150, 50)),
text='Exit',
#Place it in main manager
manager=mainScreenManager)
#Create clock
clock = pygame.time.Clock()
is_running = True
#Background scrolling parameters
i = 0
#Main game loop
while is_running:
time_delta = clock.tick(60)/1000.0
#Needed (but don't know why)
for event in pygame.event.get():
#'X' top right closes game
if event.type == pygame.QUIT:
is_running = False
#Check if something we created is processed
if event.type == pygame.USEREVENT:
# Make sound when hovering over button
# if event.user_type == pygame_gui.UI_BUTTON_ON_HOVERED:
# pygame.mixer.Sound.play(first_sound)
# If button is pressed
if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
# If start button, start
if event.ui_element == start_button:
comienzo()
# If study button, study
if event.ui_element == show_words_button:
display_study_words(d,randomSample)
# If exit, exit
if event.ui_element == exit_button:
is_running = False
#Process buttons
mainScreenManager.process_events(event)
#Denis changes
#Scrolling background
window_surface.blit(bg, (i, 0))
window_surface.blit(bg, (width+i, 0))
#If image is at end, wrap image around
if i == -width:
window_surface.blit(bg, (width+i, 0))
#Reset i
i = 0
#Decrement i
i -= 1
####
#Display title
window_surface.blit(gameTitle,(95, 120))
#Update button logic
mainScreenManager.update(time_delta)
#Display buttons
mainScreenManager.draw_ui(window_surface)
#Show the display
pygame.display.update()
# I created 2 lists of objects, one in spanish and one in english
engObjs = [word(engList[i], window_surface) for i in range(12)]
spanObjs = [word(spanList[i], window_surface) for i in range(12)]
def comienzo():
clock = pygame.time.Clock()
running = True
while running:
time_delta = clock.tick(40)
window_surface.fill((0,0,0))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
running = False
# Here i am attempting to see if I can match the x,y of the cursor on button press to one of the words and print the word i clicked
elif event.type == pygame.MOUSEBUTTONDOWN:
for i in range(12):
if ((engObjs[i].x or spanObjs[i].x) == pygame.mouse.get_pos()[0]) and ((engObjs[i].y or spanObjs[i].y) == pygame.mouse.get_pos()[1]):
print(engObjs[i].palabra)
print(engObjs[0].x,engObjs[0].y)
print(engObjs[0].palabra)
print(pygame.mouse.get_pos())
elif event.type == pygame.QUIT:
pygame.quit()
running = False
exit(0)
# this calls the mover functions and updated draw functions of the objects every loop
for i in range(12):
engObjs[i].mover()
engObjs[i].draw()
spanObjs[i].mover()
spanObjs[i].draw()
# updates the postions of the objects that were changed because of their class functions
pygame.display.update()
def display_study_words(engSpanDict,randomSample):
# Header font is bigger
headerFont = pygame.font.SysFont('Cooper Black', 60)
#Separate manager for study words screen
studyManager = pygame_gui.UIManager((width, 600))
# Clock needed to update manager (don't know why.)
clock = pygame.time.Clock()
#Back to the main screen
back_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((50, 545), (150, 50)),
text='Back',
#Study manager
manager=studyManager)
#Start the game from the study page
start_from_study_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((530, 545), (150, 50)),
text='Start',
#Study manager
manager=studyManager)
#Initialize english/spanish lists
while True:
time_delta = clock.tick(60)/1000.0
#Make the screen white
window_surface.fill((255,255,255))
#Needed (but don't know why)
for event in pygame.event.get():
#'X' top right closes game
if event.type == pygame.QUIT:
#Exit the program
exit(0)
#Check if something we created is processed
if event.type == pygame.USEREVENT:
#If button is pressed
if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
#Back button
if event.ui_element == back_button:
#Exit out of this function, returns to where it was called, which is in mainScreen.
return
#Start button
if event.ui_element == start_from_study_button:
#Start the game
comienzo()
#Update studyManager
studyManager.process_events(event)
#Display English header
window_surface.blit(headerFont.render('English', False, (0, 0, 0)),(95, -10))
#Display separating pipes
window_surface.blit(studyFont.render('|', False, (0, 0, 0)),(390, 0))
#Overlap to look clean
window_surface.blit(studyFont.render('|', False, (0, 0, 0)),(390, 20))
#Display Spanish header
window_surface.blit(headerFont.render('Spanish', False, (0, 0, 0)),(515, -10))
#Display separating rows
window_surface.blit(studyFont.render('________________________________', False, (0, 0, 0)),(75, 8))
#First word starts at height 50
wordHeight = 50
for x in range(len(randomSample)):
#English word
window_surface.blit(englishWords[x],(95, wordHeight))
#Separating rows
window_surface.blit(studyFont.render('________________________________', False, (0, 0, 0)),(75, wordHeight))
#Separating columns
window_surface.blit(studyFont.render('|',False,(0,0,0)),(390, wordHeight))
window_surface.blit(studyFont.render('|',False,(0,0,0)),(390, wordHeight+20))
#Spanish word
window_surface.blit(spanishWords[x],(515, wordHeight))
#Update wordHeight
wordHeight += 40
#Update manager (for the buttons)
studyManager.update(time_delta)
#Display buttons
studyManager.draw_ui(window_surface)
#Update the display of the pygame
pygame.display.update()
#Call main
mainScreen()