-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu.py
62 lines (46 loc) · 1.8 KB
/
menu.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
#!/usr/bin/python
import pygame
from pygame.locals import *
import math
import numpy as np
from os import listdir
from os.path import isfile, join
import random
import numpy as np
import cv2
pygame.init()
class Menu():
def __init__(self, screen, items, backGroundColor=(0,200,0), font=None, fontSize=30, fontColor=(255, 255, 255)):
self.screen = screen
self.screenWidth = self.screen.get_rect().width
self.screenHeight = self.screen.get_rect().height
self.backGroundColor = backGroundColor
self.items = items
self.font = pygame.font.SysFont(font, fontSize)
self.fontColor = fontColor
self.clock = pygame.time.Clock()
self.items = []
for item in items:
label = self.font.render(item, 1, fontColor)
width = label.get_rect().width
height = label.get_rect().height
totalHeightTextBox = len(items) * height
coordinates = ((self.screenWidth / 2) - (width / 2),(self.screenHeight / 2) - (totalHeightTextBox / 2))
self.items.append([item, label, (width, height), coordinates])
def run(self):
mainloop = True
while mainloop:
self.clock.tick(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
mainloop = False
self.screen.fill(self.backGroundColor)
for name, label, (width, height), coordinates in self.items:
self.screen.blit(label, coordinates)
pygame.display.flip()
if __name__ == "__main__":
screen = pygame.display.set_mode((640, 480), 0, 32)
menu_items = ('Start', 'Settings','Quit')
pygame.display.set_caption('Shooter Platform Game Menu')
res = Menu(screen, menu_items)
res.run()