forked from mattboan/Galtron
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathabout.py
67 lines (55 loc) · 2.25 KB
/
about.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
import sys
import pygame as pg
import sounds
# Create a variable to change current button being selected
def checkEvents(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)
if event.key == pg.K_ESCAPE:
sounds.button_click_sound.play()
pg.time.delay(300)
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)
def buttonAction(stats, selectedName):
if selectedName == 'menu':
stats.setGameLoop('mainMenu')
if selectedName == 'quit':
pg.time.delay(300)
sys.exit()
def drawMenu(setting, screen, sb, bMenu, abautImage, abautImageRect):
"""Draw the menu and all of its elements"""
screen.fill(setting.bgColor)
screen.blit(abautImage, abautImageRect)
bMenu.drawMenu()
pg.display.flip()