00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "object/lantern.hpp"
00018
00019 #include "audio/sound_manager.hpp"
00020 #include "badguy/treewillowisp.hpp"
00021 #include "badguy/willowisp.hpp"
00022 #include "sprite/sprite.hpp"
00023 #include "sprite/sprite_manager.hpp"
00024 #include "supertux/object_factory.hpp"
00025 #include "util/reader.hpp"
00026
00027 Lantern::Lantern(const Reader& reader) :
00028 Rock(reader, "images/objects/lantern/lantern.sprite"),
00029 lightcolor(1.0f, 1.0f, 1.0f),
00030 lightsprite()
00031 {
00032
00033 std::vector<float> vColor;
00034 reader.get("color", vColor);
00035 lightcolor = Color(vColor);
00036 lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite");
00037 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
00038 updateColor();
00039 sound_manager->preload("sounds/willocatch.wav");
00040 }
00041
00042 Lantern::Lantern(const Vector& pos) :
00043 Rock(pos, "images/objects/lantern/lantern.sprite"),
00044 lightcolor(0.0f, 0.0f, 0.0f),
00045 lightsprite()
00046 {
00047 lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite");
00048 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
00049 updateColor();
00050 sound_manager->preload("sounds/willocatch.wav");
00051 }
00052
00053 Lantern::~Lantern()
00054 {
00055 }
00056
00057 void
00058 Lantern::updateColor(){
00059 lightsprite->set_color(lightcolor);
00060
00061 if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){
00062 sprite->set_action("off");
00063 } else {
00064 sprite->set_action("normal");
00065 sprite->set_color(lightcolor);
00066 }
00067 }
00068
00069 void
00070 Lantern::draw(DrawingContext& context){
00071
00072 MovingSprite::draw(context);
00073
00074 context.push_target();
00075 context.set_target(DrawingContext::LIGHTMAP);
00076
00077 lightsprite->draw(context, get_bbox().get_middle(), 0);
00078
00079 context.pop_target();
00080 }
00081
00082 HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) {
00083 if (is_open()) {
00084 WillOWisp* wow = dynamic_cast<WillOWisp*>(&other);
00085 if (wow) {
00086
00087 sound_manager->play("sounds/willocatch.wav");
00088 lightcolor = Color(0,1,0);
00089 updateColor();
00090 wow->vanish();
00091 }
00092 TreeWillOWisp* twow = dynamic_cast<TreeWillOWisp*>(&other);
00093 if (twow) {
00094
00095 sound_manager->play("sounds/willocatch.wav");
00096 lightcolor = twow->get_color();
00097 updateColor();
00098 twow->vanish();
00099 }
00100 }
00101 return Rock::collision(other, hit);
00102 }
00103
00104 void
00105 Lantern::grab(MovingObject& object, const Vector& pos, Direction dir)
00106 {
00107 Rock::grab(object, pos, dir);
00108
00109
00110 if (is_open()) {
00111 sprite->set_action("off-open");
00112 }
00113
00114 }
00115
00116 void
00117 Lantern::ungrab(MovingObject& object, Direction dir)
00118 {
00119
00120 if (is_open()) {
00121 sprite->set_action("off");
00122 }
00123
00124 Rock::ungrab(object, dir);
00125 }
00126
00127 bool
00128 Lantern::is_open()
00129 {
00130 return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0);
00131 }
00132
00133