void GhostTree::die() { mystate = STATE_DYING; sprite->set_action("dying", 1); glow_sprite->set_action("dying", 1); std::vector<TreeWillOWisp*>::iterator iter; for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) { TreeWillOWisp *willo = *iter; willo->vanish(); } }
HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { if (is_open()) { WillOWisp* wow = dynamic_cast<WillOWisp*>(&other); if (wow) { // collided with WillOWisp while grabbed and unlit SoundManager::current()->play("sounds/willocatch.wav"); lightcolor = Color(0,1,0); updateColor(); wow->vanish(); } TreeWillOWisp* twow = dynamic_cast<TreeWillOWisp*>(&other); if (twow) { // collided with TreeWillOWisp while grabbed and unlit SoundManager::current()->play("sounds/willocatch.wav"); lightcolor = twow->get_color(); updateColor(); twow->vanish(); } } return Rock::collision(other, hit); }
void GhostTree::active_update(float elapsed_time) { (void) elapsed_time; if (mystate == STATE_IDLE) { if(colorchange_timer.check()) { sound_manager->play("sounds/tree_howling.ogg", get_pos()); suck_timer.start(3); treecolor = (treecolor + 1) % 3; Color col; switch(treecolor) { 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); } glow_sprite->set_color(col); } if(suck_timer.check()) { Color col = glow_sprite->get_color(); sound_manager->play("sounds/tree_suck.ogg", get_pos()); std::vector<TreeWillOWisp*>::iterator iter; for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) { TreeWillOWisp *willo = *iter; if(willo->get_color() == col) { willo->start_sucking(get_bbox().get_middle() + SUCK_TARGET_OFFSET + Vector(systemRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD), systemRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD))); } } mystate = STATE_SUCKING; } if(willowisp_timer.check()) { if(willowisps.size() < WILLOWISP_COUNT) { Vector pos = Vector(bbox.get_width() / 2, bbox.get_height() / 2 + willo_spawn_y + WILLOWISP_TOP_OFFSET); TreeWillOWisp *willowisp = new TreeWillOWisp(this, pos, 200 + willo_radius, willo_speed); Sector::current()->add_object(willowisp); willowisps.push_back(willowisp); willo_spawn_y -= 40; if(willo_spawn_y < -160) willo_spawn_y = 0; willo_radius += 20; if(willo_radius > 120) willo_radius = 0; if(willo_speed == 1.8f) { willo_speed = 1.5f; } else { willo_speed = 1.8f; } 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; 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(); Root* root = new 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(); } } } } }