import pgzrun import random from pygame import Rect WIDTH = 800 HEIGHT = 600 player_x = 400 player_y = 550 player_width = 80 player_height = 20 player_speed = 5 rocks = [] bonusstones = [] score = 0 game_over = False bonus_hits = 0 positive_hits = 0 negative_hits = 0 # Start met een paar normale stenen for _ in range(3): rocks.append({ "x": random.randint(0, WIDTH - 40), "y": 0, "size": 40, "speed": random.uniform(2, 4) }) # Start met een paar bonusstenen for _ in range(2): bonusstones.append({ "x": random.randint(0, WIDTH - 40), "y": -random.randint(100, 300), "size": 40, "speed": random.uniform(1.5, 3), "value": random.randint(-5, 5) }) def draw(): screen.clear() if game_over: screen.draw.text("GAME OVER", center=(WIDTH // 2, HEIGHT // 2 - 60), fontsize=60, color="red") screen.draw.text(f"Score: {score}", center=(WIDTH // 2, HEIGHT // 2), fontsize=40, color="white") screen.draw.text(f"Bonusstenen geraakt: {bonus_hits}", center=(WIDTH // 2, HEIGHT // 2 + 40), fontsize=30, color="lightblue") screen.draw.text(f"Positief: {positive_hits} | Negatief: {negative_hits}", center=(WIDTH // 2, HEIGHT // 2 + 80), fontsize=30, color="yellow") return screen.draw.filled_rect(Rect((player_x, player_y), (player_width, player_height)), "blue") screen.draw.text(f"Score: {score}", topleft=(10, 10), fontsize=30, color="white") for rock in rocks: screen.draw.filled_rect(Rect((rock["x"], rock["y"]), (rock["size"], rock["size"])), "gray") for bonus in bonusstones: rect = Rect((bonus["x"], bonus["y"]), (bonus["size"], bonus["size"])) color = "green" if bonus["value"] >= 0 else "orange" screen.draw.filled_rect(rect, color) screen.draw.text(str(bonus["value"]), center=rect.center, fontsize=24, color="black") def update(): global player_x, game_over, score, bonus_hits, positive_hits, negative_hits if game_over: return if keyboard.left: player_x -= player_speed if keyboard.right: player_x += player_speed player_x = max(0, min(WIDTH - player_width, player_x)) speler_rect = Rect(player_x, player_y, player_width, player_height) for rock in rocks: rock["y"] += rock["speed"] if rock["y"] > HEIGHT: rock["y"] = 0 rock["x"] = random.randint(0, WIDTH - rock["size"]) rock["speed"] = random.uniform(2, 5) rock_rect = Rect(rock["x"], rock["y"], rock["size"], rock["size"]) if speler_rect.colliderect(rock_rect): game_over = True for bonus in bonusstones: bonus["y"] += bonus["speed"] if bonus["y"] > HEIGHT: bonus["y"] = 0 bonus["x"] = random.randint(0, WIDTH - bonus["size"]) bonus["speed"] = random.uniform(1.5, 3) bonus["value"] = random.randint(-5, 5) bonus_rect = Rect(bonus["x"], bonus["y"], bonus["size"], bonus["size"]) if speler_rect.colliderect(bonus_rect): score += bonus["value"] if bonus["value"] > 0: positive_hits += 1 else: negative_hits += 1 bonus_hits += 1 bonus["y"] = 0 bonus["x"] = random.randint(0, WIDTH - bonus["size"]) bonus["value"] = random.randint(-5, 5) pgzrun.go()