From 6034c8ffca02d76e6e705b407055e985b5cb1de0 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sat, 26 May 2007 16:40:12 +0000 Subject: [PATCH] first tries at sucking SVN-Revision: 5027 --- src/badguy/ghosttree.cpp | 38 ++++++++++++++++++++------------------ src/badguy/ghosttree.hpp | 3 +-- src/badguy/treewillowisp.cpp | 19 ++++++++++++++++++- src/badguy/treewillowisp.hpp | 3 ++- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 5fd1fcb69..917345b7f 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -51,19 +51,26 @@ GhostTree::active_update(float elapsed_time) (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::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()) { @@ -89,9 +96,10 @@ GhostTree::active_update(float elapsed_time) 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; @@ -118,11 +126,5 @@ GhostTree::willowisp_died(TreeWillOWisp *willowisp) 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"); diff --git a/src/badguy/ghosttree.hpp b/src/badguy/ghosttree.hpp index df077883a..109ba3d25 100644 --- a/src/badguy/ghosttree.hpp +++ b/src/badguy/ghosttree.hpp @@ -32,8 +32,7 @@ public: void activate(); void active_update(float elapsed_time); - void willowisp_died(TreeWillOWisp *willowisp); - void start_sucking(); + void willowisp_died(TreeWillOWisp* willowisp); private: Timer willowisp_timer; diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index c3d14e0e5..c143406e8 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -24,6 +24,7 @@ #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) @@ -62,8 +63,12 @@ TreeWillOWisp::vanish() mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); set_group(COLGROUP_DISABLED); +} - tree->willowisp_died(this); +void +TreeWillOWisp::start_sucking() +{ + mystate = STATE_SUCKED; } HitResponse @@ -91,8 +96,20 @@ TreeWillOWisp::active_update(float elapsed_time) 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)); diff --git a/src/badguy/treewillowisp.hpp b/src/badguy/treewillowisp.hpp index 66215ab9b..58805e4cb 100644 --- a/src/badguy/treewillowisp.hpp +++ b/src/badguy/treewillowisp.hpp @@ -37,6 +37,7 @@ public: * make TreeWillOWisp vanish */ void vanish(); + void start_sucking(); void active_update(float elapsed_time); void set_color(const Color& color); @@ -52,7 +53,7 @@ protected: private: enum MyState { - STATE_DEFAULT, STATE_VANISHING + STATE_DEFAULT, STATE_VANISHING, STATE_SUCKED }; MyState mystate; -- 2.11.0