forked from mattboan/Galtron
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathplayMenu.py
79 lines (65 loc) · 2.54 KB
/
playMenu.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
import sys
import pygame as pg
import sounds
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, ship)
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, ship)
def buttonAction(stats, selectedName, ship):
if selectedName in ('grey', 'red', 'blue'):
color = selectedName
if color == 'grey':
stats.setting.playerShipColor = 'gray'
elif color == 'red':
stats.setting.playerShipColor = 'red'
elif color == 'blue':
stats.setting.playerShipColor = 'blue'
stats.setGameLoop('mainGame')
elif selectedName == 'menu':
stats.setGameLoop('mainMenu')
elif selectedName == 'quit':
pg.time.delay(300)
sys.exit()
def drawMenu(setting, screen, sb, bMenu):
"""Draw the menu and all of its elements"""
screen.fill(setting.bgColor)
bMenu.drawMenu()
pg.display.flip()
def checkColor():
return 'gfx/player_' + color + '.png'
def drawimg():
img = pg.image.load('gfx/player_blue.bmp')
return 0