- willo_color++;
- if(willo_color > 5)
- willo_color = 0;
- switch(willo_color) {
- case 0: willowisp->set_color(Color(1, 0, 0)); break;
- case 1: willowisp->set_color(Color(0, 1, 0)); break;
- case 2: willowisp->set_color(Color(0, 0, 1)); break;
- case 3: willowisp->set_color(Color(1, 1, 0)); break;
- case 4: willowisp->set_color(Color(1, 0, 1)); break;
- case 5: willowisp->set_color(Color(0, 1, 1)); break;
- default: assert(false);
+ if(root_timer.check()) {
+ /* TODO indicate root with an animation */
+ Player* player = get_nearest_player();
+ if (player) {
+ auto root = std::make_shared<Root>(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()+ROOT_TOP_OFFSET));
+ Sector::current()->add_object(root);
+ }
+ }
+ } else if (mystate == STATE_SWALLOWING) {
+ if (suck_lantern) {
+ // suck in lantern
+ assert (suck_lantern);
+ Vector pos = suck_lantern->get_pos();
+ Vector delta = get_bbox().get_middle() + SUCK_TARGET_OFFSET - pos;
+ Vector dir_ = delta.unit();
+ if (delta.norm() < 1) {
+ dir_ = delta;
+ suck_lantern->ungrab(*this, RIGHT);
+ suck_lantern->remove_me();
+ suck_lantern = 0;
+ sprite->set_action("swallow", 1);
+ } else {
+ pos += dir_;
+ suck_lantern->grab(*this, pos, RIGHT);
+ }
+ } else {
+ // wait until lantern is swallowed
+ if (sprite->animation_done()) {
+ if (is_color_deadly(suck_lantern_color)) {
+ die();
+ } else {
+ sprite->set_action("default");
+ mystate = STATE_IDLE;
+ spawn_lantern();
+ }