Vector ppos = bbox.get_middle();
Vector pspeed = Vector(systemRandom.randf(-10, 10), 150);
Vector paccel = Vector(0,0);
- Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", ppos, pspeed, paccel, LAYER_OBJECTS-1));
+ Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));
}
}
#include "sector.hpp"
#include "camera.hpp"
#include "main.hpp"
+#include "log.hpp"
-SpriteParticle::SpriteParticle(std::string sprite_name, Vector position, Vector velocity, Vector acceleration, int drawing_layer)
+SpriteParticle::SpriteParticle(std::string sprite_name, Vector position, AnchorPoint anchor, Vector velocity, Vector acceleration, int drawing_layer)
: position(position), velocity(velocity), acceleration(acceleration), drawing_layer(drawing_layer)
{
sprite = sprite_manager->create(sprite_name);
if (!sprite) throw std::runtime_error("Could not load sprite "+sprite_name);
sprite->set_animation_loops(1);
+
+ this->position -= get_anchor_pos(sprite->get_current_hitbox(), anchor);
}
SpriteParticle::~SpriteParticle()
#include "game_object.hpp"
#include "resources.hpp"
#include "player.hpp"
+#include "object/anchor_point.hpp"
#include "sprite/sprite.hpp"
#include "sprite/sprite_manager.hpp"
#include "video/drawing_context.hpp"
class SpriteParticle : public GameObject
{
public:
- SpriteParticle(std::string sprite_name, Vector position, Vector velocity, Vector acceleration, int drawing_layer = LAYER_OBJECTS-1);
+ SpriteParticle(std::string sprite_name, Vector position, AnchorPoint anchor, Vector velocity, Vector acceleration, int drawing_layer = LAYER_OBJECTS-1);
~SpriteParticle();
protected:
virtual void hit(Player& player);
return action->hitbox_h;
}
+Rect
+Sprite::get_current_hitbox() const
+{
+ return Rect(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
+}
+
void
Sprite::set_fps(float new_fps)
{
#include "video/surface.hpp"
#include "math/vector.hpp"
+#include "math/rect.hpp"
#include "sprite_data.hpp"
class DrawingContext;
float get_current_hitbox_width() const;
/** return height of current action's hitbox */
float get_current_hitbox_height() const;
+ /** return current action's hitbox, relative to 0,0 */
+ Rect get_current_hitbox() const;
/** Get current frame */
int get_frame() const