Fixed bullet collisions.

This commit is contained in:
Felix Ableitner 2013-03-03 21:28:12 +01:00
parent f51b8a1aaa
commit 9fd43d1d3a
2 changed files with 6 additions and 6 deletions

View file

@ -27,7 +27,7 @@ const float Bullet::DEFAULT_SPEED = 500;
*/ */
Bullet::Bullet(const sf::Vector2f& position, Sprite& shooter, float direction, Bullet::Bullet(const sf::Vector2f& position, Sprite& shooter, float direction,
const Yaml& config) : const Yaml& config) :
Particle(config, Data(position, 0, CATEGORY_PARTICLE, CATEGORY_PARTICLE)), Particle(config, Data(position, 0, CATEGORY_PARTICLE, ~CATEGORY_PARTICLE)),
mShooter(shooter), mShooter(shooter),
mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)), mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)),
mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) { mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) {
@ -41,13 +41,13 @@ Bullet::Bullet(const sf::Vector2f& position, Sprite& shooter, float direction,
* @copydoc Physical::onCollide * @copydoc Physical::onCollide
*/ */
void void
Bullet::onCollide(Sprite& other) { Bullet::onCollide(std::shared_ptr<Sprite> other) {
// Make sure we do not damage twice. // Make sure we do not damage twice.
if (!getDelete()) { if (!getDelete()) {
// Call onShot on other, with damage as param. // Call onShot on other, with damage as param.
if (other.getCategory() == CATEGORY_ACTOR) { if (other->getCategory() == CATEGORY_ACTOR) {
Character& a = dynamic_cast<Character&>(other); std::shared_ptr<Character> character = std::static_pointer_cast<Character>(other);
a.onDamage(mDamage); character->onDamage(mDamage);
} }
setDelete(true); setDelete(true);
} }

View file

@ -25,7 +25,7 @@ public:
Bullet(const sf::Vector2f& position, Sprite& shooter, float direction, Bullet(const sf::Vector2f& position, Sprite& shooter, float direction,
const Yaml& config); const Yaml& config);
void onCollide(Sprite& other); void onCollide(std::shared_ptr<Sprite> other);
// Private variables. // Private variables.
private: private: