diff options
author | Sven Gothel <[email protected]> | 2022-04-02 03:22:25 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-04-02 03:22:25 +0200 |
commit | f1949fdf091b216ff60371fa2c43ae77036fbe1d (patch) | |
tree | a2e381f5d53f78716943858549b50be4e614979f | |
parent | bf3242f09e0531ac664762fe1571a81398e22af2 (diff) |
'R' reset: Restart at chosen start_level and clear score
-rw-r--r-- | include/pacman/game.hpp | 1 | ||||
-rw-r--r-- | src/game.cpp | 11 |
2 files changed, 8 insertions, 4 deletions
diff --git a/include/pacman/game.hpp b/include/pacman/game.hpp index 561244e..f8dca67 100644 --- a/include/pacman/game.hpp +++ b/include/pacman/game.hpp @@ -425,6 +425,7 @@ class pacman_t { constexpr uint64_t score() const noexcept { return score_; } const box_t& freeze_box() const noexcept { return freeze_box_; } + void reset_score() noexcept { score_ = 0; } void set_mode(const mode_t m, const int mode_ms=-1) noexcept; void stop_audio_loops() noexcept; void set_speed(const float pct) noexcept; diff --git a/src/game.cpp b/src/game.cpp index f77fb8d..621275d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -343,8 +343,8 @@ static void set_game_mode(const game_mode_t m, const int caller) noexcept { const int old_level = current_level; switch( m ) { case game_mode_t::NEXT_LEVEL: - global_maze->reset(); ++current_level; + global_maze->reset(); [[fallthrough]]; case game_mode_t::START: pacman->set_mode( pacman_t::mode_t::LEVEL_SETUP ); @@ -384,6 +384,7 @@ int main(int argc, char *argv[]) bool show_targets = false; bool use_audio = false; int pixel_filter_quality = 0; + int start_level = 1; std::string record_bmpseq_basename; { for(int i=1; i<argc; ++i) { @@ -432,7 +433,7 @@ int main(int argc, char *argv[]) } else if( 0 == strcmp("-dist_manhatten", argv[i]) ) { manhatten_distance_enabled = true; } else if( 0 == strcmp("-level", argv[i]) && i+1<argc) { - current_level = atoi(argv[i+1]); + start_level = atoi(argv[i+1]); ++i; } else if( 0 == strcmp("-record", argv[i]) && i+1<argc) { record_bmpseq_basename = argv[i+1]; @@ -443,6 +444,7 @@ int main(int argc, char *argv[]) const std::string exename(argv[0]); global_maze = std::make_unique<maze_t>("media/playfield_pacman.txt"); + current_level = start_level; if( !global_maze->is_ok() ) { log_printf("Maze: Error: %s\n", global_maze->toString().c_str()); @@ -669,8 +671,9 @@ int main(int argc, char *argv[]) } break; case SDL_SCANCODE_R: - current_level = 1; - set_game_mode(game_mode_t::START, 15); + current_level = start_level - 1; + pacman->reset_score(); + set_game_mode(game_mode_t::NEXT_LEVEL, 15); break; case SDL_SCANCODE_W: case SDL_SCANCODE_UP: |