-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiMenu.py
More file actions
85 lines (60 loc) · 2.39 KB
/
MultiMenu.py
File metadata and controls
85 lines (60 loc) · 2.39 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
#!/usr/bin/python
import pygame
import Resources
import PlayModeMenu
import MultiGameRabbitMenu
from Button import *
from Server import *
from pygame.locals import *
class MultiMenu():
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.mixer.init()
def __init__(self):
self.screen = pygame.display.get_surface()
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()
self.background.fill((50, 50, 50))
self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)
self.buttons = {}
self.buttons["server"] = Button(self.screen.get_width()/2 - 200/2, self.screen.get_height()/2 - 150 - 40/2, 200, 40, "SERVER")
self.buttons["client"] = Button(self.screen.get_width()/2 - 200/2, self.screen.get_height()/2 - 50 - 40/2, 200, 40, "CLIENT")
self.buttons["back"] = Button(self.screen.get_width()/2 - 200/2, self.screen.get_height()/2 + 50 - 40/2, 200, 40, "BACK")
pygame.display.flip()
def update(self):
key = pygame.key.get_pressed()
mouse = pygame.mouse.get_pressed()
for event in pygame.event.get():
if event.type == QUIT or (key[K_F4] and key[K_LALT]):
return False, self
elif event.type == MOUSEBUTTONDOWN:
mse = pygame.mouse.get_pos()
if self.buttons["server"].onButton(mse):
self.buttonSound.play()
server = Server('');
server.connect()
return True, MultiGameRabbitMenu.MultiGameRabbitMenu(server)
# server.accept()
# server.send(b"connexion avec client : OK")
# server.recieve()
elif self.buttons["client"].onButton(mse):
self.buttonSound.play()
return True, MultiGameRabbitMenu.MultiGameRabbitMenu()
# client = Client('localhost')
# client.connect()
# client.recieve()
# client.send(b"connexion avec serveur : OK")
elif self.buttons["back"].onButton(mse):
self.buttonSound.play()
return True, PlayModeMenu.PlayModeMenu()
elif event.type == MOUSEMOTION:
mse = pygame.mouse.get_pos()
pygame.mouse.set_cursor(*pygame.cursors.arrow)
for button in self.buttons.values():
if button.onButton(mse):
pygame.mouse.set_cursor(*pygame.cursors.tri_left)
self.screen.blit(self.background, self.background.get_rect(), self.background.get_rect())
for button in self.buttons.values():
button.update()
pygame.display.update()
return True, self