Refactor code structure for improved readability and maintainability
This commit is contained in:
+29
-8
@@ -2,6 +2,7 @@ import os
|
||||
import random
|
||||
|
||||
from engine import maze
|
||||
from engine.collision_system import CollisionLayer
|
||||
from runtime_paths import bundle_path
|
||||
|
||||
class Graphics():
|
||||
@@ -88,6 +89,14 @@ class Graphics():
|
||||
)
|
||||
for direction in ["UP", "DOWN", "LEFT", "RIGHT"]
|
||||
},
|
||||
"explosions": {
|
||||
direction: self.render_engine.load_image(
|
||||
f"Rat/BMP_{theme_index}_EXPLOSION_{direction}.png",
|
||||
transparent_color=((125, 125, 125), (128, 128, 128)),
|
||||
surface=False,
|
||||
)
|
||||
for direction in ["UP", "DOWN", "LEFT", "RIGHT"]
|
||||
},
|
||||
"edges": {
|
||||
direction: self.render_engine.load_image(f"Rat/BMP_{theme_index}_{direction}.png", surface=True)
|
||||
for direction in ["N", "S", "E", "W"]
|
||||
@@ -112,6 +121,7 @@ class Graphics():
|
||||
self.grasses = theme_assets["grasses"]
|
||||
self.flowers = theme_assets["flowers"]
|
||||
self.caves = theme_assets["caves"]
|
||||
self.explosions = theme_assets["explosions"]
|
||||
self.edges = theme_assets["edges"]
|
||||
self.corners = theme_assets["corners"]
|
||||
self.inner_corners = theme_assets["inner_corners"]
|
||||
@@ -133,7 +143,18 @@ class Graphics():
|
||||
self.draw_blood_layer()
|
||||
|
||||
def draw_cave_foreground(self):
|
||||
for surface, x, y in self.cave_foreground_tiles:
|
||||
active_cave_explosions = {}
|
||||
for unit in self.units.values():
|
||||
if unit.collision_layer != CollisionLayer.EXPLOSION:
|
||||
continue
|
||||
if not self.map.is_tunnel(*unit.position):
|
||||
continue
|
||||
active_cave_explosions[unit.position] = getattr(unit, "cave_direction", None)
|
||||
|
||||
for cell_x, cell_y, direction, surface, x, y in self.cave_foreground_tiles:
|
||||
if (cell_x, cell_y) in active_cave_explosions:
|
||||
explosion_direction = active_cave_explosions[(cell_x, cell_y)] or direction
|
||||
surface = self.explosions.get(explosion_direction, surface)
|
||||
self.render_engine.draw_image(x, y, surface, anchor="nw", tag="cave")
|
||||
|
||||
def draw_blood_layer(self):
|
||||
@@ -150,8 +171,8 @@ class Graphics():
|
||||
def draw(surface, x, y):
|
||||
texture_tiles.append((surface, x, y))
|
||||
|
||||
def draw_cave(surface, x, y):
|
||||
self.cave_foreground_tiles.append((surface, x, y))
|
||||
def draw_cave(surface, x, y, direction):
|
||||
self.cave_foreground_tiles.append((x // self.cell_size, y // self.cell_size, direction, surface, x, y))
|
||||
|
||||
def occupied(x, y):
|
||||
return self.map.in_bounds(x, y) and self.map.get_cell(x, y) != maze.MAP_EMPTY
|
||||
@@ -259,21 +280,21 @@ class Graphics():
|
||||
else:
|
||||
draw(random_flower(), px + half_cell, py + half_cell)
|
||||
else:
|
||||
draw_cave(self.caves["RIGHT"], px, py)
|
||||
draw_cave(self.caves["RIGHT"], px, py, "RIGHT")
|
||||
else:
|
||||
draw(self.grasses[0], px + half_cell, py + half_cell)
|
||||
draw_cave(self.caves["LEFT"], px, py)
|
||||
draw_cave(self.caves["LEFT"], px, py, "LEFT")
|
||||
else:
|
||||
draw_cave(self.caves["DOWN"], px, py)
|
||||
draw_cave(self.caves["DOWN"], px, py, "DOWN")
|
||||
else:
|
||||
draw(self.grasses[0], px + half_cell, py + half_cell)
|
||||
draw_cave(self.caves["UP"], px, py)
|
||||
draw_cave(self.caves["UP"], px, py, "UP")
|
||||
|
||||
# Blood stains now handled separately as overlay layer
|
||||
self.background_texture = self.render_engine.create_texture(texture_tiles, fill_color=(128, 128, 128))
|
||||
|
||||
def add_blood_stain(self, position):
|
||||
"""Add a blood stain as sprite overlay (optimized - no background regeneration)"""
|
||||
"""Add a blood stain as sprite overlay (opti mized - no background regeneration)"""
|
||||
# Pick random blood texture from pre-generated pool
|
||||
if not self.blood_stain_textures:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user