diff options
Diffstat (limited to 'game/src/lib.rs')
| -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); } |