From e19e93b038e0feb50d7895371827b24e58de3edd Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Fri, 2 Jun 2006 23:42:27 +0000 Subject: [PATCH] SpriteParticle constructor now takes an AnchorPoint for positioning the sprite SVN-Revision: 3625 --- src/badguy/flyingsnowball.cpp | 2 +- src/object/sprite_particle.cpp | 5 ++++- src/object/sprite_particle.hpp | 3 ++- src/sprite/sprite.cpp | 6 ++++++ src/sprite/sprite.hpp | 3 +++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp index a36a998c1..4c3acdbe4 100644 --- a/src/badguy/flyingsnowball.cpp +++ b/src/badguy/flyingsnowball.cpp @@ -121,7 +121,7 @@ FlyingSnowBall::active_update(float elapsed_time) 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)); } } diff --git a/src/object/sprite_particle.cpp b/src/object/sprite_particle.cpp index a9341f49b..9faab9dda 100644 --- a/src/object/sprite_particle.cpp +++ b/src/object/sprite_particle.cpp @@ -23,13 +23,16 @@ #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() diff --git a/src/object/sprite_particle.hpp b/src/object/sprite_particle.hpp index 160cdc060..786b4a216 100644 --- a/src/object/sprite_particle.hpp +++ b/src/object/sprite_particle.hpp @@ -25,6 +25,7 @@ #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" @@ -32,7 +33,7 @@ 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); diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 43f582a16..7a32c3fee 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -166,6 +166,12 @@ Sprite::get_current_hitbox_height() const 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) { diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index b558cd1fc..df0f9c718 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -26,6 +26,7 @@ #include "video/surface.hpp" #include "math/vector.hpp" +#include "math/rect.hpp" #include "sprite_data.hpp" class DrawingContext; @@ -82,6 +83,8 @@ public: 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 -- 2.11.0