4 // Copyright (C) 2006 Wolfgang Becker <uafr@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "lantern.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "object_factory.hpp"
26 #include "badguy/willowisp.hpp"
27 #include "badguy/treewillowisp.hpp"
28 #include "audio/sound_manager.hpp"
29 #include "sprite/sprite.hpp"
30 #include "video/drawing_context.hpp"
32 Lantern::Lantern(const lisp::Lisp& reader)
33 : Rock(reader, "images/objects/lantern/lantern.sprite"),
34 lightcolor(1.0f, 1.0f, 1.0f)
37 std::vector<float> vColor;
38 reader.get("color", vColor);
39 lightcolor = Color(vColor);
40 lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite");
41 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
43 sound_manager->preload("sounds/willocatch.wav");
46 Lantern::Lantern(const Vector& pos)
47 : Rock(pos, "images/objects/lantern/lantern.sprite"),
48 lightcolor(0.0f, 0.0f, 0.0f)
50 lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite");
51 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
53 sound_manager->preload("sounds/willocatch.wav");
62 Lantern::updateColor(){
63 lightsprite->set_color(lightcolor);
64 //Turn lantern off if light is black
65 if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){
66 sprite->set_action("off");
68 sprite->set_action("normal");
69 sprite->set_color(lightcolor);
74 Lantern::draw(DrawingContext& context){
76 MovingSprite::draw(context);
78 context.push_target();
79 context.set_target(DrawingContext::LIGHTMAP);
81 lightsprite->draw(context, get_bbox().get_middle(), 0);
86 HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) {
88 WillOWisp* wow = dynamic_cast<WillOWisp*>(&other);
90 // collided with WillOWisp while grabbed and unlit
91 sound_manager->play("sounds/willocatch.wav");
92 lightcolor = Color(0,1,0);
96 TreeWillOWisp* twow = dynamic_cast<TreeWillOWisp*>(&other);
98 // collided with TreeWillOWisp while grabbed and unlit
99 sound_manager->play("sounds/willocatch.wav");
100 lightcolor = twow->get_color();
105 return Rock::collision(other, hit);
109 Lantern::grab(MovingObject& object, const Vector& pos, Direction dir)
111 Rock::grab(object, pos, dir);
113 // if lantern is not lit, draw it as opened
115 sprite->set_action("off-open");
121 Lantern::ungrab(MovingObject& object, Direction dir)
123 // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again
125 sprite->set_action("off");
128 Rock::ungrab(object, dir);
134 return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0);
137 IMPLEMENT_FACTORY(Lantern, "lantern");