From 9939249066befd6534a57a326b742e415bd59b15 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 11 Jul 2026 15:48:39 +0200 Subject: add floor transition: Space on exit descends to next depth --- src/game.rs | 24 +++++++++++++++++++++++- src/main.rs | 13 +++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/game.rs b/src/game.rs index 992023e..1c13dd4 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1585,10 +1585,32 @@ impl Game { // ---- misc ------------------------------------------------------------- - pub fn check_win(&self) -> bool { + /// True when the player is standing on the exit staircase. + pub fn on_exit(&self) -> bool { self.maze.is_exit(self.player.x, self.player.y) } + /// Descend to the next dungeon depth. Generates a new maze, places the + /// player in a starting room facing east. All stats, inventory, and + /// weapon carry over. + pub fn descend(&mut self) { + self.depth += 1; + let mut rng = rand::rng(); + let (maze, (start_x, start_y)) = Maze::generate(self.depth, &mut rng); + self.maze = maze; + self.player = Player::new(start_x, start_y, 0.0); // facing east + self.wall_texture = crate::texture::generate_wall_texture(&mut rng); + self.floor_texture = crate::texture::generate_floor_texture(&mut rng); + self.exit_texture = crate::texture::generate_exit_texture(&mut rng); + self.state = GameState::WaitingForInput; + self.moving = false; + self.turning = false; + self.attacking = false; + self.enemy_moves.clear(); + self.acted_this_turn.clear(); + self.set_message(&format!("You descend to depth {}...", self.depth)); + } + /// Whole heartbeats elapsed (displayed in HUD). pub fn heartbeats(&self) -> usize { self.heartbeat_count as usize diff --git a/src/main.rs b/src/main.rs index e82d939..694773d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,11 @@ fn main() { } else if cur_e && !prev_e { game.turn_right(); } else if cur_space && !prev_space { - game.attack(); + if game.on_exit() { + game.descend(); + } else { + game.attack(); + } } else if cur_z && !prev_z { game.use_item(); } else if cur_x && !prev_x { @@ -156,9 +160,10 @@ fn main() { } } - // ---- win check (placeholder — becomes staircase in Phase 1) ---- - if game.check_win() { - std::process::exit(0); + // ---- descend prompt ---- + // Show the prompt persistently while the player stands on the exit. + if game.on_exit() && game.state == GameState::WaitingForInput { + game.set_message("Press Space to descend..."); } // ---- render ---- -- cgit v1.2.3