#include <treewillowisp.hpp>
Inherits BadGuy.
Public Member Functions | |
TreeWillOWisp (GhostTree *tree, const Vector &pos, float radius, float speed) | |
virtual | ~TreeWillOWisp () |
void | activate () |
called when the badguy has been activated. | |
void | vanish () |
make TreeWillOWisp vanish | |
void | start_sucking (Vector suck_target) |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
void | set_color (const Color &color) |
Color | get_color () const |
virtual bool | is_flammable () const |
Returns whether to call ignite() when a badguy gets hit by a fire bullet. | |
virtual bool | is_freezable () const |
virtual void | kill_fall () |
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down). | |
virtual void | draw (DrawingContext &context) |
Called when the badguy is drawn. | |
Public Attributes | |
bool | was_sucked |
Protected Member Functions | |
virtual bool | collides (GameObject &other, const CollisionHit &hit) |
when 2 objects collided, we will first call the pre_collision_check functions of both objects that can decide on how to react to the collision. | |
HitResponse | collision_player (Player &player, const CollisionHit &hit) |
Called when the badguy collided with a player. | |
Private Types | |
enum | MyState { STATE_DEFAULT, STATE_VANISHING, STATE_SUCKED } |
Private Member Functions | |
TreeWillOWisp (const TreeWillOWisp &) | |
TreeWillOWisp & | operator= (const TreeWillOWisp &) |
Private Attributes | |
MyState | mystate |
Color | color |
float | angle |
float | radius |
float | speed |
std::auto_ptr< SoundSource > | sound_source |
GhostTree * | tree |
Vector | suck_target |
Definition at line 25 of file treewillowisp.hpp.
enum TreeWillOWisp::MyState [private] |
Definition at line 54 of file treewillowisp.hpp.
00054 { 00055 STATE_DEFAULT, STATE_VANISHING, STATE_SUCKED 00056 };
Definition at line 31 of file treewillowisp.cpp.
References angle, COLGROUP_MOVING, SoundManager::preload(), BadGuy::set_colgroup_active(), sound_manager, and TREEWILLOSOUND.
00032 : 00033 BadGuy(tree->get_pos() + pos, "images/creatures/willowisp/willowisp.sprite", 00034 LAYER_OBJECTS - 20), 00035 was_sucked(false), 00036 mystate(STATE_DEFAULT), 00037 color(), 00038 angle(), 00039 radius(), 00040 speed(), 00041 sound_source(), 00042 tree(tree), 00043 suck_target() 00044 { 00045 sound_manager->preload(TREEWILLOSOUND); 00046 00047 this->radius = radius; 00048 this->angle = 0; 00049 this->speed = speed; 00050 00051 set_colgroup_active(COLGROUP_MOVING); 00052 }
TreeWillOWisp::~TreeWillOWisp | ( | ) | [virtual] |
TreeWillOWisp::TreeWillOWisp | ( | const TreeWillOWisp & | ) | [private] |
void TreeWillOWisp::activate | ( | ) | [virtual] |
called when the badguy has been activated.
(As a side effect the dir variable might have been changed so that it faces towards the player.
Reimplemented from BadGuy.
Definition at line 59 of file treewillowisp.cpp.
References SoundManager::create_sound_source(), MovingObject::get_pos(), sound_manager, sound_source, and TREEWILLOSOUND.
00060 { 00061 sound_source.reset(sound_manager->create_sound_source(TREEWILLOSOUND)); 00062 sound_source->set_position(get_pos()); 00063 sound_source->set_looping(true); 00064 sound_source->set_gain(2.0); 00065 sound_source->set_reference_distance(32); 00066 sound_source->play(); 00067 }
void TreeWillOWisp::vanish | ( | ) |
make TreeWillOWisp vanish
Definition at line 70 of file treewillowisp.cpp.
References COLGROUP_DISABLED, mystate, BadGuy::set_colgroup_active(), MovingSprite::sprite, and STATE_VANISHING.
Referenced by active_update(), Lantern::collision(), and kill_fall().
00071 { 00072 mystate = STATE_VANISHING; 00073 sprite->set_action("vanishing", 1); 00074 set_colgroup_active(COLGROUP_DISABLED); 00075 }
void TreeWillOWisp::start_sucking | ( | Vector | suck_target | ) |
Definition at line 78 of file treewillowisp.cpp.
References mystate, STATE_SUCKED, suck_target, and was_sucked.
00079 { 00080 mystate = STATE_SUCKED; 00081 this->suck_target = suck_target; 00082 was_sucked = true; 00083 }
void TreeWillOWisp::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from BadGuy.
Definition at line 117 of file treewillowisp.cpp.
References angle, BadGuy::dir, MovingObject::get_pos(), MovingSprite::layer, LAYER_OBJECTS, MovingObject::movement, mystate, radius, GameObject::remove_me(), sound_source, speed, MovingSprite::sprite, BadGuy::start_position, STATE_SUCKED, STATE_VANISHING, suck_target, tree, vanish(), and GhostTree::willowisp_died().
00118 { 00119 // remove TreeWillOWisp if it has completely vanished 00120 if (mystate == STATE_VANISHING) { 00121 if(sprite->animation_done()) { 00122 remove_me(); 00123 tree->willowisp_died(this); 00124 } 00125 return; 00126 } 00127 00128 if (mystate == STATE_SUCKED) { 00129 Vector dir = suck_target - get_pos(); 00130 if(dir.norm() < 5) { 00131 vanish(); 00132 return; 00133 } 00134 Vector newpos = get_pos() + dir * elapsed_time; 00135 movement = newpos - get_pos(); 00136 return; 00137 } 00138 00139 angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI)); 00140 Vector newpos(start_position + Vector(sin(angle) * radius, 0)); 00141 movement = newpos - get_pos(); 00142 float sizemod = cos(angle) * 0.8f; 00143 /* TODO: modify sprite size */ 00144 00145 sound_source->set_position(get_pos()); 00146 00147 if(sizemod < 0) { 00148 layer = LAYER_OBJECTS + 5; 00149 } else { 00150 layer = LAYER_OBJECTS - 20; 00151 } 00152 }
void TreeWillOWisp::set_color | ( | const Color & | color | ) |
Definition at line 155 of file treewillowisp.cpp.
References color, and MovingSprite::sprite.
Referenced by GhostTree::active_update().
Color TreeWillOWisp::get_color | ( | ) | const |
Definition at line 162 of file treewillowisp.cpp.
References color.
Referenced by Lantern::collision().
00163 { 00164 return color; 00165 }
virtual bool TreeWillOWisp::is_flammable | ( | ) | const [inline, virtual] |
Returns whether to call ignite() when a badguy gets hit by a fire bullet.
Reimplemented from BadGuy.
Definition at line 43 of file treewillowisp.hpp.
virtual bool TreeWillOWisp::is_freezable | ( | ) | const [inline, virtual] |
virtual void TreeWillOWisp::kill_fall | ( | ) | [inline, virtual] |
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).
Reimplemented from BadGuy.
Definition at line 45 of file treewillowisp.hpp.
References vanish().
00045 { vanish(); }
void TreeWillOWisp::draw | ( | DrawingContext & | context | ) | [virtual] |
Called when the badguy is drawn.
The default implementation simply draws the badguy sprite on screen
Reimplemented from BadGuy.
Definition at line 104 of file treewillowisp.cpp.
References MovingObject::get_pos(), MovingSprite::layer, DrawingContext::LIGHTMAP, DrawingContext::pop_target(), DrawingContext::push_target(), DrawingContext::set_target(), and MovingSprite::sprite.
00105 { 00106 sprite->draw(context, get_pos(), layer); 00107 00108 context.push_target(); 00109 context.set_target(DrawingContext::LIGHTMAP); 00110 00111 sprite->draw(context, get_pos(), layer); 00112 00113 context.pop_target(); 00114 }
bool TreeWillOWisp::collides | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [protected, virtual] |
when 2 objects collided, we will first call the pre_collision_check functions of both objects that can decide on how to react to the collision.
Reimplemented from MovingObject.
Definition at line 93 of file treewillowisp.cpp.
References Lantern::is_open().
00093 { 00094 Lantern* lantern = dynamic_cast<Lantern*>(&other); 00095 if (lantern && lantern->is_open()) 00096 return true; 00097 if (dynamic_cast<Player*>(&other)) 00098 return true; 00099 00100 return false; 00101 }
HitResponse TreeWillOWisp::collision_player | ( | Player & | player, | |
const CollisionHit & | hit | |||
) | [protected, virtual] |
Called when the badguy collided with a player.
Reimplemented from BadGuy.
Definition at line 86 of file treewillowisp.cpp.
References BadGuy::collision_player().
00087 { 00088 //TODO: basically a no-op. Remove if this doesn't change. 00089 return BadGuy::collision_player(player, hit); 00090 }
TreeWillOWisp& TreeWillOWisp::operator= | ( | const TreeWillOWisp & | ) | [private] |
Definition at line 59 of file treewillowisp.hpp.
Referenced by start_sucking(), and GhostTree::willowisp_died().
MyState TreeWillOWisp::mystate [private] |
Definition at line 62 of file treewillowisp.hpp.
Referenced by active_update(), start_sucking(), and vanish().
Color TreeWillOWisp::color [private] |
float TreeWillOWisp::angle [private] |
Definition at line 65 of file treewillowisp.hpp.
Referenced by active_update(), and TreeWillOWisp().
float TreeWillOWisp::radius [private] |
float TreeWillOWisp::speed [private] |
std::auto_ptr<SoundSource> TreeWillOWisp::sound_source [private] |
GhostTree* TreeWillOWisp::tree [private] |
Vector TreeWillOWisp::suck_target [private] |
Definition at line 72 of file treewillowisp.hpp.
Referenced by active_update(), and start_sucking().