-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainMenu.py
176 lines (150 loc) · 5.95 KB
/
mainMenu.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
from random import randint, shuffle
from time import time
import game_values as GAMEVALUES
from fct import *
from visuals import flash
import interface
import res
class MainMenu():
def __init__(self, clock):
self.redirect = None
self.clock = clock
self.gameLaunchArgs = GAMEVALUES.normal_mode
self.diffNb = 2
self.clickTxt = None
if res.firstLaunch:
self.clickTxt = res.fonts["simpleText"].render(res.language["rightClick"], 1, (255, 255, 255))
self.diffNb = 3
self.gameLaunchArgs = GAMEVALUES.easy_mode
self.diffText = res.fonts["simpleText"].render(res.language["easy"], 1, (255, 255, 70))
else:
self.diffText = res.fonts["simpleText"].render(res.language["normal"], 1, (255, 255, 70))
self.playButton = interface.button(res.language["play"], (683, 300))
self.statsButton = interface.button(res.language["stats"], (683, 370))
self.prefButton = interface.button(res.language["settings"], (683, 440))
self.quitButton = interface.button(res.language["quit"], (683, 510))
self.bgButton = interface.button(str(int(res.settings["MOVING_BG"])), (1336, 728))
self.maniaButton = interface.button("maniacobra.com", (1235, 35), True)
self.htpButton = interface.button(res.language["howToPlay"], (150, 728), True)
self.allButtons = pygame.sprite.Group(self.playButton, self.prefButton, self.statsButton, self.quitButton, self.bgButton, self.maniaButton, self.htpButton)
self.mailTxt = res.fonts["mainFont"].render("{} : {}".format(res.language["contact"], res.mail), 1, (255, 255, 255))
self.titlePos = res.images["title"][0].get_rect(centerx=675, y=100)
self.version = res.fonts["simpleText"].render(GAMEVALUES.version, 1, (200, 200, 200))
self.copyright = res.fonts["simpleText"].render("© Maniacobra 2019", 1, (200, 200, 200))
self.transition = pygame.sprite.GroupSingle(flash((0, 0, 0), 255, 30))
def update(self, animBg):
animBg.update()
self.titlePos.centerx = 675
self.titlePos.y = 100
self.titlePos = self.titlePos.move(randint(0, 3)-1, randint(0, 3)-1)
for event in pygame.event.get():
if event.type == QUIT:
self.redirect = "q"
elif event.type == MOUSEMOTION:
for butt in self.allButtons:
butt.mousePos = scalePos(event.pos)
elif event.type == KEYDOWN and event.key == K_RETURN and res.settings["DEVTOOLS"]:
self.redirect = "launchTest"
elif event.type == MOUSEBUTTONDOWN and event.button == 1:
if (res.stats["diff_normal"][1] > 0 or res.stats["diff_hard"][1] > 0 or 0 < self.diffNb < 4) and self.playButton.click():
self.redirect = "launchGame"
if res.firstLaunch:
self.redirect = "tuto_launch"
elif self.statsButton.click():
self.redirect = "stats"
elif self.prefButton.click():
self.redirect = "sett"
elif self.quitButton.click():
self.redirect = "q"
elif self.htpButton.click():
self.redirect = "tuto"
elif self.bgButton.click():
if res.settings["MOVING_BG"]:
res.settings["MOVING_BG"] = False
else:
res.settings["MOVING_BG"] = True
self.bgButton.changeText(str(int(res.settings["MOVING_BG"])))
res.save_settings()
elif self.maniaButton.click():
res.openUrl("web")
elif event.type == MOUSEBUTTONDOWN and event.button == 3 and self.playButton.mouseOn:
self.clickTxt = None
res.soundMananger.playSound("click")
self.diffNb -= 1
if self.diffNb < 0:
self.diffNb = 4
if self.diffNb == 0:
self.gameLaunchArgs = GAMEVALUES.challenge_mode
diffStr = "challenge"
if res.stats["diff_normal"][1] == 0 and res.stats["diff_hard"][1] == 0:
self.playButton.changeText(res.language["locked"], True)
elif self.diffNb == 1:
self.gameLaunchArgs = GAMEVALUES.hard_mode
diffStr = "hard"
elif self.diffNb == 2:
self.gameLaunchArgs = GAMEVALUES.normal_mode
diffStr = "normal"
elif self.diffNb == 3:
self.gameLaunchArgs = GAMEVALUES.easy_mode
diffStr = "easy"
self.playButton.changeText(res.language["play"], False)
elif self.diffNb == 4:
self.gameLaunchArgs = GAMEVALUES.s_challenge_mode
diffStr = "s-challenge"
if res.stats["diff_normal"][1] == 0 and res.stats["diff_hard"][1] == 0:
self.playButton.changeText(res.language["locked"], True)
elif self.diffNb == 5:
self.gameLaunchArgs = GAMEVALUES.s_easy_mode
diffStr = "s-easy"
self.playButton.changeText(res.language["play"], False)
self.diffText = res.fonts["simpleText"].render(res.language[diffStr], 1, (255, 255, 70))
self.allButtons.update()
self.transition.update()
def show(self, window, animBg):
animBg.draw(window)
window.blit(self.version, (0, 0))
window.blit(self.copyright, (0, 15))
window.blit(res.images["title"][0], self.titlePos)
self.allButtons.draw(window)
if self.playButton.mouseOn:
diffTextRect = self.diffText.get_rect(centery=self.playButton.rect.y-6)
diffTextRect.centerx = self.playButton.rect.centerx+10
dtc_border = diffTextRect.inflate(16, 10)
window.fill((50, 50, 50), dtc_border)
pygame.draw.rect(window, (200, 200, 200), dtc_border, 2)
window.blit(self.diffText, diffTextRect)
if self.clickTxt is not None:
window.blit(self.clickTxt, (775, 290))
self.transition.draw(window)
def reinit(self):
self.redirect = None
for butt in self.allButtons:
butt.reinit()
class TutoMenu():
def __init__(self, lg=False):
self.redirect = None
self.slide = 0
self.launchGame = lg
self.dedis = None
def update(self):
for event in pygame.event.get():
if event.type == QUIT:
self.redirect = "q"
elif event.type == MOUSEBUTTONDOWN and event.button in (1, 3):
res.soundMananger.playSound("click")
self.slide += 1
if self.slide == 3:
if self.launchGame:
self.redirect = "launchGame"
self.launchGame = False
else:
self.redirect = "main"
self.slide = 2
def show(self, window):
if self.dedis is None:
window.blit(res.images["tutorial"][self.slide], (0, 0))
else:
window.blit(self.dedis, (0, 0))