-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuScene.py
executable file
·69 lines (60 loc) · 2.02 KB
/
MenuScene.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
import pygame
from Constants import *
from Scene import Scene
from GamePlayScene import GamePlayScene
from Level import *
class MenuItem:
def __init__(self, pos, text, font):
self.__pos = pos
self.__hovered = False
self.__text = text
self.__font = font
self.__item = self.__font.render(self.__text, True, self.getColor())
self.__rect = self.__item.get_rect()
self.__rect.topleft = pos
def getColor(self):
if self.__hovered:
return BLUE
else:
return WHITE
def draw(self, screen):
self.__item = self.__font.render(self.__text, True, self.getColor())
screen.blit(self.__item,self.__pos)
def getRect(self):
return self.__rect
def setHover(self, hovered):
self.__hovered = hovered
class MenuScene(Scene):
def __init__(self, game):
self.__game = game
self.__screen = game.getScreen()
self.__font=pygame.font.SysFont(None,50)
self.__item1 = MenuItem((60,60),"Single Player", self.__font)
self.__item2 = MenuItem((60,130),"Two Player", self.__font)
self.__item3 = MenuItem((60,200),"Exit", self.__font)
def update(self):
if self.__item1.getRect().collidepoint(pygame.mouse.get_pos()):
self.__item1.setHover(True)
else:
self.__item1.setHover(False)
if self.__item2.getRect().collidepoint(pygame.mouse.get_pos()):
self.__item2.setHover(True)
else:
self.__item2.setHover(False)
if self.__item3.getRect().collidepoint(pygame.mouse.get_pos()):
self.__item3.setHover(True)
else:
self.__item3.setHover(False)
def draw(self):
self.__item1.draw(self.__screen)
self.__item2.draw(self.__screen)
self.__item3.draw(self.__screen)
def handleEvents(self, events):
for event in events:
if event.type == pygame.MOUSEBUTTONUP:
if self.__item1.getRect().collidepoint(pygame.mouse.get_pos()):
self.__game.setLevel(Level_1_SinglePlayer())
self.__game.changeScene(GamePlayScene(self.__game))
if self.__item2.getRect().collidepoint(pygame.mouse.get_pos()):
self.__game.setLevel(Level_1_MultiPlayer())
self.__game.changeScene(GamePlayScene(self.__game))