diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-14 23:30:05 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-14 23:30:05 -0500 |
| commit | 65f5143d3e01e111afb960451e0741ddb37be240 (patch) | |
| tree | d59bc1e885aa31743fd87ebadab8e1728e2cd683 /dungeon/src/lib.rs | |
| parent | graphics: use 32bit color for atlas (diff) | |
| download | DungeonCrawl-65f5143d3e01e111afb960451e0741ddb37be240.tar.gz DungeonCrawl-65f5143d3e01e111afb960451e0741ddb37be240.tar.bz2 DungeonCrawl-65f5143d3e01e111afb960451e0741ddb37be240.zip | |
graphics: add text message rendering (and sans ig)
Diffstat (limited to 'dungeon/src/lib.rs')
| -rw-r--r-- | dungeon/src/lib.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/dungeon/src/lib.rs b/dungeon/src/lib.rs index a475f95..0c9e055 100644 --- a/dungeon/src/lib.rs +++ b/dungeon/src/lib.rs @@ -5,6 +5,7 @@ pub mod astar; pub mod bsp; pub mod entity; pub mod map; +pub mod msg; pub mod player_input; pub mod pos; @@ -16,10 +17,23 @@ use rand::{ use crate::{ entity::{Entity, Player}, map::Floor, + msg::Message, player_input::PlayerInput, pos::FPos, }; +/// Lets the caller know what has +/// changed in the game state this +/// tick +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum UpdateResult { + /// Default, entities have moved + EntityMovement, + /// Message on screen updated. + /// Contains if a char was added. + MessageUpdated(bool), +} + /// The `Dungeon` type represents the game state of the /// dungeon crawler. #[derive(Debug, Clone)] @@ -27,6 +41,7 @@ pub struct Dungeon { pub floor: Floor, pub player: Player, pub enemies: Vec<Entity>, + pub msg: Message, seed: u64, rng: SmallRng, } @@ -48,11 +63,13 @@ impl Dungeon { let player = Player::new(floor.player_start()); // TODO: Randomize enemy positions/types let enemies = vec![Entity::zombie(floor.random_walkable_pos(&mut rng))]; + let msg = Message::empty(); Self { floor, player, enemies, + msg, seed, rng, } @@ -91,9 +108,15 @@ impl Dungeon { &mut self.rng } - pub fn update(&mut self, player_input: PlayerInput, delta_time: f32) { - self.act_player(player_input, delta_time); - self.act_non_players(delta_time); + pub fn update(&mut self, player_input: PlayerInput, delta_time: f32) -> UpdateResult { + if self.msg.visible() { + let changed = self.msg.update(player_input); + UpdateResult::MessageUpdated(changed) + } else { + self.act_player(player_input, delta_time); + self.act_non_players(delta_time); + UpdateResult::EntityMovement + } } fn act_player(&mut self, player_input: PlayerInput, delta_time: f32) { |