X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdoor.cpp;h=4feec95d5a2459802f5e82d4a9bba9b1c0455b3b;hb=42503cac8eac1199cccec2d4fbed7fde41a2bb55;hp=89db33e33cbeaa38235faabca162e6f014e29fda;hpb=cf4de5d58eb99a11369c329c01bfa5abe4b0a398;p=supertux.git diff --git a/src/door.cpp b/src/door.cpp index 89db33e33..4feec95d5 100644 --- a/src/door.cpp +++ b/src/door.cpp @@ -16,15 +16,22 @@ // 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 "door.h" -#include "lispreader.h" -#include "lispwriter.h" +#include "door.h" +#include "utils/lispreader.h" +#include "utils/lispwriter.h" #include "gameloop.h" #include "resources.h" -#include "sprite.h" -#include "sprite_manager.h" -#include "screen/drawing_context.h" +#include "special/sprite.h" +#include "special/sprite_manager.h" +#include "video/drawing_context.h" +#include "app/globals.h" + +using namespace SuperTux; + +/** data images */ +Sprite* door; +Surface* door_opening[DOOR_OPENING_FRAMES]; Door::Door(LispReader& reader) { @@ -36,7 +43,23 @@ Door::Door(LispReader& reader) reader.read_string("sector", target_sector); reader.read_string("spawnpoint", target_spawnpoint); - sprite = sprite_manager->load("door"); + animation_timer.init(true); + door_activated = false; + + animation_timer.init(true); +} + +Door::Door(int x, int y) +{ +area.x = x; +area.y = y; +area.width = 32; +area.height = 64; + +animation_timer.init(true); +door_activated = false; + +animation_timer.init(true); } void @@ -67,14 +90,29 @@ Door::action(float ) void Door::draw(DrawingContext& context) { - sprite->draw(context, Vector(area.x, area.y), LAYER_TILES); + if(animation_timer.check()) + context.draw_surface(door_opening[(animation_timer.get_gone() * DOOR_OPENING_FRAMES) / + DOOR_OPENING_TIME], Vector(area.x, area.y - (door_opening[0]->h/2)), LAYER_TILES); + else + door->draw(context, Vector(area.x, area.y), LAYER_TILES); + + //Check if door animation is complete + //TODO: Move this out of the "draw" method as this is extremely dirty :) + if ((!animation_timer.check()) && (door_activated)) { + door_activated = false; + GameSession::current()->respawn(target_sector, target_spawnpoint); + } } void Door::interaction(InteractionType type) { + //Animate the door on activation + //TODO: Resetting the animation doesn't work correctly + // Tux and badguys should stop moving while the door is opening if(type == INTERACTION_ACTIVATE) { - GameSession::current()->respawn(target_sector, target_spawnpoint); + animation_timer.start(DOOR_OPENING_TIME); + door_activated = true; } }