SpriteParticle constructor now takes an AnchorPoint for positioning the sprite
authorChristoph Sommer <mail@christoph-sommer.de>
Fri, 2 Jun 2006 23:42:27 +0000 (23:42 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Fri, 2 Jun 2006 23:42:27 +0000 (23:42 +0000)
SVN-Revision: 3625

src/badguy/flyingsnowball.cpp
src/object/sprite_particle.cpp
src/object/sprite_particle.hpp
src/sprite/sprite.cpp
src/sprite/sprite.hpp

index a36a998..4c3acdb 100644 (file)
@@ -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));
   }
 }
index a9341f4..9faab9d 100644 (file)
 #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() 
index 160cdc0..786b4a2 100644 (file)
@@ -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);
index 43f582a..7a32c3f 100644 (file)
@@ -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)
 {
index b558cd1..df0f9c7 100644 (file)
@@ -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