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"
23 #include "sprite/sprite_manager.hpp"
24 #include "object_factory.hpp"
25 #include "badguy/willowisp.hpp"
26 #include "badguy/treewillowisp.hpp"
28 Lantern::Lantern(const lisp::Lisp& reader)
29 : Rock(reader, "images/objects/lantern/lantern.sprite"),
30 lightcolor(1.0f, 1.0f, 1.0f)
33 std::vector<float> vColor;
34 reader.get_vector("color", vColor);
35 lightcolor = Color(vColor);
36 lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite");
37 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
39 sound_manager->preload("sounds/willocatch.wav");
42 Lantern::Lantern(const Vector& pos)
43 : Rock(pos, "images/objects/lantern/lantern.sprite"),
44 lightcolor(0.0f, 0.0f, 0.0f)
46 lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite");
47 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
49 sound_manager->preload("sounds/willocatch.wav");
58 Lantern::updateColor(){
59 lightsprite->set_color(lightcolor);
60 //Turn lantern off if light is black
61 if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){
62 sprite->set_action("off");
64 sprite->set_action("normal");
65 sprite->set_color(lightcolor);
70 Lantern::draw(DrawingContext& context){
72 MovingSprite::draw(context);
74 context.push_target();
75 context.set_target(DrawingContext::LIGHTMAP);
77 lightsprite->draw(context, get_bbox().get_middle(), 0);
82 HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) {
84 WillOWisp* wow = dynamic_cast<WillOWisp*>(&other);
86 // collided with WillOWisp while grabbed and unlit
87 sound_manager->play("sounds/willocatch.wav");
88 lightcolor = Color(0,1,0);
92 TreeWillOWisp* twow = dynamic_cast<TreeWillOWisp*>(&other);
94 // collided with TreeWillOWisp while grabbed and unlit
95 sound_manager->play("sounds/willocatch.wav");
96 lightcolor = twow->get_color();
101 return Rock::collision(other, hit);
105 Lantern::grab(MovingObject& object, const Vector& pos, Direction dir)
107 Rock::grab(object, pos, dir);
109 // if lantern is not lit, draw it as opened
111 sprite->set_action("off-open");
117 Lantern::ungrab(MovingObject& object, Direction dir)
119 // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again
121 sprite->set_action("off");
124 Rock::ungrab(object, dir);
130 return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0);
133 IMPLEMENT_FACTORY(Lantern, "lantern");