forked from mattboan/Galtron
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsettingsMenu.py
80 lines (68 loc) · 2.71 KB
/
settingsMenu.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
import sys
import pygame as pg
import sounds
# Create a variable to change current button being selected
image = pg.image.load('gfx/fixsetting4.png')
rect = image.get_rect()
def checkEvents1(setting, screen, stats, sb, bMenu, ship, aliens, bullets, eBullets):
"""Respond to keypresses and mouse events."""
for event in pg.event.get():
# Check for quit event
if event.type == pg.QUIT:
sys.exit()
# Check for key down has been pressed
elif event.type == pg.KEYDOWN:
# Check if down, up, enter, esc is pressed
if event.key == pg.K_DOWN:
sounds.control_menu.play()
bMenu.down()
if event.key == pg.K_UP:
sounds.control_menu.play()
bMenu.up()
if event.key == pg.K_RETURN:
sounds.select_menu.play()
selectedName, selectedBtn = bMenu.getSelectedButton()
if selectedBtn:
buttonAction(stats, selectedName, bMenu, setting, sb)
if event.key == pg.K_ESCAPE:
sys.exit()
elif event.type == pg.MOUSEMOTION:
mouseBtnName, mouseBtn = bMenu.mouseCheck(event.pos[0], event.pos[1])
if mouseBtn is not None:
selectedName, selectedBtn = bMenu.getSelectedButton()
if mouseBtn is not selectedBtn:
sounds.control_menu.play()
bMenu.selectByName(mouseBtnName)
elif event.type == pg.MOUSEBUTTONDOWN:
pressed = pg.mouse.get_pressed()
if (pressed[0]):
pos = pg.mouse.get_pos()
mouseBtnName, mouseBtn = bMenu.mouseCheck(pos[0], pos[1])
if mouseBtn is not None:
sounds.select_menu.play()
buttonAction(stats, mouseBtnName, bMenu, setting, sb)
def buttonAction(stats, selectedName, bMenu, setting, sb):
if selectedName == 'menu':
stats.setGameLoop('mainMenu')
elif selectedName == 'invert':
bMenu.invertColorAll()
setting.invertColor()
sb.invertColor()
stats.setGameLoop('mainMenu')
elif selectedName == 'quit':
pg.time.delay(300)
sys.exit()
elif selectedName == 'speed setting':
stats.setGameLoop('speedMenu')
elif selectedName == 'interception':
setting.checkBtnPressed += 1
if setting.checkBtnPressed % 2 != 0:
setting.interception = True
stats.setGameLoop('mainMenu')
def drawMenu(setting, screen, sb, bMenu):
"""Draw the menu and all of its elements"""
global image, rect
screen.fill(setting.bgColor)
screen.blit(image, rect)
bMenu.drawMenu()
pg.display.flip()