Ladelevel-Methode hinzugefügt, um Karten dynamisch zu laden

This commit is contained in:
Benjamin 2026-06-12 17:48:59 +02:00
parent aa8f10a08a
commit ea2bc80c27

11
game.py
View file

@ -74,10 +74,7 @@ class Game:
self.tilemap: Tilemap = Tilemap(game=self, tile_size=16) self.tilemap: Tilemap = Tilemap(game=self, tile_size=16)
try: self.load_level(0)
self.tilemap.load(path="map.json")
except FileNotFoundError:
pass
self.leaf_spawners: list[pygame.Rect] = [] self.leaf_spawners: list[pygame.Rect] = []
self.enemys: list[Enemy] = [] self.enemys: list[Enemy] = []
@ -101,6 +98,12 @@ class Game:
self.scroll: list[float] = [0, 0] self.scroll: list[float] = [0, 0]
# self.boost: bool = False # self.boost: bool = False
def load_level(self, map_id: int):
try:
self.tilemap.load(path="data/maps/" + str(map_id) + ".json")
except FileNotFoundError:
pass
def run(self) -> None: def run(self) -> None:
while self.running: while self.running:
self.display.blit(self.assets["background"], (0, 0)) self.display.blit(self.assets["background"], (0, 0))