import pygame import random import sys # Init pygame.init() WIDTH, HEIGHT = 600, 800 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Brute Boeren Bergrace") clock = pygame.time.Clock() font = pygame.font.SysFont(None, 36) # Kleuren SKY = (135, 206, 235) ROAD = (160, 120, 80) WHITE = (255, 255, 255) # Speler (bakbrommer) player_x = WIDTH // 2 player_y = HEIGHT - 150 player_w, player_h = 80, 100 speed = 7 # Obstakels: hooibalen en tractors obstacles = [] score = 0 def new_obstacle(): x = random.randint(50, WIDTH - 100) y = -80 kind = random.choice(["hooi", "tractor"]) return {"x": x, "y": y, "kind": kind} # Hoofdloop running = True spawn_timer = 0 while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and player_x > 20: player_x -= speed if keys[pygame.K_RIGHT] and player_x < WIDTH - player_w - 20: player_x += speed # Spawn obstakels spawn_timer += 1 if spawn_timer > 30: obstacles.append(new_obstacle()) spawn_timer = 0 # Beweeg obstakels for ob in obstacles: ob["y"] += 5 + score // 10 # Botsing check player_rect = pygame.Rect(player_x, player_y, player_w, player_h) for ob in obstacles[:]: ob_rect = pygame.Rect(ob["x"], ob["y"], 60, 60) if player_rect.colliderect(ob_rect): print(f"Game Over! Score: {score}") pygame.quit() sys.exit() if ob["y"] > HEIGHT: obstacles.remove(ob) score += 1 # Teken screen.fill(SKY) # Weg pygame.draw.rect(screen, ROAD, (50, 0, WIDTH-100, HEIGHT)) # Strepen for y in range(0, HEIGHT, 80): pygame.draw.rect(screen, WHITE, (WIDTH//2-5, y, 10, 40)) # Speler tekenen als blauwe bakbrommer (simpel) pygame.draw.rect(screen, (0, 150, 255), (player_x, player_y, player_w, player_h)) pygame.draw.circle(screen, (0,0,0), (player_x+15, player_y+player_h), 15) pygame.draw.circle(screen, (0,0,0), (player_x+player_w-15, player_y+player_h), 15) # Obstakels tekenen for ob in obstacles: color = (255, 215, 0) if ob["kind"] == "hooi" else (200, 0, 0) pygame.draw.rect(screen, color, (ob["x"], ob["y"], 60, 60)) # Score text = font.render(f"Score: {score}", True, (0,0,0)) screen.blit(text, (10, 10)) pygame.display.flip() clock.tick(60) pygame.quit()