X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftrigger%2Fdoor.cpp;h=f8d2b72869b81ecf77af67756e3e1112535ceb63;hb=472d0ad804844d28811c86f03da74b6d6be53f1b;hp=f21d01c11e9a69e2329b9eb0360a0cfa240c5fe9;hpb=fc3c10b10042ffa92c63a9dc227d5e88095e2b73;p=supertux.git diff --git a/src/trigger/door.cpp b/src/trigger/door.cpp index f21d01c11..f8d2b7286 100644 --- a/src/trigger/door.cpp +++ b/src/trigger/door.cpp @@ -28,6 +28,7 @@ #include "video/drawing_context.hpp" #include "lisp/lisp.hpp" #include "lisp/writer.hpp" +#include "audio/sound_manager.hpp" Door::Door(const lisp::Lisp& reader) : state(CLOSED) @@ -39,7 +40,7 @@ Door::Door(const lisp::Lisp& reader) sprite = sprite_manager->create("images/objects/door/door.sprite"); sprite->set_action("closed"); - bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); + bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); } Door::Door(int x, int y, std::string sector, std::string spawnpoint) @@ -51,7 +52,7 @@ Door::Door(int x, int y, std::string sector, std::string spawnpoint) sprite = sprite_manager->create("images/objects/door/door.sprite"); sprite->set_action("closed"); - bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); + bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); } Door::~Door() @@ -68,10 +69,10 @@ Door::write(lisp::Writer& writer) writer.write_float("y", bbox.p1.y); writer.write_float("width", bbox.get_width()); writer.write_float("height", bbox.get_height()); - + writer.write_string("sector", target_sector); writer.write_string("spawnpoint", target_spawnpoint); - + sound_manager->preload("sounds/door.wav"); writer.end_list("door"); } @@ -82,19 +83,22 @@ Door::update(float ) case CLOSED: break; case OPENING: + // if door has finished opening, start timer and keep door open if(sprite->animation_done()) { state = OPEN; sprite->set_action("open"); - stay_open_timer.start(1.0); + stay_open_timer.start(1.0); } break; case OPEN: + // if door was open long enough, start closing it if (stay_open_timer.check()) { state = CLOSING; sprite->set_action("closing", 1); } break; case CLOSING: + // if door has finished closing, keep it shut if(sprite->animation_done()) { state = CLOSED; sprite->set_action("closed"); @@ -106,16 +110,18 @@ Door::update(float ) void Door::draw(DrawingContext& context) { - sprite->draw(context, bbox.p1, LAYER_TILES); + sprite->draw(context, bbox.p1, LAYER_BACKGROUNDTILES+1); } void -Door::event(Player& who, EventType type) +Door::event(Player& , EventType type) { switch (state) { case CLOSED: + // if door was activated, start opening it if (type == EVENT_ACTIVATE) { state = OPENING; + sound_manager->play("sounds/door.wav"); sprite->set_action("opening", 1); } break; @@ -138,6 +144,7 @@ Door::collision(GameObject& other, const CollisionHit& hit) break; case OPEN: { + // if door is open and was touched by a player, teleport the player Player* player = dynamic_cast (&other); if (player) { state = CLOSING;