Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-03-28 16:05:08 +01:00
parent 02202e4d3d
commit b60ffd87aa
108 changed files with 74710 additions and 15 deletions
+2 -3
View File
@@ -32,6 +32,8 @@ class Bomb(Unit):
def draw(self):
n = self.age // 40
n= 3 -n +1
if n == 0:
n = 1
if n < 0:
n = 0
image = self.game.bomb_assets[n]
@@ -123,9 +125,6 @@ class Explosion(Bomb):
self.die()
def draw(self):
if self.game.map.is_tunnel(*self.position):
return
image = self.game.assets["BMP_EXPLOSION"]
image_size = self.game.render_engine.get_image_size(image)
partial_x, partial_y = 0, 0
+3 -3
View File
@@ -44,7 +44,7 @@ class Rat(Unit):
nx, ny = x + dx, y + dy
if not self.game.map.in_bounds(nx, ny):
continue
if self.game.map.is_empty(nx, ny) and (nx, ny) != self.position_before:
if self.game.map.is_traversable(nx, ny) and (nx, ny) != self.position_before:
neighbors.append((nx, ny))
if not neighbors:
@@ -52,11 +52,11 @@ class Rat(Unit):
nx, ny = x + dx, y + dy
if not self.game.map.in_bounds(nx, ny):
continue
if self.game.map.is_empty(nx, ny):
if self.game.map.is_traversable(nx, ny):
neighbors.append((nx, ny))
if not neighbors:
print(f"[flow] rat fallback: no empty neighbors from position={self.position}", flush=True)
print(f"[flow] rat fallback: no traversable neighbors from position={self.position}", flush=True)
return self.position
self.position_before = self.position