X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Flantern.cpp;h=b041fb89de7b9d64119561fe85a3369068a0c67a;hb=75acd4b141f45e851a492f089aa9ad24a9552409;hp=e877a72d2bac552844ef412a974cc00ff6e4112f;hpb=df0550c02366ae190426938737a3adc9eda3f6a6;p=supertux.git diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index e877a72d2..b041fb89d 100644 --- a/src/object/lantern.cpp +++ b/src/object/lantern.cpp @@ -20,8 +20,14 @@ #include #include "lantern.hpp" + #include "sprite/sprite_manager.hpp" #include "object_factory.hpp" +#include "badguy/willowisp.hpp" +#include "badguy/treewillowisp.hpp" +#include "audio/sound_manager.hpp" +#include "sprite/sprite.hpp" +#include "video/drawing_context.hpp" Lantern::Lantern(const lisp::Lisp& reader) : Rock(reader, "images/objects/lantern/lantern.sprite"), @@ -29,11 +35,22 @@ Lantern::Lantern(const lisp::Lisp& reader) { //get color from lisp std::vector vColor; - reader.get_vector("color", vColor); + reader.get("color", vColor); lightcolor = Color(vColor); lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); updateColor(); + sound_manager->preload("sounds/willocatch.wav"); +} + +Lantern::Lantern(const Vector& pos) + : Rock(pos, "images/objects/lantern/lantern.sprite"), + lightcolor(0.0f, 0.0f, 0.0f) +{ + lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"); + lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + updateColor(); + sound_manager->preload("sounds/willocatch.wav"); } Lantern::~Lantern() @@ -66,4 +83,56 @@ Lantern::draw(DrawingContext& context){ context.pop_target(); } +HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { + if (is_open()) { + WillOWisp* wow = dynamic_cast(&other); + if (wow) { + // collided with WillOWisp while grabbed and unlit + sound_manager->play("sounds/willocatch.wav"); + lightcolor = Color(0,1,0); + updateColor(); + wow->vanish(); + } + TreeWillOWisp* twow = dynamic_cast(&other); + if (twow) { + // collided with TreeWillOWisp while grabbed and unlit + sound_manager->play("sounds/willocatch.wav"); + lightcolor = twow->get_color(); + updateColor(); + twow->vanish(); + } + } + return Rock::collision(other, hit); +} + +void +Lantern::grab(MovingObject& object, const Vector& pos, Direction dir) +{ + Rock::grab(object, pos, dir); + + // if lantern is not lit, draw it as opened + if (is_open()) { + sprite->set_action("off-open"); + } + +} + +void +Lantern::ungrab(MovingObject& object, Direction dir) +{ + // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again + if (is_open()) { + sprite->set_action("off"); + } + + Rock::ungrab(object, dir); +} + +bool +Lantern::is_open() +{ + return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0); +} + IMPLEMENT_FACTORY(Lantern, "lantern"); +