From c4fb606d4d5934cae7be629b382007bfcc2ea6c8 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sat, 11 Sep 2004 14:22:01 +0000 Subject: [PATCH] Implemented a cheating system, mainly for debugging. It might be a bit ugly and could be faster. Feel free to replace it. Cheat words are: grow, fire, ice, lifeup, lifedown, invincible. SVN-Revision: 1896 --- src/gameloop.cpp | 85 +++++++++++++++++++++++++++++++++----------------------- src/gameloop.h | 5 ++-- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 76995bbab..217ca69ab 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -95,6 +95,8 @@ GameSession::restart_level() fps_timer.init(true); frame_timer.init(true); + last_keys.clear(); + #if 0 float old_x_pos = -1; if (world) @@ -361,42 +363,15 @@ GameSession::process_events() } } break; - case SDLK_TAB: - if(debug_mode) + default: + /* Check if chacrater is ASCII */ + char ch[2]; + if((event.key.keysym.unicode & 0xFF80) == 0) { - tux.grow(false); + ch[0] = event.key.keysym.unicode & 0x7F; + ch[1] = '\0'; } - break; - case SDLK_END: - if(debug_mode) - player_status.distros += 50; - break; - case SDLK_DELETE: - if(debug_mode) - tux.got_power = tux.FIRE_POWER; - break; - case SDLK_HOME: - if(debug_mode) - tux.got_power = tux.ICE_POWER; - break; - case SDLK_INSERT: - if(debug_mode) - tux.invincible_timer.start(TUX_INVINCIBLE_TIME); - break; - case SDLK_l: - if(debug_mode) - --player_status.lives; - break; - case SDLK_s: - if(debug_mode) - player_status.score += 1000; - case SDLK_f: - if(debug_fps) - debug_fps = false; - else - debug_fps = true; - break; - default: + last_keys.append(ch); // add to cheat keys break; } } @@ -474,6 +449,48 @@ GameSession::process_events() } } /* while */ } + +// Cheating words (the goal of this is really for debugging, but could +// be used for some cheating) +// TODO: this could be implmented in a more elegant and faster way +if(!last_keys.empty()) + { + Player &tux = *currentsector->player; + if(last_keys.find("grow") != std::string::npos) + { + tux.grow(false); + last_keys.clear(); + } + if(last_keys.find("fire") != std::string::npos) + { + tux.grow(false); + tux.got_power = tux.FIRE_POWER; + last_keys.clear(); + } + if(last_keys.find("ice") != std::string::npos) + { + tux.grow(false); + tux.got_power = tux.ICE_POWER; + last_keys.clear(); + } + if(last_keys.find("lifeup") != std::string::npos) + { + player_status.lives++; + last_keys.clear(); + } + if(last_keys.find("lifedown") != std::string::npos) + { + player_status.lives--; + last_keys.clear(); + } + if(last_keys.find("invincible") != std::string::npos) + { // be invincle for the rest of the level + tux.invincible_timer.start(time_left.get_left()); + last_keys.clear(); + } + if(last_keys.size() > 15) + last_keys.clear(); + } } void diff --git a/src/gameloop.h b/src/gameloop.h index 5e71456bd..d36c95c58 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -67,7 +67,6 @@ private: float fps_fps; FrameRate frame_rate; int pause_menu_frame; - int debug_fps; /** If true the end_sequence will be played, user input will be ignored while doing that */ @@ -116,6 +115,9 @@ public: private: static GameSession* current_; + // for cheating + std::string last_keys; + void restart_level(); void check_end_conditions(); @@ -127,7 +129,6 @@ private: void drawendscreen(); void drawresultscreen(void); -private: void on_escape_press(); void process_menu(); }; -- 2.11.0