Pass bullet damage from weapon.
This commit is contained in:
parent
b0d2fe7a1f
commit
6ea371ee2e
3 changed files with 7 additions and 5 deletions
|
@ -20,10 +20,11 @@ const float Bullet::SPEED = 500.0f;
|
||||||
* @param texture Texture to display for bullet.
|
* @param texture Texture to display for bullet.
|
||||||
*/
|
*/
|
||||||
Bullet::Bullet(const Vector2f& position, b2World& world,
|
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,
|
Particle(texture, PhysicalData(position, Vector2i(20, 20), world, CATEGORY_PARTICLE,
|
||||||
CATEGORY_PARTICLE, true, true)),
|
CATEGORY_PARTICLE, true, true)),
|
||||||
mShooter(shooter) {
|
mShooter(shooter),
|
||||||
|
mDamage(damage) {
|
||||||
setSpeed(angle(direction), SPEED);
|
setSpeed(angle(direction), SPEED);
|
||||||
setAngle(direction);
|
setAngle(direction);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +39,7 @@ Bullet::onCollide(Physical& other, uint16 type) {
|
||||||
// Call onShot on other, with damage as param.
|
// Call onShot on other, with damage as param.
|
||||||
if (type == CATEGORY_ACTOR) {
|
if (type == CATEGORY_ACTOR) {
|
||||||
Actor& a = dynamic_cast<Actor&>(other);
|
Actor& a = dynamic_cast<Actor&>(other);
|
||||||
a.onDamage(10);
|
a.onDamage(mDamage);
|
||||||
}
|
}
|
||||||
setDelete(true);
|
setDelete(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Bullet : public Particle {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Bullet(const Vector2f& position, b2World& world, const std::shared_ptr<sf::Texture>& texture,
|
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);
|
void onCollide(Physical& other, uint16 category);
|
||||||
bool doesCollide(Physical& other);
|
bool doesCollide(Physical& other);
|
||||||
|
@ -26,6 +26,7 @@ public:
|
||||||
private:
|
private:
|
||||||
static const float SPEED;
|
static const float SPEED;
|
||||||
Physical& mShooter;
|
Physical& mShooter;
|
||||||
|
const int mDamage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DG_BULLET_H_ */
|
#endif /* DG_BULLET_H_ */
|
||||||
|
|
|
@ -34,5 +34,5 @@ Weapon::fire() {
|
||||||
std::shared_ptr<Particle>
|
std::shared_ptr<Particle>
|
||||||
Weapon::createParticle() {
|
Weapon::createParticle() {
|
||||||
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition(), mWorld, mBulletTexture,
|
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition(), mWorld, mBulletTexture,
|
||||||
mHolder, mHolder.getAngle()));
|
mHolder, mHolder.getAngle(), 10));
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue