#include <math.h>
+#include "audio/sound_manager.hpp"
#include "math/random_generator.hpp"
#include "object/player.hpp"
#include "object/sprite_particle.hpp"
#include "util/reader.hpp"
Firefly::Firefly(const Reader& lisp) :
- MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
+ MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
activated(false),
initial_position()
{
return;
}
//Replace sprite
- sprite = sprite_manager->create( sprite_name );
+ sprite = SpriteManager::current()->create( sprite_name );
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
reactivate();
+
+ //Load sound
+ if( sprite_name.find("vbell", 0) == std::string::npos ) {
+ SoundManager::current()->preload("sounds/savebell_low.wav");
+ }
+ else {
+ SoundManager::current()->preload("sounds/savebell2.wav");
+ }
}
void
HitResponse
Firefly::collision(GameObject& other, const CollisionHit& )
{
- if(activated)
+ // If the bell is already activated, don't ring it again!
+ if(activated || sprite->get_action() == "ringing")
return ABORT_MOVE;
Player* player = dynamic_cast<Player*> (&other);
// TODO: provide convenience function in MovingSprite or MovingObject?
for (int i = 0; i < 5; i++) {
Vector ppos = bbox.get_middle();
- float angle = systemRandom.randf(-M_PI_2, M_PI_2);
- float velocity = systemRandom.randf(450, 900);
+ float angle = graphicsRandom.randf(-M_PI_2, M_PI_2);
+ float velocity = graphicsRandom.randf(450, 900);
float vx = sin(angle)*velocity;
float vy = -cos(angle)*velocity;
Vector pspeed = Vector(vx, vy);
Vector paccel = Vector(0, 1000);
- Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
+ Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
}
- // TODO play sound
+
+ if( sprite_name.find("vbell", 0) == std::string::npos ) {
+ SoundManager::current()->play("sounds/savebell2.wav");
+ }
+ else {
+ SoundManager::current()->play("sounds/savebell_low.wav");
+ }
+
sprite->set_action("ringing");
GameSession::current()->set_reset_point(Sector::current()->get_name(),
initial_position);