Refactor engine and rendering system: move SDL2 logic to render.py, update entity/game structure, clean up unused files, and fix event handling. Major codebase reorganization for maintainability.
This commit is contained in:
+16
-16
@@ -28,10 +28,10 @@ class Marine(Entity):
|
||||
self.selected = True
|
||||
# Play a random voice response when selected
|
||||
sound_file = f"marine/tmawht0{random.randint(0, 3)}.wav"
|
||||
if not self.engine.cmd_sound_effects:
|
||||
if not self.game.cmd_sound_effects:
|
||||
self.graphics.play_sound(sound_file)
|
||||
self.engine.cmd_sound_effects = True
|
||||
|
||||
self.game.cmd_sound_effects = True
|
||||
|
||||
def move(self):
|
||||
# Aquisisci la posizione dell'unità
|
||||
self.iso_x, self.iso_y = self.graphics.iso_transform(self.x, self.y)
|
||||
@@ -98,23 +98,23 @@ class Marine(Entity):
|
||||
|
||||
# Verifica che le coordinate siano valide
|
||||
if not (0 <= y < map_height and 0 <= x < map_width):
|
||||
if not self.engine.cmd_sound_effects:
|
||||
self.engine.graphics.play_sound("sounds/perror.wav")
|
||||
self.engine.cmd_sound_effects = True
|
||||
if not self.game.cmd_sound_effects:
|
||||
self.graphics.play_sound("sounds/perror.wav")
|
||||
self.game.cmd_sound_effects = True
|
||||
return
|
||||
|
||||
# Ora puoi controllare il contenuto della cella in sicurezza
|
||||
if self.engine.map[y][x]["wall"]:
|
||||
if not self.engine.cmd_sound_effects:
|
||||
self.engine.graphics.play_sound("sounds/perror.wav")
|
||||
self.engine.cmd_sound_effects = True
|
||||
if not self.game.cmd_sound_effects:
|
||||
self.graphics.play_sound("sounds/perror.wav")
|
||||
self.game.cmd_sound_effects = True
|
||||
return
|
||||
|
||||
self.target_cell = target_cell
|
||||
if not self.engine.cmd_sound_effects:
|
||||
if not self.game.cmd_sound_effects:
|
||||
self.graphics.play_sound(f"marine/tmayes0{random.randint(0, 3)}.wav")
|
||||
self.engine.cmd_sound_effects = True
|
||||
|
||||
self.game.cmd_sound_effects = True
|
||||
|
||||
def cast_rays_to_distance(self, distance):
|
||||
# Cast rays to check for visibility
|
||||
done_cells = {}
|
||||
@@ -126,12 +126,12 @@ class Marine(Entity):
|
||||
v_x, v_y = self.graphics.inv_iso_transform(ray_x, ray_y)
|
||||
if v_x>= 0 and v_x < len(self.engine.map[0]) and v_y >= 0 and v_y < len(self.engine.map):
|
||||
if (v_x, v_y) not in done_cells.keys():
|
||||
done_cells.update({(v_x, v_y): self.engine.map_shadow[v_y][v_x]})
|
||||
done_cells.update({(v_x, v_y): self.game.map_shadow[v_y][v_x]})
|
||||
self.engine.map[v_y][v_x]["visited"] = True
|
||||
self.engine.map_shadow[v_y][v_x] = 0
|
||||
self.game.map_shadow[v_y][v_x] = 0
|
||||
if i == 1:
|
||||
|
||||
self.engine.map_shadow[v_y][v_x] = max(done_cells.get((v_x, v_y), 0)-0.5, 0)
|
||||
|
||||
self.game.map_shadow[v_y][v_x] = max(done_cells.get((v_x, v_y), 0)-0.5, 0)
|
||||
print(done_cells.get((v_x, v_y), 0))
|
||||
#self.graphics.draw_line((self.centered_position[0], self.centered_position[1], ray_x, ray_y), color=(0, 255, 0, 255))
|
||||
continue
|
||||
|
||||
+7
-6
@@ -1,8 +1,8 @@
|
||||
class Entity:
|
||||
def __init__(self, asset, x, y, action, direction, speed, engine):
|
||||
def __init__(self, asset, x, y, action, direction, speed, game):
|
||||
self.asset = asset
|
||||
|
||||
self.graphics = engine.graphics
|
||||
self.graphics = game.engine.graphics
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.next_cell = (x, y)
|
||||
@@ -12,13 +12,14 @@ class Entity:
|
||||
self.direction = direction
|
||||
self.speed = speed
|
||||
self.frame = 0
|
||||
self.engine = engine
|
||||
self.game = game
|
||||
self.engine = game.engine
|
||||
self.selected = True
|
||||
self.movement = 0
|
||||
|
||||
def update(self):
|
||||
occlusion = self.graphics.get_distance((self.x, self.y), self.engine.cursor_pos) / 4
|
||||
|
||||
occlusion = self.graphics.get_distance((self.x, self.y), self.game.cursor_pos) / 4
|
||||
|
||||
# Set color based on selection status
|
||||
color = (0, 255, 0, 255)
|
||||
if self.selected:
|
||||
@@ -27,7 +28,7 @@ class Entity:
|
||||
# Draw target indicator if target is set
|
||||
|
||||
|
||||
occlusion = self.graphics.engine.map_shadow[self.y][self.x]
|
||||
occlusion = self.game.map_shadow[self.y][self.x]
|
||||
if occlusion >= 0.8:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user