-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenu.py
More file actions
58 lines (50 loc) · 1.62 KB
/
Menu.py
File metadata and controls
58 lines (50 loc) · 1.62 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
# -*- coding: UTF-8 -*-
import pygame
from Screen import Screen
# a class representing the menu of the game
class Menu(Screen):
selectedItem = 0
# constructor
def __init__(self):
# initialize a basic font
self.basicFont = pygame.font.SysFont(None, 48)
# the update method with handles events
def update(self, event):
# handle keydown events
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
self.selectedItem += 1
if self.selectedItem == 2:
self.selectedItem = 0
if event.key == pygame.K_UP:
self.selectedItem -= 1
if self.selectedItem < 0:
self.selectedItem = 1
return;
# the draw method of the Menu
def draw(self, displayDevice):
# set up the text
displayDevice.fill((0, 0, 150))
text = self.basicFont.render('Mayday', True, (255, 255, 255), (0, 0, 255))
textRect = text.get_rect()
textRect.centerx = displayDevice.get_rect().centerx
textRect.centery = 100
displayDevice.blit(text, textRect)
# display menu items
if self.selectedItem == 1:
gameColor = (255, 255, 255)
optionColor = (0, 0, 0)
else:
gameColor = (0, 0, 0)
optionColor = (255, 255, 255)
text = self.basicFont.render('Start game', True, gameColor, (0, 0, 255))
textRect = text.get_rect()
textRect.centerx = 100
textRect.centery = 150
displayDevice.blit(text, textRect)
text = self.basicFont.render('Options', True, optionColor, (0, 0, 255))
textRect = text.get_rect()
textRect.centerx = 100
textRect.centery = 250
displayDevice.blit(text, textRect)
return;