summaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/lib.rs34
-rw-r--r--graphics/src/render.rs47
2 files changed, 67 insertions, 14 deletions
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 0fdcedb..02eb97f 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -34,6 +34,11 @@ pub enum Key {
Right,
// Interact
Return,
+ E,
+ F,
+ Q,
+ // Number
+ Number(u8),
// Debug keys
F3,
F4,
@@ -56,6 +61,20 @@ impl From<KeyboardKey> for Key {
K::KEY_RIGHT => Self::Right,
// Interact
K::KEY_ENTER => Self::Return,
+ K::KEY_E => Self::E,
+ K::KEY_F => Self::F,
+ K::KEY_Q => Self::Q,
+ // Number
+ K::KEY_ZERO | K::KEY_KP_0 => Self::Number(0),
+ K::KEY_ONE | K::KEY_KP_1 => Self::Number(1),
+ K::KEY_TWO | K::KEY_KP_2 => Self::Number(2),
+ K::KEY_THREE | K::KEY_KP_3 => Self::Number(3),
+ K::KEY_FOUR | K::KEY_KP_4 => Self::Number(4),
+ K::KEY_FIVE | K::KEY_KP_5 => Self::Number(5),
+ K::KEY_SIX | K::KEY_KP_6 => Self::Number(6),
+ K::KEY_SEVEN | K::KEY_KP_7 => Self::Number(7),
+ K::KEY_EIGHT | K::KEY_KP_8 => Self::Number(8),
+ K::KEY_NINE | K::KEY_KP_9 => Self::Number(9),
// Debug keys
K::KEY_F3 => Self::F3,
K::KEY_F4 => Self::F4,
@@ -79,6 +98,21 @@ impl From<Key> for KeyboardKey {
Key::Right => Self::KEY_RIGHT,
// Interact
Key::Return => Self::KEY_ENTER,
+ Key::E => Self::KEY_E,
+ Key::F => Self::KEY_F,
+ Key::Q => Self::KEY_Q,
+ // Number
+ Key::Number(0) => Self::KEY_ZERO,
+ Key::Number(1) => Self::KEY_ONE,
+ Key::Number(2) => Self::KEY_TWO,
+ Key::Number(3) => Self::KEY_THREE,
+ Key::Number(4) => Self::KEY_FOUR,
+ Key::Number(5) => Self::KEY_FIVE,
+ Key::Number(6) => Self::KEY_SIX,
+ Key::Number(7) => Self::KEY_SEVEN,
+ Key::Number(8) => Self::KEY_EIGHT,
+ Key::Number(9) => Self::KEY_NINE,
+ Key::Number(_) => Self::KEY_NULL,
// Debug keys
Key::F3 => Self::KEY_F3,
Key::F4 => Self::KEY_F4,
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;
};