Updated addon repository URL and improved debug output on download
[supertux.git] / src / worldmap / tux.cpp
index 1d49b2f..365b985 100644 (file)
@@ -1,13 +1,11 @@
-//  $Id$
-//
 //  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 it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  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
 //  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, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#include <config.h>
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "tux.hpp"
+#include "control/input_manager.hpp"
+#include "scripting/squirrel_util.hpp"
 #include "sprite/sprite.hpp"
 #include "sprite/sprite_manager.hpp"
-#include "video/drawing_context.hpp"
-#include "player_status.hpp"
-#include "worldmap.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/player_status.hpp"
+#include "supertux/savegame.hpp"
+#include "supertux/tile.hpp"
 #include "worldmap/level.hpp"
-#include "special_tile.hpp"
-#include "sprite_change.hpp"
-#include "control/joystickkeyboardcontroller.hpp"
-#include "scripting/squirrel_util.hpp"
-#include "tile.hpp"
-#include "main.hpp"
+#include "worldmap/tux.hpp"
 
-namespace WorldMapNS
-{
+namespace worldmap {
 
 static const float TUXSPEED = 200;
 static const float map_message_TIME = 2.8f;
 
-Tux::Tux(WorldMap* worldmap_)
-  : worldmap(worldmap_)
+Tux::Tux(WorldMap* worldmap_) :
+  back_direction(),
+  worldmap(worldmap_),
+  sprite(SpriteManager::current()->create("images/worldmap/common/tux.sprite")),
+  controller(),
+  input_direction(),
+  direction(),
+  tile_pos(),
+  offset(),
+  moving(),
+  ghost_mode()
 {
-  sprite.reset(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 ? "air-walking" : "air-stop");
+      break;
+    case EARTH_BONUS:
+      sprite->set_action(moving ? "earth-walking" : "earth-stop");
+      break;
     case NO_BONUS:
       sprite->set_action(moving ? "small-walking" : "small-stop");
       break;
@@ -78,7 +86,6 @@ Tux::draw(DrawingContext& context)
   sprite->draw(context, get_pos(), LAYER_OBJECTS);
 }
 
-
 Vector
 Tux::get_pos()
 {
@@ -86,7 +93,7 @@ Tux::get_pos()
   float y = tile_pos.y * 32;
 
   switch(direction)
-    {
+  {
     case D_WEST:
       x -= offset - 32;
       break;
@@ -101,7 +108,7 @@ Tux::get_pos()
       break;
     case D_NONE:
       break;
-    }
+  }
 
   return Vector(x, y);
 }
@@ -145,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;
@@ -162,11 +169,11 @@ Tux::tryStartWalking()
 bool
 Tux::canWalk(int tile_data, Direction dir)
 {
-  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) ||
-      (tile_data & Tile::WORLDMAP_WEST  && dir == D_WEST));
+  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) ||
+     (tile_data & Tile::WORLDMAP_WEST  && dir == D_WEST));
 }
 
 void
@@ -186,7 +193,7 @@ Tux::tryContinueWalking(float elapsed_time)
 
   SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos);
   if(sprite_change != NULL) {
-    sprite.reset(new Sprite( *(sprite_change->sprite.get()) ));
+    sprite = sprite_change->sprite->clone();
     sprite_change->clear_stay_action();
   }
 
@@ -197,9 +204,9 @@ Tux::tryContinueWalking(float elapsed_time)
     // direction and the apply_action_ are opposites, since they "see"
     // directions in a different way
     if((direction == D_NORTH && special_tile->apply_action_south) ||
-            (direction == D_SOUTH && special_tile->apply_action_north) ||
-            (direction == D_WEST && special_tile->apply_action_east) ||
-            (direction == D_EAST && special_tile->apply_action_west))
+       (direction == D_SOUTH && special_tile->apply_action_north) ||
+       (direction == D_WEST && special_tile->apply_action_east) ||
+       (direction == D_EAST && special_tile->apply_action_west))
     {
       if(special_tile->passive_message) {
         worldmap->passive_message = special_tile->map_message;
@@ -223,10 +230,10 @@ Tux::tryContinueWalking(float elapsed_time)
   if ((worldmap->at_level())
       || (worldmap->tile_data_at(tile_pos) & Tile::WORLDMAP_STOP)
       || (special_tile && !special_tile->passive_message
-                       && special_tile->script == "")
+          && special_tile->script == "")
       || (teleporter) || ghost_mode) {
     if(special_tile && !special_tile->map_message.empty()
-        && !special_tile->passive_message)
+       && !special_tile->passive_message)
       worldmap->passive_message_timer.start(0);
     stop();
     return;
@@ -273,7 +280,7 @@ Tux::tryContinueWalking(float elapsed_time)
 
   SpriteChange* next_sprite = worldmap->at_sprite_change(next_tile);
   if(next_sprite != NULL && next_sprite->change_on_touch) {
-    sprite.reset(new Sprite( *(next_sprite->sprite.get()) ));
+    sprite = next_sprite->sprite->clone();
     next_sprite->clear_stay_action();
   }
   SpriteChange* last_sprite = worldmap->at_sprite_change(tile_pos);
@@ -288,13 +295,14 @@ Tux::tryContinueWalking(float elapsed_time)
 void
 Tux::updateInputDirection()
 {
-  if(main_controller->hold(Controller::UP))
+  Controller* controller_ = InputManager::current()->get_controller();
+  if(controller_->hold(Controller::UP))
     input_direction = D_NORTH;
-  else if(main_controller->hold(Controller::DOWN))
+  else if(controller_->hold(Controller::DOWN))
     input_direction = D_SOUTH;
-  else if(main_controller->hold(Controller::LEFT))
+  else if(controller_->hold(Controller::LEFT))
     input_direction = D_WEST;
-  else if(main_controller->hold(Controller::RIGHT))
+  else if(controller_->hold(Controller::RIGHT))
     input_direction = D_EAST;
 }
 
@@ -314,9 +322,11 @@ Tux::setup()
   // check if we already touch a SpriteChange object
   SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos);
   if(sprite_change != NULL) {
-    sprite.reset(new Sprite( *(sprite_change->sprite.get()) ));
+    sprite = sprite_change->sprite->clone();
     sprite_change->clear_stay_action();
   }
 }
 
-}
+} // namespace WorldmapNS
+
+/* EOF */