X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Flantern.cpp;h=b041fb89de7b9d64119561fe85a3369068a0c67a;hb=75acd4b141f45e851a492f089aa9ad24a9552409;hp=a91b15ffc28f0e8a125e6bc99732b30081083bd5;hpb=9f9a92cd9d8433c6d4d63b0178fd038a95b9e1a1;p=supertux.git diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index a91b15ffc..b041fb89d 100644 --- a/src/object/lantern.cpp +++ b/src/object/lantern.cpp @@ -20,10 +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"), @@ -31,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() @@ -69,10 +84,11 @@ Lantern::draw(DrawingContext& context){ } HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { - if ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + 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(); @@ -80,6 +96,7 @@ HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { 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(); @@ -94,7 +111,7 @@ Lantern::grab(MovingObject& object, const Vector& pos, Direction dir) Rock::grab(object, pos, dir); // if lantern is not lit, draw it as opened - if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + if (is_open()) { sprite->set_action("off-open"); } @@ -103,12 +120,18 @@ Lantern::grab(MovingObject& object, const Vector& pos, Direction dir) void Lantern::ungrab(MovingObject& object, Direction dir) { - Rock::ungrab(object, dir); - // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again - if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + 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");