3 // SuperTux - Boss "GhostTree"
4 // Copyright (C) 2007 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "ghosttree.hpp"
22 #include "treewillowisp.hpp"
25 static const size_t WILLOWISP_COUNT = 10;
27 GhostTree::GhostTree(const lisp::Lisp& lisp)
28 : BadGuy(lisp, "images/creatures/ghosttree/ghosttree.sprite",
30 willo_spawn_y(0), willo_radius(200), willo_speed(1.8f), willo_color(0),
35 GhostTree::~GhostTree()
42 willowisp_timer.start(1.0f, true);
43 colorchange_timer.start(13, true);
44 root_timer.start(5, true);
45 set_group(COLGROUP_DISABLED);
49 GhostTree::active_update(float elapsed_time)
53 if(colorchange_timer.check()) {
54 sound_manager->play("sounds/tree_howling.ogg", get_pos());
56 treecolor = (treecolor + 1) % 3;
60 case 0: col = Color(1, 0, 0); break;
61 case 1: col = Color(0, 1, 0); break;
62 case 2: col = Color(0, 0, 1); break;
63 case 3: col = Color(1, 1, 0); break;
64 case 4: col = Color(1, 0, 1); break;
65 case 5: col = Color(0, 1, 1); break;
66 default: assert(false);
68 sprite->set_color(col);
71 if(suck_timer.check()) {
72 Color col = sprite->get_color();
73 sound_manager->play("sounds/tree_suck.ogg", get_pos());
74 std::vector<TreeWillOWisp*>::iterator iter;
75 for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
76 TreeWillOWisp *willo = *iter;
77 if(willo->get_color() == col) {
78 willo->start_sucking();
83 if(willowisp_timer.check()) {
84 if(willowisps.size() < WILLOWISP_COUNT) {
85 Vector pos = Vector(bbox.get_width() / 2, bbox.get_height() / 2 + willo_spawn_y);
86 TreeWillOWisp *willowisp
87 = new TreeWillOWisp(this, pos, 200 + willo_radius, willo_speed);
89 Sector::current()->add_object(willowisp);
90 willowisps.push_back(willowisp);
93 if(willo_spawn_y < -160)
97 if(willo_radius > 120)
100 if(willo_speed == 1.8f) {
107 willo_color = (willo_color + 1) % 3;
108 } while(willo_color == treecolor);
110 switch(willo_color) {
111 case 0: willowisp->set_color(Color(1, 0, 0)); break;
112 case 1: willowisp->set_color(Color(0, 1, 0)); break;
113 case 2: willowisp->set_color(Color(0, 0, 1)); break;
114 case 3: willowisp->set_color(Color(1, 1, 0)); break;
115 case 4: willowisp->set_color(Color(1, 0, 1)); break;
116 case 5: willowisp->set_color(Color(0, 1, 1)); break;
117 default: assert(false);
122 if(root_timer.check()) {
123 /* TODO indicate root with an animation */
124 Player* player = get_nearest_player();
125 Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()));
126 Sector::current()->add_object(root);
131 GhostTree::willowisp_died(TreeWillOWisp *willowisp)
133 willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp));
136 IMPLEMENT_FACTORY(GhostTree, "ghosttree");