This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-gunner/source/effects/Bullet.cpp

53 lines
1.2 KiB
C++
Raw Normal View History

/*
* Bullet.cpp
*
* Created on: 12.08.2012
* Author: Felix
*/
#include "Bullet.h"
#include "../abstract/Actor.h"
#include "../util/Log.h"
2012-09-11 17:20:17 +00:00
const Vector2i Bullet::SIZE = Vector2i(20, 20);
const float Bullet::SPEED = 500.0f;
/**
* Places a bullet in the world.
*
* @param position World position of the bullet.
* @param world Box2d world.
* @param texture Texture to display for bullet.
*/
Bullet::Bullet(const Vector2f& position, b2World& world,
2012-09-11 14:55:04 +00:00
const std::shared_ptr<sf::Texture>& texture, Physical& shooter, float direction, int damage) :
2012-09-11 17:20:17 +00:00
Particle(texture, PhysicalData(position, SIZE, world, CATEGORY_PARTICLE,
CATEGORY_PARTICLE, true, true)),
2012-09-11 14:55:04 +00:00
mShooter(shooter),
mDamage(damage) {
setSpeed(angle(direction), SPEED);
setAngle(direction);
}
/**
* @copydoc Physical::onCollide
*/
void
Bullet::onCollide(Physical& other, uint16 type) {
// Make sure we do not damage twice.
if (!getDelete()) {
// Call onShot on other, with damage as param.
if (type == CATEGORY_ACTOR) {
Actor& a = dynamic_cast<Actor&>(other);
2012-09-11 14:55:04 +00:00
a.onDamage(mDamage);
}
setDelete(true);
}
}
bool
Bullet::doesCollide(Physical& other) {
return &other != &mShooter;
}