Я не могу добавить текст поверх моих кнопок, поскольку он идет под ними, а также общий текст на экране без перехода на следующую страницу. Любая критика полезна, поскольку я пытаюсь узнать как можно больше. И любые советы о том, как создать движущийся фон, например, парящие облака, если вы понимаете, о чем я. Полный код здесь:
import pygame, sys
import pygame_menu
mainClock = pygame.time.Clock()
from pygame.locals import *
pygame.init()
pygame.display.set_caption('The Breakout')
screen = pygame.display.set_mode((500, 500), 0, 32)
font = pygame.font.SysFont(None, 20)
background_image = pygame.image.load("BG.jpg")
def draw_text(text, font, color, surface, x, y):
textobj = font.render(text,2, color)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
def text_objects(text, font):
black = (0,0,0)
white = (255,255,255)
surf = pygame.Surface(font.size(text))
surf.fill(white)
textSurface = font.render(text, True, black, surf)
return textSurface, textSurface.get_rect()
def main_menu():
while True:
screen.fill((0, 0, 0))
screen.blit(background_image, [0, 0])
draw_text('The Breakout', font, (255, 255, 255), screen, 215, 50)
mx, my = pygame.mouse.get_pos()
button_1 = pygame.Rect(150, 150, 200, 40)
button_2 = pygame.Rect(150, 250, 200, 40)
if button_1.collidepoint((mx, my)):
if click:
game()
if button_2.collidepoint((mx, my)):
if click:
options()
pygame.draw.rect(screen, (0,0,255), button_1)
pygame.draw.rect(screen, (0,0,255), button_2)
def drawText(text, font, surface, x, y, color):
textobj = font.render(text, 1, color)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
click = False
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
click = True
pygame.display.update()
mainClock.tick(60)
def game():
running = True
while running:
screen.fill((0, 0, 0))
screen.blit(background_image, [0, 0])
draw_text('Game', font, (255, 25, 255), screen, 230, 50)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
pygame.display.update()
mainClock.tick(60)
def options():
running = True
while running:
screen.fill((0, 0, 0))
screen.blit(background_image, [0, 0])
draw_text('User Guide', font, (255, 25, 255), screen, 215, 50)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
pygame.display.update()
mainClock.tick(60)
from pygame import mixer
mixer.music.load("music.mp3")
mixer.music.play(-1)
main_menu()