summaryrefslogtreecommitdiff
path: root/graphics/src/render.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-19 23:10:38 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-19 23:11:05 -0500
commit9f2df31db6fe5450826cc68fd2158fe218dd8000 (patch)
tree07096790eb1ca63512700a130c2baae3b4d151b3 /graphics/src/render.rs
parentdungeon: implement items (diff)
downloadDungeonCrawl-9f2df31db6fe5450826cc68fd2158fe218dd8000.tar.gz
DungeonCrawl-9f2df31db6fe5450826cc68fd2158fe218dd8000.tar.bz2
DungeonCrawl-9f2df31db6fe5450826cc68fd2158fe218dd8000.zip
dungeon: inventory usage
Diffstat (limited to 'graphics/src/render.rs')
-rw-r--r--graphics/src/render.rs47
1 files changed, 33 insertions, 14 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 5841a7b..89f9dc3 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -331,6 +331,7 @@ impl Renderer {
ys,
TEXTURE_SIZE,
0.0,
+ Color::WHITE,
);
// draw top wall borders
@@ -344,6 +345,7 @@ impl Renderer {
ys,
TEXTURE_SIZE,
0.0,
+ Color::WHITE,
);
}
if !is_wall(Direction::East) {
@@ -354,6 +356,7 @@ impl Renderer {
ys,
TEXTURE_SIZE,
90.0,
+ Color::WHITE,
);
}
if !is_wall(Direction::South) {
@@ -364,6 +367,7 @@ impl Renderer {
ys,
TEXTURE_SIZE,
180.0,
+ Color::WHITE,
);
}
if !is_wall(Direction::West) {
@@ -374,6 +378,7 @@ impl Renderer {
ys,
TEXTURE_SIZE,
270.0,
+ Color::WHITE,
);
}
}
@@ -404,6 +409,7 @@ impl Renderer {
y * TEXTURE_SIZE,
TEXTURE_SIZE,
0.0,
+ Color::WHITE,
);
if idx == ATLAS_FLOOR {
// add possible extentions
@@ -424,6 +430,7 @@ impl Renderer {
y * TEXTURE_SIZE,
TEXTURE_SIZE,
0.0,
+ Color::WHITE,
);
}
}
@@ -478,10 +485,10 @@ impl Renderer {
where
R: RaylibDraw,
{
- self.draw_entity(r, &dungeon.player.entity);
- for enemy in &dungeon.enemies {
+ for enemy in &dungeon.entities {
self.draw_entity(r, enemy);
}
+ self.draw_entity(r, &dungeon.player.entity);
}
/// Draws an entity
@@ -519,6 +526,7 @@ impl Renderer {
dest_rec.y - WALL_HEIGHT as f32,
size,
0.0,
+ Color::WHITE,
);
if self.debug {
@@ -592,9 +600,15 @@ impl Renderer {
);
};
- // Draw enemy dots
- for enemy in &dungeon.enemies {
- draw_dot(enemy.pos, Color::RED);
+ // Draw entity dots
+ for entity in &dungeon.entities {
+ use EntityKind as K;
+ let color = match entity.kind {
+ K::Player => Color::LIME,
+ K::Zombie(_) => Color::RED,
+ K::Item(_) => Color::TURQUOISE,
+ };
+ draw_dot(entity.pos, color);
}
// Draw player dot
@@ -630,6 +644,11 @@ impl Renderer {
let slot_x = SLOTS_X + SLOT_LEN * idx;
// Draw slot container
+ let tint = if (idx as usize) == player.active_inv_slot {
+ Color::YELLOW
+ } else {
+ Color::WHITE
+ };
r.draw_atlas(
&self.textures.atlas,
ATLAS_INV_CONTAINER,
@@ -637,6 +656,7 @@ impl Renderer {
UI_PADDING,
SLOT_LEN,
0.0,
+ tint,
);
if let Some(item) = player.inventory.get(idx as usize) {
@@ -682,6 +702,7 @@ impl Renderer {
HEART_Y,
ICON_WIDTH,
0.0,
+ Color::WHITE,
);
draw_text!(self, r, TEXT_X, HEART_Y, "x{health:02}");
@@ -694,6 +715,7 @@ impl Renderer {
DAMAGE_Y,
ICON_WIDTH,
0.0,
+ Color::WHITE,
);
draw_text!(self, r, TEXT_X, DAMAGE_Y, "x{damage:02}");
}
@@ -830,6 +852,7 @@ impl Renderer {
y,
FONT_SIZE,
0.0,
+ Color::WHITE,
);
}
}
@@ -886,6 +909,8 @@ where
Self: RaylibDraw,
{
/// Draw an atlas texture index
+ #[inline]
+ #[expect(clippy::too_many_arguments)]
fn draw_atlas(
&mut self,
tex: &Texture2D,
@@ -894,6 +919,7 @@ where
y: impl Into<f32>,
size: impl Into<f32>,
rotation: impl Into<f32>,
+ tint: Color,
) {
let size_into = size.into();
let source_rec = rect! {
@@ -912,14 +938,7 @@ where
dest_rec.width / 2.0,
dest_rec.height / 2.0,
};
- self.draw_texture_pro(
- tex,
- source_rec,
- dest_rec,
- origin,
- rotation.into(),
- Color::WHITE,
- );
+ self.draw_texture_pro(tex, source_rec, dest_rec, origin, rotation.into(), tint);
}
/// Draw dungeon tiles helper function
@@ -961,7 +980,7 @@ where
}
fn draw_pathing_deug(&mut self, dungeon: &Dungeon) {
- for enemy in &dungeon.enemies {
+ for enemy in &dungeon.entities {
let Some(ai) = enemy.get_ai() else {
continue;
};