AI_Labyrinth/menu.py
Szymon Komosinski 37d1265b98 First deadline
2020-04-27 11:38:36 +02:00

83 lines
2.0 KiB
Python

import pygame as pg
from config import *
from gamemodes import *
def text_objects(text, font):
textSurface = font.render(text, True, purple)
return textSurface, textSurface.get_rect()
def button(msg, x, y, w, h, action=None):
mouse = pg.mouse.get_pos()
click = pg.mouse.get_pressed()
font = pg.font.SysFont("ubuntumono", 80)
if x+w > mouse[0] > x and y+h > mouse[1] > y:
textSurface = font.render(msg, True, purple)
if click[0] == 1 and action != None:
action()
else:
textSurface = font.render(msg, True, black)
textRectangle = textSurface.get_rect()
textRectangle.center = ((x + (w / 2)), (y + (h / 2)))
gameDisplay.blit(textSurface, textRectangle)
def quitgame():
pg.quit()
quit()
def unpause():
global pause
pause = False
def paused():
largeText = pg.font.SysFont("ubuntumono", 160)
TextSurf, TextRect = text_objects("Paused", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)
while pause:
for event in pg.event.get():
# print(event)
if event.type == pg.QUIT:
pg.quit()
quit()
# gameDisplay.fill(white)
button("Continue", 150, 450, 100, 50, unpause)
button("Quit", 550, 450, 100, 50, quitgame)
pg.display.update()
def game_intro():
intro = True
while intro:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
quit()
gameDisplay.fill(white)
largeText = pg.font.SysFont("ubuntumono", 160)
TextSurf, TextRect = text_objects("Key *Star Race", largeText)
TextRect.center = ((display_width / 2), (display_height / 4))
gameDisplay.blit(TextSurf, TextRect)
button("Singleplayer", 720, 360, 450, 100, singlePlayer)
button("Multiplayer", 738, 480, 450, 100)
button("Quit", 874, 600, 450, 100, quitgame)
pg.display.update()
clock.tick(15)