diff options
| author | salmonik <salmonik@tuta.io> | 2026-07-11 15:48:39 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-07-11 15:48:39 +0200 |
| commit | 9939249066befd6534a57a326b742e415bd59b15 (patch) | |
| tree | 804a5418eab14d64665f67df08d66a0ed435d47f | |
| parent | add enemy AI: chase, patrol, attack, and movement animation (diff) | |
| download | dungeon-9939249066befd6534a57a326b742e415bd59b15.tar.gz dungeon-9939249066befd6534a57a326b742e415bd59b15.zip | |
add floor transition: Space on exit descends to next depth
| -rw-r--r-- | src/game.rs | 24 | ||||
| -rw-r--r-- | src/main.rs | 13 |
2 files changed, 32 insertions, 5 deletions
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 { | |||
| 1585 | 1585 | ||
| 1586 | // ---- misc ------------------------------------------------------------- | 1586 | // ---- misc ------------------------------------------------------------- |
| 1587 | 1587 | ||
| 1588 | pub fn check_win(&self) -> bool { | 1588 | /// True when the player is standing on the exit staircase. |
| 1589 | pub fn on_exit(&self) -> bool { | ||
| 1589 | self.maze.is_exit(self.player.x, self.player.y) | 1590 | self.maze.is_exit(self.player.x, self.player.y) |
| 1590 | } | 1591 | } |
| 1591 | 1592 | ||
| 1593 | /// Descend to the next dungeon depth. Generates a new maze, places the | ||
| 1594 | /// player in a starting room facing east. All stats, inventory, and | ||
| 1595 | /// weapon carry over. | ||
| 1596 | pub fn descend(&mut self) { | ||
| 1597 | self.depth += 1; | ||
| 1598 | let mut rng = rand::rng(); | ||
| 1599 | let (maze, (start_x, start_y)) = Maze::generate(self.depth, &mut rng); | ||
| 1600 | self.maze = maze; | ||
| 1601 | self.player = Player::new(start_x, start_y, 0.0); // facing east | ||
| 1602 | self.wall_texture = crate::texture::generate_wall_texture(&mut rng); | ||
| 1603 | self.floor_texture = crate::texture::generate_floor_texture(&mut rng); | ||
| 1604 | self.exit_texture = crate::texture::generate_exit_texture(&mut rng); | ||
| 1605 | self.state = GameState::WaitingForInput; | ||
| 1606 | self.moving = false; | ||
| 1607 | self.turning = false; | ||
| 1608 | self.attacking = false; | ||
| 1609 | self.enemy_moves.clear(); | ||
| 1610 | self.acted_this_turn.clear(); | ||
| 1611 | self.set_message(&format!("You descend to depth {}...", self.depth)); | ||
| 1612 | } | ||
| 1613 | |||
| 1592 | /// Whole heartbeats elapsed (displayed in HUD). | 1614 | /// Whole heartbeats elapsed (displayed in HUD). |
| 1593 | pub fn heartbeats(&self) -> usize { | 1615 | pub fn heartbeats(&self) -> usize { |
| 1594 | self.heartbeat_count as usize | 1616 | 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() { | |||
| 110 | } else if cur_e && !prev_e { | 110 | } else if cur_e && !prev_e { |
| 111 | game.turn_right(); | 111 | game.turn_right(); |
| 112 | } else if cur_space && !prev_space { | 112 | } else if cur_space && !prev_space { |
| 113 | game.attack(); | 113 | if game.on_exit() { |
| 114 | game.descend(); | ||
| 115 | } else { | ||
| 116 | game.attack(); | ||
| 117 | } | ||
| 114 | } else if cur_z && !prev_z { | 118 | } else if cur_z && !prev_z { |
| 115 | game.use_item(); | 119 | game.use_item(); |
| 116 | } else if cur_x && !prev_x { | 120 | } else if cur_x && !prev_x { |
| @@ -156,9 +160,10 @@ fn main() { | |||
| 156 | } | 160 | } |
| 157 | } | 161 | } |
| 158 | 162 | ||
| 159 | // ---- win check (placeholder — becomes staircase in Phase 1) ---- | 163 | // ---- descend prompt ---- |
| 160 | if game.check_win() { | 164 | // Show the prompt persistently while the player stands on the exit. |
| 161 | std::process::exit(0); | 165 | if game.on_exit() && game.state == GameState::WaitingForInput { |
| 166 | game.set_message("Press Space to descend..."); | ||
| 162 | } | 167 | } |
| 163 | 168 | ||
| 164 | // ---- render ---- | 169 | // ---- render ---- |
