LF08/win_screen.py
2023-05-08 22:25:18 +02:00

49 lines
1.8 KiB
Python

import pygame
import sys
class WinScreen(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.label = pygame.font.SysFont("Arial", 50).render("Win", True, (255, 0, 0))
self.rect = self.label.get_rect(center=(400, 300))
def draw(self, win):
win.fill((0, 0, 0)) # Black
win.blit(self.label, self.rect)
self.start_quit(win)
@staticmethod
def start_quit(win):
# Rechtecke
start_button = pygame.Rect(200, 400, 100, 50)
quit_button = pygame.Rect(500, 400, 120, 50)
# Schriftart
font = pygame.font.Font(None, 32)
# Text
start_text = font.render("Start", True, (0, 0, 0))
quit_text = font.render("Beenden", True, (0, 0, 0))
# Buttons zeichnen
pygame.draw.rect(win, (100, 100, 100), start_button)
win.blit(start_text, (start_button.x + 25, start_button.y + 10))
pygame.draw.rect(win, (100, 100, 100), quit_button)
win.blit(quit_text, (quit_button.x + 10, quit_button.y + 10))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = event.pos
# Start-Button
if start_button.collidepoint(mouse_pos) or \
start_text.get_rect(center=(start_button.x + 50, start_button.y + 25)).collidepoint(mouse_pos):
game.start()
# Beenden-Button
if quit_button.collidepoint(mouse_pos) or \
quit_text.get_rect(center=(quit_button.x + 60, quit_button.y + 25)).collidepoint(mouse_pos):
pygame.quit()
sys.exit()