X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Flantern.cpp;h=b041fb89de7b9d64119561fe85a3369068a0c67a;hb=75acd4b141f45e851a492f089aa9ad24a9552409;hp=41c04f0a8f5a3eb21160c6f8b6859cd1d7372ba0;hpb=85016783ff1628b7de20e0c106cf55563aa77bed;p=supertux.git diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index 41c04f0a8..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,12 +35,22 @@ Lantern::Lantern(const lisp::Lisp& reader) { //get color from lisp std::vector vColor; - reader.get_vector("color", vColor ); - lightcolor = 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_color(lightcolor); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + updateColor(); + sound_manager->preload("sounds/willocatch.wav"); } Lantern::~Lantern() @@ -43,6 +59,18 @@ Lantern::~Lantern() } void +Lantern::updateColor(){ + lightsprite->set_color(lightcolor); + //Turn lantern off if light is black + if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + sprite->set_action("off"); + } else { + sprite->set_action("normal"); + sprite->set_color(lightcolor); + } +} + +void Lantern::draw(DrawingContext& context){ //Draw the Sprite. MovingSprite::draw(context); @@ -55,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"); +