Old House
import pygame
import sys
# Initialisierung von Pygame
pygame.init()
# Fenstergröße und Titel
WIDTH, HEIGHT = 640, 480
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Der Fluch des verlassenen Hauses")
# Farben
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
# Spieler-Parameter
player_size = 50
player_x = WIDTH // 2
player_y = HEIGHT // 2
player_speed = 5
# Schlüssel-Parameter
key_x, key_y = 100, 100
key_collected = False
# Schriftart
font = pygame.font.SysFont(None, 36)
# Spielzustand
game_over = False
# Spielschleife
clock = pygame.time.Clock()
while True:
# Ereignisüberprüfung
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Spielerbewegung
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
player_x -= player_speed
if keys[pygame.K_RIGHT]:
player_x += player_speed
if keys[pygame.K_UP]:
player_y -= player_speed
if keys[pygame.K_DOWN]:
player_y += player_speed
# Spiellogik
if not key_collected:
if abs(player_x - key_x) < player_size and abs(player_y - key_y) < player_size:
key_collected = True
# Bildschirm aktualisieren
screen.fill(BLACK)
if key_collected:
text = font.render("Schlüssel gefunden! Gehe zur Tür!", True, WHITE)
screen.blit(text, (20, 20))
else:
pygame.draw.rect(screen, RED, (key_x, key_y, player_size, player_size))
pygame.draw.rect(screen, WHITE, (player_x, player_y, player_size, player_size))
# Spielende
if game_over:
text = font.render("Game Over", True, RED)
screen.blit(text, (WIDTH // 2 - 100, HEIGHT // 2))
pygame.display.flip()
clock.tick(30)
Leave a comment
Log in with itch.io to leave a comment.