Pass bullet damage from weapon.

This commit is contained in:
Felix Ableitner 2012-09-11 16:55:04 +02:00
parent b0d2fe7a1f
commit 6ea371ee2e
3 changed files with 7 additions and 5 deletions

View file

@ -20,10 +20,11 @@ const float Bullet::SPEED = 500.0f;
* @param texture Texture to display for bullet.
*/
Bullet::Bullet(const Vector2f& position, b2World& world,
const std::shared_ptr<sf::Texture>& texture, Physical& shooter, float direction) :
const std::shared_ptr<sf::Texture>& texture, Physical& shooter, float direction, int damage) :
Particle(texture, PhysicalData(position, Vector2i(20, 20), world, CATEGORY_PARTICLE,
CATEGORY_PARTICLE, true, true)),
mShooter(shooter) {
mShooter(shooter),
mDamage(damage) {
setSpeed(angle(direction), SPEED);
setAngle(direction);
}
@ -38,7 +39,7 @@ Bullet::onCollide(Physical& other, uint16 type) {
// Call onShot on other, with damage as param.
if (type == CATEGORY_ACTOR) {
Actor& a = dynamic_cast<Actor&>(other);
a.onDamage(10);
a.onDamage(mDamage);
}
setDelete(true);
}

View file

@ -17,7 +17,7 @@ class Bullet : public Particle {
// Public functions.
public:
Bullet(const Vector2f& position, b2World& world, const std::shared_ptr<sf::Texture>& texture,
Physical& shooter, float direction);
Physical& shooter, float direction, int damage);
void onCollide(Physical& other, uint16 category);
bool doesCollide(Physical& other);
@ -26,6 +26,7 @@ public:
private:
static const float SPEED;
Physical& mShooter;
const int mDamage;
};
#endif /* DG_BULLET_H_ */

View file

@ -34,5 +34,5 @@ Weapon::fire() {
std::shared_ptr<Particle>
Weapon::createParticle() {
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition(), mWorld, mBulletTexture,
mHolder, mHolder.getAngle()));
mHolder, mHolder.getAngle(), 10));
}