From ac71ff12c7f43a7cf3b8583a4f7fa0d4f1ba684c Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 2 Oct 2026 18:28:01 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge=20Asset-Ladefunktion=20hinzu=20und=20?= =?UTF-8?q?zeichne=20den=20Boden=20mit=20Game=20Assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.py | 30 ++++++++++++++++++++++++++++-- plan.txt | 20 ++++++++++++++++++++ scripts/utils.py | 13 +++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 plan.txt create mode 100644 scripts/utils.py diff --git a/game.py b/game.py index 1846389..4c130d2 100644 --- a/game.py +++ b/game.py @@ -3,8 +3,13 @@ from pygame.math import Vector2 from pygame.rect import Rect from pygame.typing import SequenceLike -SCREEN_WIDTH = 1280 -SCREEN_HEIGHT = 720 +from scripts.utils import load_image + +TILE_SIZE = 64 +COLS = 20 +ROWS = 12 +SCREEN_WIDTH = TILE_SIZE*COLS +SCREEN_HEIGHT = TILE_SIZE*ROWS SCREEN_CENTER = (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) PLAYER_SIZE = 40 LIGHT_RADIUS = 150 @@ -19,6 +24,7 @@ class Item: self.height: float = height self.color: SequenceLike[int] | str | int = color + @property def rect(self)-> pygame.Rect: return pygame.Rect(self.x, self.y, self.width, self.height) @@ -49,6 +55,10 @@ class Game: self.light_points: list[pygame.Vector2] self.light_surface: pygame.Surface = pygame.Surface((SCREEN_WIDTH,SCREEN_HEIGHT), pygame.SRCALPHA) + # Assets + self.assets = { + "floor_01": load_image("level/ground/floor_1.png") + } def create_light_points(self)-> list[pygame.Vector2]: points: list[pygame.Vector2] = [] @@ -91,6 +101,22 @@ class Game: # Hintergrund self.screen.fill((0, 0, 0, 0)) + + for y in range(ROWS): + for x in range(COLS): + self.screen.blit(self.assets["floor_01"], pygame.Rect(x*64, y*64, TILE_SIZE, TILE_SIZE)) + + + # 1. Zeichne 1 Tile -> [] + + # 2. Zeichne eine Reihe von Tiles -> [][][][][][] + + # 3. Zeichne mehrere Reihen von Tiles + # -> [][][][][][] + # -> [][][][][][] + # -> [][][][][][] + + # Licht self.light_surface.fill((0, 0, 0, 0)) pygame.draw.polygon(self.light_surface, (243, 255, 74, 255), self.create_light_points()) diff --git a/plan.txt b/plan.txt new file mode 100644 index 0000000..91a5b55 --- /dev/null +++ b/plan.txt @@ -0,0 +1,20 @@ +# Ziel: + +Der Boden wird richtig sichtbar, wenn die Taschenlampe rüber leuchtet, die ein bisschen durchsichtig ist. + +USER + | + | + v + + - Maske Licht + - Schwarz + - Boden + +# Plan: + +1. Boden zeichnen mit Game Asset. + -> ein asset Dictonary erstellen + -> Dort die Bild Datei einfügen. + -> Bild laden mit einer Hilfsfunktion. + -> Bild zeichnen und duplizieren diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 0000000..72aaa19 --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,13 @@ +from pathlib import Path + +import pygame + +# Einheitlichkeit: Wenn image_path ein Path-Objekt ist, sollte auch load_image ein Path-Objekt laden. + +images_path = Path("./data/textures/") + + +def load_image(path: str) -> pygame.Surface: + # print(self.images_path) + # print(self.images_path / path) + return pygame.image.load(images_path / path) \ No newline at end of file