Refactor code structure for improved readability and maintainability
This commit is contained in:
+2
-3
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user