Ich wollte nur fragen, was an diesem Python-Skript falsch ist. Es wird nur keine Rückmeldung angezeigt:
import pygame
# Initialisierung von Pygame
pygame.init()
# Fenstergröße festlegen
window_width = 800
window_height = 600
window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("Plattform-Spiel")
# Farben definieren
black = (0, 0, 0)
white = (255, 255, 255)
# Spielergröße und Position
player_width = 50
player_height = 50
player_x = window_width // 2 - player_width // 2
player_y = window_height - player_height
# Spielerbewegung
player_x_speed = 0
player_y_speed = 0
player_jump_power = -10
gravity = 0.5
# Plattformgröße und Position
platform_width = 200
platform_height = 20
platform_x = window_width // 2 - platform_width // 2
platform_y = window_height - platform_height - 50
# Hauptspielschleife
running = True
while running:
window.fill(white)
# Ereignisse verarbeiten
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
player_x_speed = -5
elif event.key == pygame.K_RIGHT:
player_x_speed = 5
elif event.key == pygame.K_SPACE:
if player_y == window_height - player_height:
player_y_speed = player_jump_power
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
player_x_speed = 0
# Spielerbewegung aktualisieren
player_x += player_x_speed
player_y += player_y_speed
player_y_speed += gravity
# Kollisionserkennung mit Plattform
if player_y + player_height >= platform_y and player_y_speed >= 0:
if player_x + player_width >= platform_x and player_x <= platform_x + platform_width:
player_y = platform_y - player_height
player_y_speed = 0
# Spieler zeichnen
pygame.draw.rect(window, black, (player_x, player_y, player_width, player_height))
# Plattform zeichnen
pygame.draw.rect(window, black, (platform_x, platform_y, platform_width, platform_height))
# Fenster aktualisieren
pygame.display.flip()
# Pygame beenden
pygame.quit()