2021-09-10 19:22:30 +02:00
|
|
|
import gamedata.objects.menu.menu as menu
|
|
|
|
|
|
|
|
class MainMenu(menu.Menu):
|
|
|
|
def __init__(self,x,y,game,w=100,h=100):
|
|
|
|
super().__init__(x,y,game,w,h) # initialise l'objet de base avec les bons arguments
|
2021-09-10 21:33:24 +02:00
|
|
|
# Buttons dictionnaries
|
2021-09-10 19:22:30 +02:00
|
|
|
def fnPlay(self,game):
|
2021-09-10 21:33:24 +02:00
|
|
|
game.scene = game.scenes.ingame
|
2021-09-10 19:22:30 +02:00
|
|
|
btnPlay = {"name":"Play","function":fnPlay}
|
|
|
|
def fnOptions(self,game):
|
|
|
|
game.scene = game.scenes.options
|
|
|
|
btnOptions= {"name":"Options","function": fnOptions}
|
|
|
|
def fnQuit(self,game):
|
|
|
|
game.running = False
|
|
|
|
btnQuit= {"name":"Quit","function": fnQuit}
|
|
|
|
|
|
|
|
# Spacing between buttons
|
|
|
|
self.vpadding = 20
|
|
|
|
self.hpadding = 20
|
|
|
|
|
|
|
|
# Initialising grid
|
|
|
|
self.grid = [
|
|
|
|
[btnPlay],
|
|
|
|
[btnOptions],
|
|
|
|
[btnQuit]
|
|
|
|
]
|
|
|
|
|
|
|
|
self.create(self.grid,self.rect)
|
|
|
|
|
2021-09-16 08:34:40 +02:00
|
|
|
self.depth = -1
|
2021-09-18 10:23:40 +02:00
|
|
|
|
2021-09-16 08:34:40 +02:00
|
|
|
# Shadow sprite
|
|
|
|
shadow = game.sprite_lib["shadow.png"]
|
|
|
|
self.shadow = game.pygame.transform.scale(shadow,(1000,1000)) # J'augmente la taille de l'ombre
|
|
|
|
|
2021-09-18 10:23:40 +02:00
|
|
|
# Animation timer
|
|
|
|
self.timer = game.lib.Timer(1.5)
|
|
|
|
|
|
|
|
self.buttonsmaxoffset = 400
|
|
|
|
self.buttonsoffset = 400
|
|
|
|
self.titleoffset = 400
|
|
|
|
self.titlemaxoffset = 400
|
|
|
|
|
|
|
|
self.stop = False
|
|
|
|
|
|
|
|
def step(self):
|
|
|
|
super().step()
|
|
|
|
if not self.stop and self.timer.tick(self.game.dt):
|
|
|
|
self.stop = True
|
|
|
|
self.buttonsoffset = 0
|
|
|
|
if not self.stop:
|
|
|
|
self.buttonsoffset = self.timer.getratio()**4*self.buttonsmaxoffset
|
|
|
|
self.titleoffset = 0
|
|
|
|
if not self.stop:
|
|
|
|
self.titleoffset = self.timer.getratio()**4*self.titlemaxoffset
|
|
|
|
|
|
|
|
# Move the buttons
|
|
|
|
for btn in self.lbuttons:
|
|
|
|
btn.rect[1] = btn.baserect[1]+self.buttonsoffset
|
|
|
|
|
2021-09-10 19:22:30 +02:00
|
|
|
def draw(self):
|
2021-09-18 10:23:40 +02:00
|
|
|
# Shadow
|
|
|
|
self.game.lib.drawcenter(self.game,self.shadow,self.game.DISPLAY_WIDTH/2,self.game.DISPLAY_HEIGHT*3/5+self.buttonsoffset)
|
2021-09-10 19:22:30 +02:00
|
|
|
# Display game title
|
2021-09-18 10:23:40 +02:00
|
|
|
self.game.lib.drawcenter(self.game,self.game.sprite_lib["gui/title.png"],self.game.DISPLAY_WIDTH/2,self.baserect[1]-self.game.DISPLAY_HEIGHT/8-self.titleoffset)
|