#include <lantern.hpp>
Inherits Rock.
Public Member Functions | |
Lantern (const Vector &pos) | |
Lantern (const Reader &reader) | |
void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
~Lantern () | |
HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
void | grab (MovingObject &object, const Vector &pos, Direction dir) |
called each frame when the object has been grabbed. | |
void | ungrab (MovingObject &object, Direction dir) |
bool | is_open () |
returns true if lamp is currently open | |
Color | get_color () const |
returns the lamp's color | |
Private Member Functions | |
void | updateColor () |
Lantern (const Lantern &) | |
Lantern & | operator= (const Lantern &) |
Private Attributes | |
Color | lightcolor |
SpritePtr | lightsprite |
A portable Light Source.
Definition at line 25 of file lantern.hpp.
Lantern::Lantern | ( | const Vector & | pos | ) |
Definition at line 42 of file lantern.cpp.
References SpriteManager::create(), GL_ONE, GL_SRC_ALPHA, lightsprite, SoundManager::preload(), sound_manager, sprite_manager, and updateColor().
00042 : 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 }
Lantern::Lantern | ( | const Reader & | reader | ) |
Definition at line 27 of file lantern.cpp.
References SpriteManager::create(), lisp::Lisp::get(), GL_ONE, GL_SRC_ALPHA, lightcolor, lightsprite, SoundManager::preload(), sound_manager, sprite_manager, and updateColor().
00027 : 00028 Rock(reader, "images/objects/lantern/lantern.sprite"), 00029 lightcolor(1.0f, 1.0f, 1.0f), 00030 lightsprite() 00031 { 00032 //get color from lisp 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 }
Lantern::~Lantern | ( | ) |
Lantern::Lantern | ( | const Lantern & | ) | [private] |
void Lantern::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Reimplemented from MovingSprite.
Definition at line 70 of file lantern.cpp.
References MovingSprite::draw(), MovingObject::get_bbox(), DrawingContext::LIGHTMAP, lightsprite, DrawingContext::pop_target(), DrawingContext::push_target(), and DrawingContext::set_target().
00070 { 00071 //Draw the Sprite. 00072 MovingSprite::draw(context); 00073 //Let there be light. 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 }
HitResponse Lantern::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Reimplemented from Rock.
Definition at line 82 of file lantern.cpp.
References Rock::collision(), TreeWillOWisp::get_color(), is_open(), lightcolor, SoundManager::play(), sound_manager, updateColor(), TreeWillOWisp::vanish(), and WillOWisp::vanish().
00082 { 00083 if (is_open()) { 00084 WillOWisp* wow = dynamic_cast<WillOWisp*>(&other); 00085 if (wow) { 00086 // collided with WillOWisp while grabbed and unlit 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 // collided with TreeWillOWisp while grabbed and unlit 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 }
void Lantern::grab | ( | MovingObject & | object, | |
const Vector & | pos, | |||
Direction | dir | |||
) | [virtual] |
called each frame when the object has been grabbed.
Reimplemented from Rock.
Definition at line 105 of file lantern.cpp.
References Rock::grab(), is_open(), and MovingSprite::sprite.
Referenced by GhostTree::collision().
00106 { 00107 Rock::grab(object, pos, dir); 00108 00109 // if lantern is not lit, draw it as opened 00110 if (is_open()) { 00111 sprite->set_action("off-open"); 00112 } 00113 00114 }
void Lantern::ungrab | ( | MovingObject & | object, | |
Direction | dir | |||
) | [virtual] |
Reimplemented from Rock.
Definition at line 117 of file lantern.cpp.
References is_open(), MovingSprite::sprite, and Rock::ungrab().
00118 { 00119 // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again 00120 if (is_open()) { 00121 sprite->set_action("off"); 00122 } 00123 00124 Rock::ungrab(object, dir); 00125 }
bool Lantern::is_open | ( | ) |
returns true if lamp is currently open
Definition at line 128 of file lantern.cpp.
References Color::blue, Rock::grabbed, Color::green, lightcolor, and Color::red.
Referenced by WillOWisp::collides(), TreeWillOWisp::collides(), collision(), grab(), and ungrab().
00129 { 00130 return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0); 00131 }
Color Lantern::get_color | ( | ) | const [inline] |
returns the lamp's color
Definition at line 46 of file lantern.hpp.
References lightcolor.
Referenced by GhostTree::collision().
00046 { 00047 return lightcolor; 00048 }
void Lantern::updateColor | ( | ) | [private] |
Definition at line 58 of file lantern.cpp.
References Color::blue, Color::green, lightcolor, lightsprite, Color::red, and MovingSprite::sprite.
Referenced by collision(), and Lantern().
00058 { 00059 lightsprite->set_color(lightcolor); 00060 //Turn lantern off if light is black 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 }
Color Lantern::lightcolor [private] |
Definition at line 51 of file lantern.hpp.
Referenced by collision(), get_color(), is_open(), Lantern(), and updateColor().
SpritePtr Lantern::lightsprite [private] |