Added simple cheat menu to grow/fire/ice/shrink/... Tux
authorIngo Ruhnke <grumbel@gmail.com>
Fri, 15 Aug 2014 07:43:41 +0000 (09:43 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Fri, 15 Aug 2014 07:44:48 +0000 (09:44 +0200)
src/control/controller.cpp
src/control/controller.hpp
src/control/game_controller_manager.cpp
src/control/keyboard_manager.cpp
src/supertux/game_session.cpp
src/supertux/menu/cheat_menu.cpp [new file with mode: 0644]
src/supertux/menu/cheat_menu.hpp [new file with mode: 0644]
src/supertux/menu/menu_storage.cpp
src/supertux/menu/menu_storage.hpp

index 6a3882e..a25c39b 100644 (file)
@@ -26,6 +26,7 @@ const char* Controller::controlNames[] = {
   "pause-menu",
   "menu-select",
   "menu-back",
+  "cheat-menu",
   "console",
   "peek-left",
   "peek-right",
index b73695d..8d8543e 100644 (file)
@@ -35,6 +35,7 @@ public:
     MENU_SELECT,
     MENU_BACK,
 
+    CHEAT_MENU,
     CONSOLE,
 
     PEEK_LEFT,
index e7ca81d..4c9ccbf 100644 (file)
@@ -67,10 +67,11 @@ GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev)
       break;
 
     case SDL_CONTROLLER_BUTTON_BACK:
+      set_control(Controller::CONSOLE, ev.state);
       break;
 
     case SDL_CONTROLLER_BUTTON_GUIDE:
-      set_control(Controller::CONSOLE, ev.state);
+      set_control(Controller::CHEAT_MENU, ev.state);
       break;
 
     case SDL_CONTROLLER_BUTTON_START:
index d46e4f6..0fe55b6 100644 (file)
@@ -51,6 +51,7 @@ KeyboardManager::KeyboardManager(InputManager* parent) :
   keymap[SDLK_PAGEDOWN] = Controller::PEEK_RIGHT;
   keymap[SDLK_HOME]     = Controller::PEEK_UP;
   keymap[SDLK_END]      = Controller::PEEK_DOWN;
+  keymap[SDLK_TAB]      = Controller::CHEAT_MENU;
 }
 
 KeyboardManager::~KeyboardManager()
index 8fb7427..3ddedfc 100644 (file)
@@ -417,7 +417,15 @@ GameSession::update(float elapsed_time)
 {
   // handle controller
   if(g_input_manager->get_controller()->pressed(Controller::PAUSE_MENU))
+  {
     on_escape_press();
+  }
+
+  if(g_input_manager->get_controller()->pressed(Controller::CHEAT_MENU))
+  {
+    game_pause = true;
+    MenuManager::instance().set_menu(MenuStorage::CHEAT_MENU);
+  }
 
   process_events();
   MenuManager::instance().check_menu();
diff --git a/src/supertux/menu/cheat_menu.cpp b/src/supertux/menu/cheat_menu.cpp
new file mode 100644 (file)
index 0000000..f31d80d
--- /dev/null
@@ -0,0 +1,109 @@
+//  SuperTux
+//  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "supertux/menu/cheat_menu.hpp"
+
+#include "gui/menu_item.hpp"
+#include "gui/menu_manager.hpp"
+#include "object/player.hpp"
+#include "supertux/game_session.hpp"
+#include "supertux/player_status.hpp"
+#include "supertux/sector.hpp"
+#include "util/gettext.hpp"
+
+CheatMenu::CheatMenu()
+{
+  add_label(_("Cheats"));
+  add_hl();
+  add_entry(MNID_GROW, _("Bonus: Grow"));
+  add_entry(MNID_FIRE, _("Bonus: Fire"));
+  add_entry(MNID_ICE, _("Bonus: Ice"));
+  add_entry(MNID_STAR, _("Bonus: Star"));
+  add_entry(MNID_SHRINK, _("Shrink Tux"));
+  add_entry(MNID_KILL, _("Kill Tux"));
+  add_entry(MNID_FINISH, _("Finish Level"));
+  add_hl();
+  add_back(_("Back"));
+}
+
+void
+CheatMenu::menu_action(MenuItem* item)
+{
+  if (Sector::current())
+  {
+    std::vector<Player*> players = Sector::current()->get_players();
+    Player* player = players.empty() ? nullptr : players[0];
+
+    switch(item->id)
+    {
+      case MNID_GROW:
+        if (player)
+        {
+          player->set_bonus(GROWUP_BONUS);
+        }
+        break;
+
+      case MNID_FIRE:
+        if (player)
+        {
+          player->set_bonus(FIRE_BONUS);
+        }
+        break;
+
+      case MNID_ICE:
+        if (player)
+        {
+          player->set_bonus(ICE_BONUS);
+        }
+        break;
+
+      case MNID_STAR:
+        if (player)
+        {
+          player->make_invincible();
+        }
+        break;
+
+      case MNID_SHRINK:
+        if (player)
+        {
+          player->kill(false);
+        }
+        break;
+
+      case MNID_KILL:
+        if (player)
+        {
+          player->kill(true);
+        }
+        break;
+
+      case MNID_FINISH:
+        if (GameSession::current())
+        {
+          GameSession::current()->finish(true);
+        }
+        break;
+
+      default:
+        break;
+    }
+  }
+
+  MenuManager::instance().clear_menu_stack();
+}
+
+/* EOF */
diff --git a/src/supertux/menu/cheat_menu.hpp b/src/supertux/menu/cheat_menu.hpp
new file mode 100644 (file)
index 0000000..708b2d8
--- /dev/null
@@ -0,0 +1,48 @@
+//  SuperTux
+//  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_CHEAT_MENU_HPP
+#define HEADER_SUPERTUX_SUPERTUX_MENU_CHEAT_MENU_HPP
+
+#include "gui/menu.hpp"
+
+class CheatMenu : public Menu
+{
+private:
+  enum MenuIDs {
+    MNID_GROW,
+    MNID_FIRE,
+    MNID_ICE,
+    MNID_STAR,
+    MNID_SHRINK,
+    MNID_KILL,
+    MNID_FINISH
+  };
+
+public:
+  CheatMenu();
+
+  void menu_action(MenuItem* item) override;
+  void check_menu() override {}
+
+private:
+  CheatMenu(const CheatMenu&) = delete;
+  CheatMenu& operator=(const CheatMenu&) = delete;
+};
+
+#endif
+
+/* EOF */
index a0706ff..da69440 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "supertux/globals.hpp"
 #include "supertux/menu/addon_menu.hpp"
+#include "supertux/menu/cheat_menu.hpp"
 #include "supertux/menu/contrib_menu.hpp"
 #include "supertux/menu/game_menu.hpp"
 #include "supertux/menu/joystick_menu.hpp"
@@ -80,6 +81,9 @@ MenuStorage::create(MenuId menu_id)
     case GAME_MENU:
       return std::unique_ptr<Menu>(new GameMenu);
 
+    case CHEAT_MENU:
+      return std::unique_ptr<Menu>(new CheatMenu);
+
     case CONTRIB_MENU:
       return std::unique_ptr<Menu>(new ContribMenu);
 
index 44aaf51..d88e931 100644 (file)
@@ -46,7 +46,8 @@ public:
     KEYBOARD_MENU,
     JOYSTICK_MENU,
     WORLDMAP_MENU,
-    GAME_MENU
+    GAME_MENU,
+    CHEAT_MENU
   };
 
 public: