summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-15 11:48:27 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-15 11:48:27 -0500
commitab20683e387d5ef09d52d1647492e819bf93380b (patch)
tree420c0eb27f7c56167291d3e57a61f790d21d4d01
parentdungeon: randomize floor brick accents (diff)
downloadDungeonCrawl-ab20683e387d5ef09d52d1647492e819bf93380b.tar.gz
DungeonCrawl-ab20683e387d5ef09d52d1647492e819bf93380b.tar.bz2
DungeonCrawl-ab20683e387d5ef09d52d1647492e819bf93380b.zip
graphics: add astar paths to debug rendering
-rw-r--r--dungeon/src/entity.rs17
-rw-r--r--dungeon/src/msg.rs1
-rw-r--r--graphics/src/render.rs25
3 files changed, 43 insertions, 0 deletions
diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs
index 6ed46cc..7c16418 100644
--- a/dungeon/src/entity.rs
+++ b/dungeon/src/entity.rs
@@ -125,6 +125,15 @@ impl EnemyMoveState {
}
}
}
+
+ /// Returns an optional reference to the current path this entity is moving
+ pub const fn moves(&self) -> Option<&[Pos]> {
+ match self {
+ Self::Idle(_) => None,
+ Self::Roam(moves) => Some(moves.as_slice()),
+ Self::Attack(moves, _) => Some(moves.as_slice()),
+ }
+ }
}
impl Default for EnemyMoveState {
fn default() -> Self {
@@ -229,6 +238,14 @@ impl Entity {
self.fpos = FPos::from_pos(pos);
self.moving_to = None;
}
+
+ /// Returns a reference to this entities current AI
+ pub const fn get_ai(&self) -> Option<&EnemyMoveState> {
+ match &self.kind {
+ EntityKind::Zombie(ai) => Some(ai),
+ _ => None,
+ }
+ }
}
/// The `Player` type represents the main player entity
diff --git a/dungeon/src/msg.rs b/dungeon/src/msg.rs
index 68a6cbd..032a201 100644
--- a/dungeon/src/msg.rs
+++ b/dungeon/src/msg.rs
@@ -48,6 +48,7 @@ impl Message {
if self.waiting && !input.interact {
return false;
}
+ self.waiting = false;
if self.last.elapsed() < DURATION_PER {
return false;
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index cc9847e..8202e49 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -278,6 +278,9 @@ impl Renderer {
let camera = dungeon.render_camera();
let mut rc = r.begin_mode2D(camera);
self.draw_bg_tilemap(&mut rc);
+ if self.debug {
+ rc.draw_pathing_deug(dungeon);
+ }
self.draw_entities(&mut rc, dungeon);
self.draw_fg_tilemap(&mut rc);
}
@@ -952,5 +955,27 @@ where
) {
self.draw_rectangle(x.into(), y.into(), width.into(), height.into(), color);
}
+
+ fn draw_pathing_deug(&mut self, dungeon: &Dungeon) {
+ for enemy in &dungeon.enemies {
+ let Some(ai) = enemy.get_ai() else {
+ continue;
+ };
+ let Some(moves) = ai.moves() else {
+ continue;
+ };
+ for pos in moves {
+ let (x, y) = pos.xy();
+ let color = Color::RED.alpha(0.5);
+ self.draw_rectangle_ext(
+ x * TILE_SIZE,
+ y * TILE_SIZE,
+ TILE_SIZE,
+ TILE_SIZE,
+ color,
+ );
+ }
+ }
+ }
}
impl<T> RaylibDrawExt for T where T: RaylibDraw {}