ENDE: 09.10.2026

This commit is contained in:
Benjamin 2026-10-09 18:32:12 +02:00
parent b2ae3d4ba7
commit f91d7a7fa1
3 changed files with 33 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

40
game.py
View file

@ -16,7 +16,7 @@ LIGHT_RADIUS = 150
class Item:
def __init__(self, x: float, y: float, width: float, height: float, color, flashlight, game):
def __init__(self, x: float, y: float, width: float, height: float, color, flashlight, game, image: pygame.Surface = None):
self.x: float = x
self.y: float = y
self.vector = pygame.Vector2(self.x, self.y)
@ -26,19 +26,28 @@ class Item:
self.visible: bool = False
self.flashlight = flashlight
self.game = game
self.mask = pygame.mask.Mask(self.rect.size, fill=True)
self.image = image
@property
def rect(self) -> pygame.Rect:
if not self.image:
return pygame.Rect(self.x, self.y, self.width, self.height)
else:
return pygame.Rect(self.x, self.y, self.image.get_width(), self.image.get_height())
def update(self):
self.visible = False
self.visible = self.flashlight.light_mask.overlap(self.game.test_item_mask, self.rect.topleft) is not None
self.visible = self.flashlight.light_mask.overlap(self.mask, self.rect.topleft) is not None
def render(self, surface):
def render(self, surface: pygame.Surface):
if self.visible and self.flashlight.light_state:
if not self.image:
pygame.draw.rect(surface, self.color, self.rect)
else:
surface.blit(self.image, (self.x, self.y, self.image.get_width(), self.image.get_height()))
class Game:
@ -63,9 +72,19 @@ class Game:
# Flashlight
self.flashlight_player = Flashlight(self, self.player)
# Assets
self.assets = {
"floor_01": load_image("level/ground/floor_1.png"),
"plant_01": load_image("items/furniture/plant.png"),
}
# Items
self.test_item = Item(140, 300, 20, 20, "blue", self.flashlight_player, self)
self.test_item_mask = pygame.mask.Mask(self.test_item.rect.size, fill=True)
self.items = [
Item(140, 300, 20, 20, "blue", self.flashlight_player, self, self.assets["plant_01"]),
Item(140, 340, 20, 20, "red", self.flashlight_player, self),
]
# Level
self.walls: list[Rect] = [
pygame.Rect(100 * 2, 100 * 2, 20 * 2, 50 * 2),
@ -73,8 +92,7 @@ class Game:
pygame.Rect(550 * 2, 80 * 2, 20 * 2, 200 * 2),
]
# Assets
self.assets = {"floor_01": load_image("level/ground/floor_1.png")}
def update(self) -> None:
# Ereignisse
@ -96,7 +114,9 @@ class Game:
# Spielzustände aktualisieren
self.player.update(walls=self.walls, dt=self.dt)
self.flashlight_player.update()
self.test_item.update()
for item in self.items:
item.update()
def render(self) -> None:
# Hintergrund
@ -120,7 +140,9 @@ class Game:
# Licht
self.flashlight_player.render(self.screen)
self.test_item.render(self.screen)
for item in self.items:
item.render(self.screen)
# Wände
for wall in self.walls: