Füge Asset-Ladefunktion hinzu und zeichne den Boden mit Game Assets
This commit is contained in:
parent
1de1af1e70
commit
ac71ff12c7
3 changed files with 61 additions and 2 deletions
30
game.py
30
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())
|
||||
|
|
|
|||
20
plan.txt
Normal file
20
plan.txt
Normal file
|
|
@ -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
|
||||
13
scripts/utils.py
Normal file
13
scripts/utils.py
Normal file
|
|
@ -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)
|
||||
Loading…
Reference in a new issue