diff --git a/src/game_state.rs b/src/game_state.rs index ce9577d90abf6dd3566b4d43bad03a193521565c..8306272316b0a0dd65992fd76b314a3d37448ced 100644 --- a/src/game_state.rs +++ b/src/game_state.rs @@ -92,19 +92,20 @@ impl GameState { fn handle_user_turn(&mut self, ctx: &mut Context) -> bool { let key = GameState::get_pressed_key(ctx); + let is_player_alive = self.current_run.player.current_hp > 0; + return match key { Key::CapsLock => false, - Key::N => self.create_new_run(), - Key::W | Key::A | Key::S | Key::D | Key::Down | Key::Up | Key::Right | Key::Left => GameState::handle_user_movement(self, key), - Key::Space => true, + Key::N => !is_player_alive && self.create_new_run(), + Key::W | Key::A | Key::S | Key::D | Key::Down | Key::Up | Key::Right | Key::Left => + is_player_alive && self.handle_user_movement(key), + Key::Space => is_player_alive, _ => false }; } fn create_new_run(&mut self) -> bool { - if self.current_run.player.current_hp == 0 { - self.current_run = Run::new(); - } + self.current_run = Run::new(); false }