From ecd50c335ca7dd467d97bdb6f234fda6681e43ee Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sat, 26 May 2007 15:41:46 +0000 Subject: [PATCH] willowisp position relative to ghosttree now, ghosttree is notified from vanished willos SVN-Revision: 5025 --- src/badguy/ghosttree.cpp | 19 +++++++++---------- src/badguy/ghosttree.hpp | 8 ++++++-- src/badguy/root.cpp | 2 -- src/badguy/treewillowisp.cpp | 22 +++++++++++++++------- src/badguy/treewillowisp.hpp | 6 +++++- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 56ca1b39e..5fd1fcb69 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -22,13 +22,13 @@ #include "treewillowisp.hpp" #include "root.hpp" -static const int WILLOWISP_COUNT = 10; +static const size_t WILLOWISP_COUNT = 10; GhostTree::GhostTree(const lisp::Lisp& lisp) : BadGuy(lisp, "images/creatures/ghosttree/ghosttree.sprite", LAYER_OBJECTS - 10), - willowisp_counter(0), willo_spawn_y(0), willo_radius(200), - willo_speed(1.8f), willo_color(0), treecolor(0) + willo_spawn_y(0), willo_radius(200), willo_speed(1.8f), willo_color(0), + treecolor(0) { } @@ -67,14 +67,13 @@ GhostTree::active_update(float elapsed_time) } if(willowisp_timer.check()) { - if(willowisp_counter < WILLOWISP_COUNT) { - Vector pos = get_bbox().get_middle(); - pos.y += willo_spawn_y; + if(willowisps.size() < WILLOWISP_COUNT) { + Vector pos = Vector(bbox.get_width() / 2, bbox.get_height() / 2 + willo_spawn_y); TreeWillOWisp *willowisp - = new TreeWillOWisp(pos, 200 + willo_radius, willo_speed); + = new TreeWillOWisp(this, pos, 200 + willo_radius, willo_speed); Sector::current()->add_object(willowisp); - willowisp_counter++; + willowisps.push_back(willowisp); willo_spawn_y -= 40; if(willo_spawn_y < -160) @@ -114,9 +113,9 @@ GhostTree::active_update(float elapsed_time) } void -GhostTree::willowisp_died() +GhostTree::willowisp_died(TreeWillOWisp *willowisp) { - willowisp_counter--; + willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp)); } void diff --git a/src/badguy/ghosttree.hpp b/src/badguy/ghosttree.hpp index c52b6a0a3..df077883a 100644 --- a/src/badguy/ghosttree.hpp +++ b/src/badguy/ghosttree.hpp @@ -19,8 +19,11 @@ #ifndef __GHOSTTREE_H__ #define __GHOSTTREE_H__ +#include #include "badguy.hpp" +class TreeWillOWisp; + class GhostTree : public BadGuy { public: @@ -29,11 +32,10 @@ public: void activate(); void active_update(float elapsed_time); - void willowisp_died(); + void willowisp_died(TreeWillOWisp *willowisp); void start_sucking(); private: - int willowisp_counter; Timer willowisp_timer; float willo_spawn_y; float willo_radius; @@ -43,6 +45,8 @@ private: Timer colorchange_timer; Timer root_timer; int treecolor; + + std::vector willowisps; }; #endif diff --git a/src/badguy/root.cpp b/src/badguy/root.cpp index 77a220af5..4b94051fd 100644 --- a/src/badguy/root.cpp +++ b/src/badguy/root.cpp @@ -38,7 +38,6 @@ void Root::activate() { set_pos(start_position + Vector(0, ypos)); - std::cout << "SetPos: " << get_pos() << "\n"; } void @@ -53,6 +52,5 @@ Root::active_update(float elapsed_time) remove_me(); } set_pos(start_position + Vector(0, ypos)); - std::cout << "SetPos: " << get_pos() << "\n"; } diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index 9ec089705..c3d14e0e5 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -20,19 +20,23 @@ #include #include "treewillowisp.hpp" +#include "ghosttree.hpp" #include "object/lantern.hpp" static const std::string SOUNDFILE = "sounds/willowisp.wav"; -TreeWillOWisp::TreeWillOWisp(const Vector& pos, float radius, float speed) - : BadGuy(pos, "images/creatures/willowisp/willowisp.sprite", - LAYER_OBJECTS - 20), mystate(STATE_DEFAULT) +TreeWillOWisp::TreeWillOWisp(GhostTree* tree, const Vector& pos, + float radius, float speed) + : BadGuy(Vector(0, 0), "images/creatures/willowisp/willowisp.sprite", + LAYER_OBJECTS - 20), mystate(STATE_DEFAULT), tree(tree) { + treepos_delta = pos; sound_manager->preload(SOUNDFILE); this->radius = radius; this->angle = 0; this->speed = speed; + start_position = tree->get_pos() + treepos_delta; } TreeWillOWisp::~TreeWillOWisp() @@ -58,6 +62,8 @@ TreeWillOWisp::vanish() mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); set_group(COLGROUP_DISABLED); + + tree->willowisp_died(this); } HitResponse @@ -70,15 +76,17 @@ TreeWillOWisp::collision_player(Player& player, const CollisionHit& hit) bool TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) { Lantern* lantern = dynamic_cast(&other); - if (lantern && lantern->is_open()) return true; - if (dynamic_cast(&other)) return true; + if (lantern && lantern->is_open()) + return true; + if (dynamic_cast(&other)) + return true; + return false; } void TreeWillOWisp::active_update(float elapsed_time) { - // remove TreeWillOWisp if it has completely vanished if (mystate == STATE_VANISHING) { if(sprite->animation_done()) { @@ -88,7 +96,7 @@ TreeWillOWisp::active_update(float elapsed_time) } angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI)); - Vector newpos(start_position.x + sin(angle) * radius, start_position.y); + Vector newpos(tree->get_pos() + treepos_delta + Vector(sin(angle) * radius, 0)); movement = newpos - get_pos(); float sizemod = cos(angle) * 0.8f; /* TODO: modify sprite size */ diff --git a/src/badguy/treewillowisp.hpp b/src/badguy/treewillowisp.hpp index 49b8d076a..66215ab9b 100644 --- a/src/badguy/treewillowisp.hpp +++ b/src/badguy/treewillowisp.hpp @@ -23,10 +23,12 @@ #include "badguy.hpp" +class GhostTree; + class TreeWillOWisp : public BadGuy { public: - TreeWillOWisp(const Vector& pos, float radius, float speed); + TreeWillOWisp(GhostTree* tree, const Vector& pos, float radius, float speed); virtual ~TreeWillOWisp(); void activate(); @@ -60,6 +62,8 @@ private: float speed; std::auto_ptr sound_source; + Vector treepos_delta; + GhostTree* tree; }; #endif -- 2.11.0