Level-Management und Sprung-Logik aktualisiert; Kollisionserkennung für Wandrutschen verbessert

This commit is contained in:
Benjamin 2026-06-19 16:50:33 +02:00
parent 3fe918c082
commit 825cc81d9e
2 changed files with 30 additions and 21 deletions

37
game.py
View file

@ -76,7 +76,19 @@ class Game:
self.tilemap: Tilemap = Tilemap(game=self, tile_size=16)
self.load_level("map")
self.level: int | str = 0
self.load_level(self.level)
self.clouds: Clouds = Clouds(cloud_images=self.assets["clouds"], count=16)
self.isJumping: bool = False
# self.boost: bool = False
def load_level(self, map_id: str | int):
try:
self.tilemap.load(path="data/maps/" + str(map_id) + ".json")
except FileNotFoundError:
pass
self.leaf_spawners: list[pygame.Rect] = []
self.enemies: list[Enemy] = []
@ -95,21 +107,16 @@ class Game:
self.particles: list[Particle] = []
self.projectiles: list = []
self.sparks: list[Spark] = []
self.clouds: Clouds = Clouds(cloud_images=self.assets["clouds"], count=16)
self.isJumping: bool = False
self.dead: int = 0
self.scroll: list[float] = [0, 0]
# self.boost: bool = False
def load_level(self, map_id: str | int):
try:
self.tilemap.load(path="data/maps/" + str(map_id) + ".json")
except FileNotFoundError:
pass
def run(self) -> None:
while self.running:
self.display.blit(self.assets["background"], (0, 0))
if self.dead:
self.dead += 1
if self.dead > 40:
self.load_level(self.level)
self.scroll[0] += (
self.player.rect().centerx
@ -147,10 +154,11 @@ class Game:
enemy.render(self.display, offset=render_scroll)
if kill:
self.enemies.remove(enemy)
if not self.dead:
self.player.update(
self.tilemap, movement=((self.movement[1] - self.movement[0]), 0)
self.tilemap, (self.movement[1] - self.movement[0], 0)
)
self.player.render(surface=self.display, offset=render_scroll)
self.player.render(self.display, offset=render_scroll)
# [[x, y], direction, timer]
for projectile in self.projectiles.copy():
@ -181,7 +189,8 @@ class Game:
elif abs(self.player.dashing) < 50:
if self.player.rect().collidepoint(projectile[0]):
self.projectiles.remove(projectile)
for i in range(30):
self.dead += 1
for _ in range(30):
angle = random.random() * math.pi * 2
speed = random.random() * 5
self.sparks.append(

View file

@ -219,14 +219,14 @@ class Player(PhysicsEntity):
# Wenn wir länger als 4 Frames in der Luft sind -> Springen!
self.wall_slide = False
if self.collisions.left or self.collisions.right and self.air_time > 4:
if (self.collisions.right or self.collisions.left) and self.air_time > 4:
self.wall_slide = True
self.velocity[1] = min(self.velocity[1], 0.5)
if self.collisions.left:
self.flip = True
else:
if self.collisions.right:
self.flip = False
else:
self.flip = True
self.set_action("wall_slide")