#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)
{
}
}
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)
}
void
-GhostTree::willowisp_died()
+GhostTree::willowisp_died(TreeWillOWisp *willowisp)
{
- willowisp_counter--;
+ willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp));
}
void
#ifndef __GHOSTTREE_H__
#define __GHOSTTREE_H__
+#include <vector>
#include "badguy.hpp"
+class TreeWillOWisp;
+
class GhostTree : public BadGuy
{
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;
Timer colorchange_timer;
Timer root_timer;
int treecolor;
+
+ std::vector<TreeWillOWisp*> willowisps;
};
#endif
Root::activate()
{
set_pos(start_position + Vector(0, ypos));
- std::cout << "SetPos: " << get_pos() << "\n";
}
void
remove_me();
}
set_pos(start_position + Vector(0, ypos));
- std::cout << "SetPos: " << get_pos() << "\n";
}
#include <config.h>
#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()
mystate = STATE_VANISHING;
sprite->set_action("vanishing", 1);
set_group(COLGROUP_DISABLED);
+
+ tree->willowisp_died(this);
}
HitResponse
bool
TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) {
Lantern* lantern = dynamic_cast<Lantern*>(&other);
- if (lantern && lantern->is_open()) return true;
- if (dynamic_cast<Player*>(&other)) return true;
+ if (lantern && lantern->is_open())
+ return true;
+ if (dynamic_cast<Player*>(&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()) {
}
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 */
#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();
float speed;
std::auto_ptr<SoundSource> sound_source;
+ Vector treepos_delta;
+ GhostTree* tree;
};
#endif