-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGame.py
More file actions
388 lines (336 loc) · 16.9 KB
/
Game.py
File metadata and controls
388 lines (336 loc) · 16.9 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
import cursor
from cursor import *
import pygame
from pygame.locals import *
import sys
import gui
import Play
import credit
import leaderboardMenu
import Robot_Skin_selector
import random
import Config
import Image
from Image import *
import Button
from Button import *
import TickBox
import textfield
import Sounds
import RadioButton
#if the script was run directly, this function will run
def createCanvas() :
pygame.init()
Config.loadConfig()
#,pygame.FULLSCREEN|pygame.HWSURFACE,32
canvas = pygame.display.set_mode((800,600))
menu1(canvas)
return
def menu1(canvas):
#this variable is for checking if the start button was clicked
inStart= 0
#if the settings button was clicked
inSettings= 0
#setting up the coordinates for the images and buttons
#left arrow
leftX = 10
leftY = 300
#right arrow
rightX = 280
rightY = 300
#sound
sX = 720
sY = 530
#robot
rX = 65
rY = 200
#credit button
cX = 460
cY = 370
#start button
startX = 480
startY = 185
#leaderboard button
lX = 380
lY = 315
#close button
eX = 500
eY = 435
#settings
setX = 445
setY = 245
#loading all images, buttons
#robot = image(canvas,(rX,rY),"robots/robot.png")
#robot.scale(300,300)
#robot.scale(200,200)
#transp = image(canvas,(10,140),"menu/transparrent.png")
helloW = image(canvas,(60,0),"menu/VR.png")
bgpart = image(canvas,(0,0),"menu/bgpart.png")
background = image(canvas,(0,0),"menu/wallpaper.jpg")
startB = button(canvas,(startX,startY),"buttons/start.png")
leftB = button(canvas,(leftX,leftY),"buttons/larrow.png")
rightB = button(canvas,(rightX,rightY),"buttons/rarrow.png")
soundOffB = button(canvas,(sX,sY),"buttons/soundoff.png")
soundOffB.scale(35,50)
soundOnB = button(canvas,(sX,sY),"buttons/soundon.png")
soundOnB.scale(60,50)
creditB = button(canvas,(cX,cY),"buttons/credits.png")
leaderboardB = button(canvas,(lX,lY),"buttons/Leaderboard.png")
closeB = button(canvas,(eX,eY),"buttons/exit.png")
single = button(canvas,(73,250),"buttons/Single-Player.png")
multi = button(canvas,(95,310),"buttons/Multiplayer.png")
ai = button(canvas,(170,370),"buttons/AI.png")
singleO = button(canvas,(73,250),"buttons/Single-PlayerO.png")
multiO = button(canvas,(95,310),"buttons/MultiplayerO.png")
aiO = button(canvas,(170,370),"buttons/AIO.png")
settingsB = button(canvas,(setX,setY),"buttons/Settings.png")
logo=image(canvas,(10,520),'logo/helloWorldStudio.png')
font = pygame.font.SysFont("calibri",25)
font1 = pygame.font.SysFont("calibri",15)
font1.set_bold(1)
font.set_bold(1)
text = font.render("Receive Emails:",1,(250,250,250))
text1 = font.render("Enter Email:",1,(250,250,250))
text2 = font.render("Enter Name:",1,(250,250,250))
easyTxt = font1.render("Easy",1,(250,250,250))
medTxt = font1.render("Medium",1,(250,250,250))
hardTxt = font1.render("Hard",1,(250,250,250))
difTxt = font.render("AI Difficulty:",1,(250,250,250))
#blitting everything
canvas.fill((0,0,0))
background.blit()
#transp.blit()
leaderboardB.blit()
creditB.blit()
helloW.blit()
closeB.blit()
#robot.blit()
startB.blit()
soundOffB.blit()
settingsB.blit()
logo.blit()
#initializing the tickbox and textfields
emailTickBox = TickBox.tickBox(canvas,(230,330))
if Config.config["receiveEmail"] ==True:
print "True"
emailTickBox.status = 1
emailTextField = textfield.textField(canvas,(20,270),(280,30),Config.config["email"],20)
nameTextField = textfield.textField(canvas,(20,180),(280,30),Config.config["name"],20)
easyBox = RadioButton.radioButton(canvas,(50,420))
medBox = RadioButton.radioButton(canvas,(130,420))
hardBox = RadioButton.radioButton(canvas,(210,420))
if Config.config["difficulty"]==1:easyBox.status=1
if Config.config["difficulty"]==2:medBox.status=1
if Config.config["difficulty"]==3:hardBox.status=1
#no sound when the game run, this var will be set to 1 if the sound button clicked
sound = 0
ran = ""
if sound == 1:
soundOnB.blit()
while True:
for event in pygame.event.get():
#if user hits x button, window closes
if event.type == QUIT:
Config.saveConfig()
pygame.quit()
sys.exit()
#if the user presses a key
if event.type == KEYDOWN :
#if esc key pressed, window closes
if event.key == K_ESCAPE :
Config.saveConfig()
pygame.quit()
sys.exit()
#if we are in the settings menu
if inSettings== 1:
#if the email textfield was clicked, user will write in it
if emailTextField.isSelected():
emailTextField.handle(event.key)
print event.key
#if the name textfield was clicked
elif nameTextField.isSelected():
nameTextField.handle(event.key)
print event.key
#getting position of the mouse
pos = pygame.mouse.get_pos()
#update stored name and email
Config.config["email"] = emailTextField.answer
Config.config["name"] = nameTextField.answer
#if user pressed the left mouse button
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 :
#play click sound
soundFXs = Sounds.Audio(False)
soundFXs.Plysound(False,False,True,False,False)
#if we are in the startmenu
if inStart== 1:
if multi.clicked():
gui.start(canvas,True,False,False,0,0)
#if singleplayer button was clicked, start in single player mode
if single.clicked():
gui.start(canvas,False,False,False,0,0)
#if ai button was clicked, start in ai mode
elif ai.clicked():
gui.start(canvas,False,False,True,Config.config["numAI"],Config.config["difficulty"])
#if we are in the settings menu
if inSettings== 1:
#if the email tickbox was clicked, untick/tick it
if emailTickBox.clicked():
Config.config["receiveEmail"] = not Config.config["receiveEmail"]
if easyBox.clicked():
Config.config["difficulty"] = 1
easyBox.check()
medBox.unCheck()
hardBox.unCheck()
easyBox.blit()
medBox.blit()
hardBox.blit()
elif medBox.clicked():
Config.config["difficulty"] = 2
easyBox.unCheck()
medBox.check()
hardBox.unCheck()
easyBox.blit()
medBox.blit()
hardBox.blit()
elif hardBox.clicked():
Config.config["difficulty"] = 3
easyBox.unCheck()
medBox.unCheck()
hardBox.check()
easyBox.blit()
medBox.blit()
hardBox.blit()
#if email textfield was clicked, select it and unselect the other one
elif emailTextField.clicked():
emailTextField.select()
nameTextField.off()
#if name textfield clicked
elif nameTextField.clicked():
nameTextField.select()
emailTextField.off()
elif (easyBox.collide(pos) or
medBox.collide(pos) or
hardBox.collide(pos) or
emailTextField.collide(pos) or
nameTextField.collide(pos) or
emailTickBox.collide(pos)):
pygame.mouse.set_cursor(*cursor.HAND_CURSOR)
else :
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
#if the start button was clicked
if startB.clicked() == 1 :
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
#we are in startmenu
inStart = 1
#not in settings menu
inSettings = 0
#reblit everything with the game mode buttons
background.blit()
#transp.blit()
leaderboardB.blit()
creditB.blit()
helloW.blit()
closeB.blit()
startB.blit()
soundOffB.blit()
logo.blit()
if sound == 1:
soundOnB.blit()
settingsB.blit()
single.blit()
multi.blit()
ai.blit()
#if settings button clicked
if settingsB.collide(pos):
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
inStart = 0
inSettings = 1
background.blit()
#transp.blit()
leaderboardB.blit()
creditB.blit()
helloW.blit()
closeB.blit()
startB.blit()
soundOffB.blit()
logo.blit()
if sound == 1:
soundOnB.blit()
settingsB.blit()
canvas.blit(text,(30,340))
canvas.blit(text1,(30,240))
canvas.blit(text2,(30,150))
emailTextField.blit()
nameTextField.blit()
canvas.blit(difTxt,(30,390))
emailTickBox.blit()
easyBox.blit()
medBox.blit()
hardBox.blit()
canvas.blit(easyTxt,(54,460))
canvas.blit(medTxt,(122,460))
canvas.blit(hardTxt,(213,460))
#if close button was clicked, window closes
elif closeB.collide(pos) :
pygame.quit()
sys.exit()
#if sound button was clicked and it was off
elif sound == 0 and soundOffB.collide(pos) == 1 :
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
inStart= 0
sound = 1
bgpart.blit()
soundOffB.blit()
soundOnB.blit()
soundFXs.playMusic()
#if it was on
elif sound == 1 and soundOnB.collide(pos) == 1 :
inStart= 0
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
pygame.mixer.music.stop()
pygame.mixer.init(44100, -16,2,2048)
sound = 0
bgpart.blit()
soundOffB.blit()
#if credit button clicked
elif creditB.clicked() :
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
credit.creditMenu(canvas)
#if leaderboard button was clicked
elif leaderboardB.clicked():
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
leaderboardMenu.leaderboardMenu(canvas)
#if we are in start menu
if inStart== 1:
#if collision with the game mode buttons, use hand cursor
if single.collide(pos):
pygame.mouse.set_cursor(*cursor.HAND_CURSOR)
singleO.blit()
elif multi.collide(pos):
pygame.mouse.set_cursor(*cursor.HAND_CURSOR)
multiO.blit()
elif ai.collide(pos):
pygame.mouse.set_cursor(*cursor.HAND_CURSOR)
aiO.blit()
#else use arrow
else :
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
single.blit()
multi.blit()
ai.blit()
#if collision with buttons, use hand cursor
if (settingsB.collide(pos) == 1 or
startB.collide(pos) == 1 or
leaderboardB.collide(pos) == 1 or
creditB.collide(pos) == 1 or
soundOffB.collide(pos) or
closeB.collide(pos)):
pygame.mouse.set_cursor(*cursor.HAND_CURSOR)
else :
pygame.mouse.set_cursor(*cursor.ARROW_CURSOR)
#print emailTickBox.getStatus(
pygame.display.update()
return
#if the script was run directly, run createCanvas function
if __name__ == "__main__" :
createCanvas()