From: Christoph Sommer Date: Sat, 26 May 2007 18:50:16 +0000 (+0000) Subject: some new GhostTree stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e4eade21a778b7042eccfac371f33fb257ec7105;p=supertux.git some new GhostTree stuff SVN-Revision: 5035 --- diff --git a/data/images/creatures/ghosttree/ghosttree-dying-0.png b/data/images/creatures/ghosttree/ghosttree-dying-0.png new file mode 100644 index 000000000..cc97d00f6 Binary files /dev/null and b/data/images/creatures/ghosttree/ghosttree-dying-0.png differ diff --git a/data/images/creatures/ghosttree/ghosttree-glow-dying-0.png b/data/images/creatures/ghosttree/ghosttree-glow-dying-0.png new file mode 100644 index 000000000..b0d8aaa66 Binary files /dev/null and b/data/images/creatures/ghosttree/ghosttree-glow-dying-0.png differ diff --git a/data/images/creatures/ghosttree/ghosttree-glow.png b/data/images/creatures/ghosttree/ghosttree-glow.png new file mode 100644 index 000000000..5b9ff86d3 Binary files /dev/null and b/data/images/creatures/ghosttree/ghosttree-glow.png differ diff --git a/data/images/creatures/ghosttree/ghosttree-glow.sprite b/data/images/creatures/ghosttree/ghosttree-glow.sprite new file mode 100644 index 000000000..0ec463471 --- /dev/null +++ b/data/images/creatures/ghosttree/ghosttree-glow.sprite @@ -0,0 +1,18 @@ +(supertux-sprite + (action + (name "default") + (images + "ghosttree-glow.png" + ) + ) + (action + (name "dying") + (fps 4) + (images + "ghosttree-glow-dying-0.png" + "ghosttree-glow-dying-0.png" + "ghosttree-glow-dying-0.png" + "ghosttree-glow-dying-0.png" + ) + ) +) diff --git a/data/images/creatures/ghosttree/ghosttree.sprite b/data/images/creatures/ghosttree/ghosttree.sprite index 7cb246426..fc57556b4 100644 --- a/data/images/creatures/ghosttree/ghosttree.sprite +++ b/data/images/creatures/ghosttree/ghosttree.sprite @@ -5,4 +5,14 @@ "ghosttree.png" ) ) + (action + (name "dying") + (fps 4) + (images + "ghosttree-dying-0.png" + "ghosttree-dying-0.png" + "ghosttree-dying-0.png" + "ghosttree-dying-0.png" + ) + ) ) diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 5fb5c492e..b916b577a 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -20,9 +20,14 @@ #include "ghosttree.hpp" #include "treewillowisp.hpp" +#include "sprite/sprite_manager.hpp" #include "root.hpp" +#include "random_generator.hpp" static const size_t WILLOWISP_COUNT = 10; +static const float ROOT_TOP_OFFSET = -64; +static const Vector SUCK_TARGET_OFFSET = Vector(-32,72); +static const float SUCK_TARGET_SPREAD = 16; GhostTree::GhostTree(const lisp::Lisp& lisp) : BadGuy(lisp, "images/creatures/ghosttree/ghosttree.sprite", @@ -30,6 +35,7 @@ GhostTree::GhostTree(const lisp::Lisp& lisp) willo_spawn_y(0), willo_radius(200), willo_speed(1.8f), willo_color(0), treecolor(0) { + glow_sprite.reset(sprite_manager->create("images/creatures/ghosttree/ghosttree-glow.sprite")); } GhostTree::~GhostTree() @@ -37,6 +43,19 @@ GhostTree::~GhostTree() } void +GhostTree::die() +{ + sprite->set_action("dying", 1); + glow_sprite->set_action("dying", 1); + + std::vector::iterator iter; + for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) { + TreeWillOWisp *willo = *iter; + willo->vanish(); + } +} + +void GhostTree::activate() { willowisp_timer.start(1.0f, true); @@ -65,17 +84,17 @@ GhostTree::active_update(float elapsed_time) case 5: col = Color(0, 1, 1); break; default: assert(false); } - sprite->set_color(col); + glow_sprite->set_color(col); } if(suck_timer.check()) { - Color col = sprite->get_color(); + Color col = glow_sprite->get_color(); sound_manager->play("sounds/tree_suck.ogg", get_pos()); std::vector::iterator iter; for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) { TreeWillOWisp *willo = *iter; if(willo->get_color() == col) { - willo->start_sucking(); + 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))); } } } @@ -122,7 +141,7 @@ GhostTree::active_update(float elapsed_time) 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()-64)); + Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()+ROOT_TOP_OFFSET)); Sector::current()->add_object(root); } } @@ -133,5 +152,17 @@ GhostTree::willowisp_died(TreeWillOWisp *willowisp) willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp)); } +void +GhostTree::draw(DrawingContext& context) +{ + BadGuy::draw(context); + + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + glow_sprite->draw(context, get_pos(), layer); + context.pop_target(); +} + + IMPLEMENT_FACTORY(GhostTree, "ghosttree"); diff --git a/src/badguy/ghosttree.hpp b/src/badguy/ghosttree.hpp index d451c389d..c17792bb2 100644 --- a/src/badguy/ghosttree.hpp +++ b/src/badguy/ghosttree.hpp @@ -33,6 +33,9 @@ public: void activate(); void active_update(float elapsed_time); void willowisp_died(TreeWillOWisp* willowisp); + virtual void draw(DrawingContext& context); + + void die(); private: Timer willowisp_timer; @@ -41,6 +44,7 @@ private: float willo_speed; int willo_color; + std::auto_ptr glow_sprite; Timer colorchange_timer; Timer suck_timer; Timer root_timer; diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index c143406e8..36d798e78 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -66,9 +66,10 @@ TreeWillOWisp::vanish() } void -TreeWillOWisp::start_sucking() +TreeWillOWisp::start_sucking(Vector suck_target) { mystate = STATE_SUCKED; + this->suck_target = suck_target; } HitResponse @@ -102,7 +103,7 @@ TreeWillOWisp::active_update(float elapsed_time) } if (mystate == STATE_SUCKED) { - Vector dir = tree->get_bbox().get_middle() - get_pos(); + Vector dir = suck_target - get_pos(); if(dir.norm() < 5) { vanish(); return; diff --git a/src/badguy/treewillowisp.hpp b/src/badguy/treewillowisp.hpp index 58805e4cb..60fac85ba 100644 --- a/src/badguy/treewillowisp.hpp +++ b/src/badguy/treewillowisp.hpp @@ -37,7 +37,7 @@ public: * make TreeWillOWisp vanish */ void vanish(); - void start_sucking(); + void start_sucking(Vector suck_target); void active_update(float elapsed_time); void set_color(const Color& color); @@ -65,6 +65,8 @@ private: std::auto_ptr sound_source; Vector treepos_delta; GhostTree* tree; + + Vector suck_target; }; #endif