(void) elapsed_time;
if(colorchange_timer.check()) {
- treecolor++;
- if(treecolor > 5)
- treecolor = 0;
+ treecolor = (treecolor + 1) % 3;
+ Color col;
switch(treecolor) {
- case 0: sprite->set_color(Color(1, 0, 0)); break;
- case 1: sprite->set_color(Color(0, 1, 0)); break;
- case 2: sprite->set_color(Color(0, 0, 1)); break;
- case 3: sprite->set_color(Color(1, 1, 0)); break;
- case 4: sprite->set_color(Color(1, 0, 1)); break;
- case 5: sprite->set_color(Color(0, 1, 1)); break;
+ case 0: col = Color(1, 0, 0); break;
+ case 1: col = Color(0, 1, 0); break;
+ case 2: col = Color(0, 0, 1); break;
+ case 3: col = Color(1, 1, 0); break;
+ case 4: col = Color(1, 0, 1); break;
+ case 5: col = Color(0, 1, 1); break;
default: assert(false);
}
+ sprite->set_color(col);
+ std::vector<TreeWillOWisp*>::iterator iter;
+ for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
+ TreeWillOWisp *willo = *iter;
+ if(willo->get_color() == col) {
+ willo->start_sucking();
+ }
+ }
}
if(willowisp_timer.check()) {
willo_speed = 1.8f;
}
- willo_color++;
- if(willo_color > 5)
- willo_color = 0;
+ do {
+ willo_color = (willo_color + 1) % 3;
+ } while(willo_color == treecolor);
+
switch(willo_color) {
case 0: willowisp->set_color(Color(1, 0, 0)); break;
case 1: willowisp->set_color(Color(0, 1, 0)); break;
willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp));
}
-void
-GhostTree::start_sucking()
-{
- /* TODO create a particle system to indicate the sucking... */
-}
-
IMPLEMENT_FACTORY(GhostTree, "ghosttree");
#include "object/lantern.hpp"
static const std::string SOUNDFILE = "sounds/willowisp.wav";
+static const float SUCKSPEED = 25;
TreeWillOWisp::TreeWillOWisp(GhostTree* tree, const Vector& pos,
float radius, float speed)
mystate = STATE_VANISHING;
sprite->set_action("vanishing", 1);
set_group(COLGROUP_DISABLED);
+}
- tree->willowisp_died(this);
+void
+TreeWillOWisp::start_sucking()
+{
+ mystate = STATE_SUCKED;
}
HitResponse
if (mystate == STATE_VANISHING) {
if(sprite->animation_done()) {
remove_me();
+ tree->willowisp_died(this);
+ }
+ return;
+ }
+
+ if (mystate == STATE_SUCKED) {
+ Vector dir = tree->get_bbox().get_middle() - get_pos();
+ if(dir.norm() < 5) {
+ vanish();
return;
}
+ Vector newpos = get_pos() + dir * elapsed_time;
+ movement = newpos - get_pos();
+ return;
}
angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));