projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Moved Menu stuff to its own directory
[supertux.git]
/
src
/
worldmap
/
tux.cpp
diff --git
a/src/worldmap/tux.cpp
b/src/worldmap/tux.cpp
index
b135933
..
a98cfd9
100644
(file)
--- a/
src/worldmap/tux.cpp
+++ b/
src/worldmap/tux.cpp
@@
-1,13
+1,11
@@
-// $Id$
-//
// SuperTux - A Jump'n Run
// Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
//
// SuperTux - A Jump'n Run
// Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
// 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
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-15,37
+13,43
@@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 "sprite/sprite_manager.hpp"
-#include "video/drawing_context.hpp"
-#include "player_status.hpp"
-#include "worldmap.hpp"
-#include "worldmap/level.hpp"
-#include "special_tile.hpp"
-#include "sprite_change.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "scripting/squirrel_util.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "scripting/squirrel_util.hpp"
-#include "main.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/player_status.hpp"
+#include "supertux/tile.hpp"
+#include "worldmap/level.hpp"
+#include "worldmap/tux.hpp"
-namespace WorldMapNS
-{
+namespace WorldMapNS {
static const float TUXSPEED = 200;
static const float map_message_TIME = 2.8f;
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(),
+ controller(),
+ input_direction(),
+ direction(),
+ tile_pos(),
+ offset(),
+ moving(),
+ ghost_mode()
{
{
- sprite
.reset(sprite_manager->create("images/worldmap/common/tux.sprite")
);
+ sprite
= sprite_manager->create("images/worldmap/common/tux.sprite"
);
offset = 0;
moving = false;
direction = D_NONE;
input_direction = D_NONE;
offset = 0;
moving = false;
direction = D_NONE;
input_direction = D_NONE;
+
+ ghost_mode = false;
}
Tux::~Tux()
}
Tux::~Tux()
@@
-74,7
+78,6
@@
Tux::draw(DrawingContext& context)
sprite->draw(context, get_pos(), LAYER_OBJECTS);
}
sprite->draw(context, get_pos(), LAYER_OBJECTS);
}
-
Vector
Tux::get_pos()
{
Vector
Tux::get_pos()
{
@@
-82,7
+85,7
@@
Tux::get_pos()
float y = tile_pos.y * 32;
switch(direction)
float y = tile_pos.y * 32;
switch(direction)
-
{
+ {
case D_WEST:
x -= offset - 32;
break;
case D_WEST:
x -= offset - 32;
break;
@@
-97,7
+100,7
@@
Tux::get_pos()
break;
case D_NONE:
break;
break;
case D_NONE:
break;
-
}
+ }
return Vector(x, y);
}
return Vector(x, y);
}
@@
-118,6
+121,18
@@
Tux::set_direction(Direction dir)
}
void
}
void
+Tux::set_ghost_mode(bool enabled)
+{
+ ghost_mode = enabled;
+}
+
+bool
+Tux::get_ghost_mode()
+{
+ return ghost_mode;
+}
+
+void
Tux::tryStartWalking()
{
if (moving)
Tux::tryStartWalking()
{
if (moving)
@@
-135,7
+150,7
@@
Tux::tryStartWalking()
moving = true;
direction = input_direction;
back_direction = reverse_dir(direction);
moving = true;
direction = input_direction;
back_direction = reverse_dir(direction);
- } else if (
input_direction == back_direction
) {
+ } else if (
ghost_mode || (input_direction == back_direction)
) {
moving = true;
direction = input_direction;
tile_pos = worldmap->get_next_tile(tile_pos, direction);
moving = true;
direction = input_direction;
tile_pos = worldmap->get_next_tile(tile_pos, direction);
@@
-144,12
+159,13
@@
Tux::tryStartWalking()
}
bool
}
bool
-Tux::canWalk(
const Tile* tile
, Direction dir)
+Tux::canWalk(
int tile_data
, Direction dir)
{
{
- return ((tile->getData() & Tile::WORLDMAP_NORTH && dir == D_NORTH) ||
- (tile->getData() & Tile::WORLDMAP_SOUTH && dir == D_SOUTH) ||
- (tile->getData() & Tile::WORLDMAP_EAST && dir == D_EAST) ||
- (tile->getData() & 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
}
void
@@
-180,9
+196,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 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;
{
if(special_tile->passive_message) {
worldmap->passive_message = special_tile->map_message;
@@
-204,33
+220,31
@@
Tux::tryContinueWalking(float elapsed_time)
// stop if we reached a level, a WORLDMAP_STOP tile, a teleporter or a special tile without a passive_message
if ((worldmap->at_level())
// stop if we reached a level, a WORLDMAP_STOP tile, a teleporter or a special tile without a passive_message
if ((worldmap->at_level())
- || (worldmap->
at(tile_pos)->getData(
) & Tile::WORLDMAP_STOP)
+ || (worldmap->
tile_data_at(tile_pos
) & Tile::WORLDMAP_STOP)
|| (special_tile && !special_tile->passive_message
|| (special_tile && !special_tile->passive_message
-
&& special_tile->script == "")
- || (teleporter)) {
+ && special_tile->script == "")
+ || (teleporter)
|| ghost_mode
) {
if(special_tile && !special_tile->map_message.empty()
if(special_tile && !special_tile->map_message.empty()
-
&& !special_tile->passive_message)
+ && !special_tile->passive_message)
worldmap->passive_message_timer.start(0);
stop();
return;
}
// if user wants to change direction, try changing, else guess the direction in which to walk next
worldmap->passive_message_timer.start(0);
stop();
return;
}
// if user wants to change direction, try changing, else guess the direction in which to walk next
- const Tile* tile = worldmap->at(tile_pos);
- if (direction != input_direction) {
- if(canWalk(tile, input_direction)) {
- direction = input_direction;
- back_direction = reverse_dir(direction);
- }
+ const int tile_data = worldmap->tile_data_at(tile_pos);
+ if ((direction != input_direction) && canWalk(tile_data, input_direction)) {
+ direction = input_direction;
+ back_direction = reverse_dir(direction);
} else {
Direction dir = D_NONE;
} else {
Direction dir = D_NONE;
- if (tile
->getData()
& Tile::WORLDMAP_NORTH && back_direction != D_NORTH)
+ if (tile
_data
& Tile::WORLDMAP_NORTH && back_direction != D_NORTH)
dir = D_NORTH;
dir = D_NORTH;
- else if (tile
->getData()
& Tile::WORLDMAP_SOUTH && back_direction != D_SOUTH)
+ else if (tile
_data
& Tile::WORLDMAP_SOUTH && back_direction != D_SOUTH)
dir = D_SOUTH;
dir = D_SOUTH;
- else if (tile
->getData()
& Tile::WORLDMAP_EAST && back_direction != D_EAST)
+ else if (tile
_data
& Tile::WORLDMAP_EAST && back_direction != D_EAST)
dir = D_EAST;
dir = D_EAST;
- else if (tile
->getData()
& Tile::WORLDMAP_WEST && back_direction != D_WEST)
+ else if (tile
_data
& Tile::WORLDMAP_WEST && back_direction != D_WEST)
dir = D_WEST;
if (dir == D_NONE) {
dir = D_WEST;
if (dir == D_NONE) {
@@
-250,8
+264,8
@@
Tux::tryContinueWalking(float elapsed_time)
return;
Vector next_tile;
return;
Vector next_tile;
- if (!worldmap->path_ok(direction, tile_pos, &next_tile)) {
- log_
warnin
g << "Tilemap data is buggy" << std::endl;
+ if (!
ghost_mode && !
worldmap->path_ok(direction, tile_pos, &next_tile)) {
+ log_
debu
g << "Tilemap data is buggy" << std::endl;
stop();
return;
}
stop();
return;
}
@@
-273,13
+287,13
@@
Tux::tryContinueWalking(float elapsed_time)
void
Tux::updateInputDirection()
{
void
Tux::updateInputDirection()
{
- if(main_controller->hold(Controller::UP))
+ if(
g_
main_controller->hold(Controller::UP))
input_direction = D_NORTH;
input_direction = D_NORTH;
- else if(main_controller->hold(Controller::DOWN))
+ else if(
g_
main_controller->hold(Controller::DOWN))
input_direction = D_SOUTH;
input_direction = D_SOUTH;
- else if(main_controller->hold(Controller::LEFT))
+ else if(
g_
main_controller->hold(Controller::LEFT))
input_direction = D_WEST;
input_direction = D_WEST;
- else if(main_controller->hold(Controller::RIGHT))
+ else if(
g_
main_controller->hold(Controller::RIGHT))
input_direction = D_EAST;
}
input_direction = D_EAST;
}
@@
-304,4
+318,6
@@
Tux::setup()
}
}
}
}
-}
+} // namespace WorldmapNS
+
+/* EOF */