-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
106 lines (75 loc) · 3.63 KB
/
menu.py
File metadata and controls
106 lines (75 loc) · 3.63 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import pygame, sys
from pygame.locals import *
from button import Button
from game import Game
from window import Window
class MainMenu(Window):
playing = True
def __init__(self, title, width, height, bg_path):
# background
self.bg = pygame.image.load(bg_path)
Window.__init__(self, title, width, height)
#initialisation de pygame et pour l'affichage
pygame.init()
self.clock = pygame.time.Clock()
#volume du jeu
volume = 1.0
#pour la police d'écriture
self.screen.fill((0,0,0))
def _set_title(self, title):
self._title = title
def _get_title(self):
return self._title
def _set_width(self, width):
self._width = width
def _get_width(self):
return self._width
def _set_height(self, height):
self._height = height
def _get_height(self):
return self._height
def _set_bg_path(self, bg_path):
self._bg_path = bg_path
def _get_bg_path(self):
return self._bg_path
title = property(_get_title, _set_title)
width = property(_get_width, _set_width)
height = property(_get_height, _set_height)
bg_path = property(_get_bg_path, _set_bg_path)
def gameLoop(self):
def get_font(size): # Returns Press-Start-2P in the desired size
return pygame.font.Font("assets/font.ttf", size)
while self.playing:
self.screen.blit(self.bg, (0,0))
#pour avoir la position de la souris
menu_mouse_pos = pygame.mouse.get_pos()
playButton = Button(image=pygame.image.load("assets/images/Play Rect.png"), pos=(640,250), text_input="JOUER", font=get_font(75), base_color=(215, 252, 212), hovering_color=(255, 255, 255))
optButton = Button(image=pygame.image.load("assets/images/Option Rect.png"), pos=(640, 400), text_input="OPTIONS", font=get_font(75), base_color=(215, 252, 212), hovering_color=(255, 255, 255))
quitButton = Button(image=pygame.image.load("assets/images/Quit Rect.png"), pos=(640, 550), text_input="QUIT", font=get_font(75), base_color=(215, 252, 212), hovering_color=(255, 255, 255))
#pour changer la couleur du bouton quand on passe dessus
for button in [playButton, quitButton, optButton]:
button.changeColor(menu_mouse_pos)
button.update(self.screen)
#pour les events bouton et quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#pour checker si un bouton est cliqué
elif event.type == pygame.MOUSEBUTTONDOWN:
#pour quitter
if quitButton.checkForInput(menu_mouse_pos):
pygame.quit()
sys.exit()
if playButton.checkForInput(menu_mouse_pos):
gameMenu = Game("Generating chickens", 1280, 720, "assets/images/bgGame.jpg")
#pour quitter avec echap
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
main.playing = False
pygame.quit()
sys.exit()
#pour actualiser l'affichage
pygame.display.flip()
self.clock.tick(60) #nombre d'image par seconde
main = MainMenu("Main Menu", 1280, 720, "assets/images/bgMenu.jpg")