[cppcheck] Part 3: More perf fixes that were missed during non-verbose run for whatev...
[supertux.git] / src / worldmap / tux.cpp
index 7ecfb12..2ea454b 100644 (file)
@@ -1,5 +1,5 @@
 //  SuperTux -  A Jump'n Run
-//  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
+//  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmail.com>
 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
 //
 //  This program is free software: you can redistribute it and/or modify
 //  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 "control/joystickkeyboardcontroller.hpp"
+#include "control/input_manager.hpp"
 #include "scripting/squirrel_util.hpp"
 #include "sprite/sprite.hpp"
 #include "sprite/sprite_manager.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/player_status.hpp"
+#include "supertux/savegame.hpp"
 #include "supertux/tile.hpp"
 #include "worldmap/level.hpp"
 #include "worldmap/tux.hpp"
@@ -33,7 +34,7 @@ static const float map_message_TIME = 2.8f;
 Tux::Tux(WorldMap* worldmap_) :
   back_direction(),
   worldmap(worldmap_),
-  sprite(),
+  sprite(SpriteManager::current()->create("images/worldmap/common/tux.sprite")),
   controller(),
   input_direction(),
   direction(),
@@ -42,8 +43,6 @@ Tux::Tux(WorldMap* worldmap_) :
   moving(),
   ghost_mode()
 {
-  sprite = sprite_manager->create("images/worldmap/common/tux.sprite");
-
   offset = 0;
   moving = false;
   direction = D_NONE;
@@ -59,13 +58,22 @@ Tux::~Tux()
 void
 Tux::draw(DrawingContext& context)
 {
-  switch (player_status->bonus) {
+  switch (worldmap->get_savegame().get_player_status()->bonus) {
     case GROWUP_BONUS:
       sprite->set_action(moving ? "large-walking" : "large-stop");
       break;
     case FIRE_BONUS:
       sprite->set_action(moving ? "fire-walking" : "fire-stop");
       break;
+    case ICE_BONUS:
+      sprite->set_action(moving ? "ice-walking" : "ice-stop");
+      break;
+    case AIR_BONUS:
+      sprite->set_action(moving ? "ice-walking" : "ice-stop");
+      break;
+    case EARTH_BONUS:
+      sprite->set_action(moving ? "fire-walking" : "fire-stop");
+      break;
     case NO_BONUS:
       sprite->set_action(moving ? "small-walking" : "small-stop");
       break;
@@ -144,7 +152,7 @@ Tux::tryStartWalking()
 
   // We got a new direction, so lets start walking when possible
   Vector next_tile;
-  if ((!level || level->solved)
+  if ((!level || level->solved || level->perfect)
       && worldmap->path_ok(input_direction, tile_pos, &next_tile)) {
     tile_pos = next_tile;
     moving = true;
@@ -161,7 +169,7 @@ Tux::tryStartWalking()
 bool
 Tux::canWalk(int tile_data, Direction dir)
 {
-  return ghost_mode || 
+  return ghost_mode ||
     ((tile_data & Tile::WORLDMAP_NORTH && dir == D_NORTH) ||
      (tile_data & Tile::WORLDMAP_SOUTH && dir == D_SOUTH) ||
      (tile_data & Tile::WORLDMAP_EAST  && dir == D_EAST) ||
@@ -287,13 +295,14 @@ Tux::tryContinueWalking(float elapsed_time)
 void
 Tux::updateInputDirection()
 {
-  if(g_main_controller->hold(Controller::UP))
+  Controller* controller_ = InputManager::current()->get_controller();
+  if(controller_->hold(Controller::UP))
     input_direction = D_NORTH;
-  else if(g_main_controller->hold(Controller::DOWN))
+  else if(controller_->hold(Controller::DOWN))
     input_direction = D_SOUTH;
-  else if(g_main_controller->hold(Controller::LEFT))
+  else if(controller_->hold(Controller::LEFT))
     input_direction = D_WEST;
-  else if(g_main_controller->hold(Controller::RIGHT))
+  else if(controller_->hold(Controller::RIGHT))
     input_direction = D_EAST;
 }