|
|
|
|
@ -11,43 +11,22 @@ class World:
|
|
|
|
|
obstacle_count = random.randint(2, 3)
|
|
|
|
|
for _ in range(obstacle_count):
|
|
|
|
|
x = random.randint(500, 4000) # X-Position irgendwo in der Welt
|
|
|
|
|
self.obstacles.append(Obstacle(x, 520, settings.world.obstacle.box))
|
|
|
|
|
self.obstacles.append(Obstacle(x, 520, settings.obstacles.box))
|
|
|
|
|
|
|
|
|
|
# Welt Generierung
|
|
|
|
|
self.screen = screen
|
|
|
|
|
self.background = pygame.image.load(settings.BACKGROUND_IMG).convert()
|
|
|
|
|
self.bg_width = self.background.get_width()
|
|
|
|
|
|
|
|
|
|
# Boden
|
|
|
|
|
self.ground_rect = pygame.Rect(0, 650, 5000, 80) # Boden
|
|
|
|
|
full_image = pygame.image.load(settings.world.ground.img).convert_alpha()
|
|
|
|
|
# --- Ausschneiden des Bereichs
|
|
|
|
|
cropped = pygame.Surface((settings.world.ground.crop_scale_right, settings.world.ground.crop_height), pygame.SRCALPHA)
|
|
|
|
|
cropped.blit(full_image, (0, 0), (0, settings.world.ground.crop_top, settings.world.ground.crop_scale_right, settings.world.ground.crop_height))
|
|
|
|
|
# --- Skalieren für Anzeige
|
|
|
|
|
self.ground_image = pygame.transform.scale(cropped, (settings.world.ground.scale_width, settings.world.ground.scale_height))
|
|
|
|
|
self.tile_width = self.ground_image.get_width()
|
|
|
|
|
|
|
|
|
|
# Spieler
|
|
|
|
|
self.ground_rect = pygame.Rect(0, 740, 5000, 80) # Boden
|
|
|
|
|
self.player = Player(200, 500) # Spieler
|
|
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
|
self.screen.fill((0, 0, 0)) # Bildschirm löschen, bevor gezeichnet wird
|
|
|
|
|
camera_offset = self.player.rect.centerx - settings.SCREEN_WIDTH // 2
|
|
|
|
|
world_width = max(self.bg_width, max([obs.rect.right for obs in self.obstacles] + [self.ground_rect.right]))
|
|
|
|
|
camera_offset = max(0, min(camera_offset, world_width - settings.SCREEN_WIDTH))
|
|
|
|
|
camera_offset = max(0, min(camera_offset, self.bg_width - settings.SCREEN_WIDTH))
|
|
|
|
|
self.player.update(self.ground_rect.top, self.obstacles)
|
|
|
|
|
|
|
|
|
|
bg_offset = int(camera_offset * 0.5) # Parallax: langsamer bewegen
|
|
|
|
|
self.screen.blit(self.background, (-bg_offset, 0))
|
|
|
|
|
# Boden kacheln ohne Parallax
|
|
|
|
|
start_tile = (camera_offset // self.tile_width) * self.tile_width
|
|
|
|
|
end_x = camera_offset + settings.SCREEN_WIDTH
|
|
|
|
|
x = start_tile
|
|
|
|
|
while x < end_x:
|
|
|
|
|
screen_x = x - camera_offset
|
|
|
|
|
self.screen.blit(self.ground_image, (screen_x, self.ground_rect.top))
|
|
|
|
|
x += self.tile_width
|
|
|
|
|
self.screen.blit(self.background, (-camera_offset, 0))
|
|
|
|
|
# pygame.draw.rect(self.screen, (124, 252, 0), self.ground_rect)
|
|
|
|
|
|
|
|
|
|
for obs in self.obstacles:
|
|
|
|
|
obs.draw(self.screen, camera_offset)
|
|
|
|
|
|