diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-19 23:10:38 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-19 23:11:05 -0500 |
| commit | 9f2df31db6fe5450826cc68fd2158fe218dd8000 (patch) | |
| tree | 07096790eb1ca63512700a130c2baae3b4d151b3 /game | |
| parent | dungeon: implement items (diff) | |
| download | DungeonCrawl-9f2df31db6fe5450826cc68fd2158fe218dd8000.tar.gz DungeonCrawl-9f2df31db6fe5450826cc68fd2158fe218dd8000.tar.bz2 DungeonCrawl-9f2df31db6fe5450826cc68fd2158fe218dd8000.zip | |
dungeon: inventory usage
Diffstat (limited to 'game')
| -rw-r--r-- | game/src/lib.rs | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/game/src/lib.rs b/game/src/lib.rs index 77942b4..f123326 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -1,4 +1,7 @@ -use dungeon::{Dungeon, UpdateResult, player_input::PlayerInput, pos::Direction}; +use dungeon::{ + Dungeon, UpdateResult, entity::PLAYER_INVENTORY_SIZE, player_input::PlayerInput, + pos::Direction, +}; use graphics::{Key, Window}; pub struct Game { @@ -57,6 +60,26 @@ impl Game { None } + fn get_player_input(&mut self) -> PlayerInput { + let direction = self.player_dir(); + let interact = self.window.is_key_pressed(Key::Return); + let use_item = self.window.is_key_pressed(Key::E); + let attack = self.window.is_key_pressed(Key::F); + let drop = self.window.is_key_pressed(Key::Q); + let inv_slot = (0..PLAYER_INVENTORY_SIZE) + .filter_map(|u16| u8::try_from(u16).ok()) + .find(|u8| self.window.is_key_pressed(Key::Number(*u8 + 1))) + .map(|u8| u8 as usize); + PlayerInput { + direction, + interact, + use_item, + attack, + drop, + inv_slot, + } + } + pub fn run(&mut self) { // Main game loop while self.window.is_open() { @@ -70,12 +93,8 @@ impl Game { .set_message("Lorem ipsum dolor sit amet consectetur adipiscing elit"); } - let inputs = PlayerInput { - direction: self.player_dir(), - interact: self.window.is_key_pressed(Key::Return), - }; - // Update game state + let inputs = self.get_player_input(); let result = self .dungeon .update(inputs, self.window.delta_time().as_secs_f32()); @@ -91,11 +110,6 @@ impl Game { } } - // Update on screen message - if self.dungeon.msg.update(inputs) { - self.window.audio().speak.play(); - } - // Draw a single frame self.window.draw_frame(&self.dungeon); } |