X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fworldmap%2Ftux.cpp;h=2e89f04803cdf66101039facf9be28e71b4b0aa7;hb=4a486d92343d1824b311c234e9321e08f280fe68;hp=0e8e2a70725df315c6033d94e1235823663b888f;hpb=2bae88e5e4c711db0e12a1339777e0fb4bba73c5;p=supertux.git diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index 0e8e2a707..2e89f0480 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -34,14 +34,14 @@ namespace WorldMapNS { -static const float TUXSPEED = 200; +static const float TUXSPEED = 200; static const float map_message_TIME = 2.8; Tux::Tux(WorldMap* worldmap_) : worldmap(worldmap_) { sprite.reset(sprite_manager->create("images/worldmap/common/tux.sprite")); - + offset = 0; moving = false; direction = D_NONE; @@ -98,7 +98,7 @@ Tux::get_pos() case D_NONE: break; } - + return Vector(x, y); } @@ -117,11 +117,11 @@ Tux::set_direction(Direction dir) input_direction = dir; } -void -Tux::tryStartWalking() +void +Tux::tryStartWalking() { if (moving) - return; + return; if (input_direction == D_NONE) return; @@ -143,7 +143,7 @@ Tux::tryStartWalking() } } -bool +bool Tux::canWalk(const Tile* tile, Direction dir) { return ((tile->getData() & Tile::WORLDMAP_NORTH && dir == D_NORTH) || @@ -152,7 +152,7 @@ Tux::canWalk(const Tile* tile, Direction dir) (tile->getData() & Tile::WORLDMAP_WEST && dir == D_WEST)); } -void +void Tux::tryContinueWalking(float elapsed_time) { if (!moving) @@ -170,13 +170,13 @@ 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_change->in_stay_action = false; + sprite_change->clear_stay_action(); } // if this is a special_tile with passive_message, display it SpecialTile* special_tile = worldmap->at_special_tile(); if(special_tile) - { + { // direction and the apply_action_ are opposites, since they "see" // directions in a different way if((direction == D_NORTH && special_tile->apply_action_south) || @@ -217,8 +217,8 @@ Tux::tryContinueWalking(float elapsed_time) // 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)) { + if (direction != input_direction) { + if(canWalk(tile, input_direction)) { direction = input_direction; back_direction = reverse_dir(direction); } @@ -248,7 +248,7 @@ Tux::tryContinueWalking(float elapsed_time) // Walk automatically to the next tile if(direction == D_NONE) return; - + Vector next_tile; if (!worldmap->path_ok(direction, tile_pos, &next_tile)) { log_warning << "Tilemap data is buggy" << std::endl; @@ -259,12 +259,12 @@ 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()) )); - next_sprite->in_stay_action = false; + next_sprite->clear_stay_action(); } SpriteChange* last_sprite = worldmap->at_sprite_change(tile_pos); if(last_sprite != NULL && next_sprite != NULL) { log_debug << "Old: " << tile_pos << " New: " << next_tile << std::endl; - last_sprite->in_stay_action = true; + last_sprite->set_stay_action(); } tile_pos = next_tile; @@ -286,11 +286,22 @@ Tux::updateInputDirection() void Tux::update(float elapsed_time) { - updateInputDirection(); + updateInputDirection(); if (moving) tryContinueWalking(elapsed_time); else tryStartWalking(); } +void +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_change->clear_stay_action(); + } +} + }