2012-09-09 20:50:15 +00:00
|
|
|
/*
|
|
|
|
* Bullet.cpp
|
|
|
|
*
|
|
|
|
* Created on: 12.08.2012
|
|
|
|
* Author: Felix
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Bullet.h"
|
2012-09-12 12:21:57 +00:00
|
|
|
|
2012-10-01 09:02:44 +00:00
|
|
|
#include "../abstract/Character.h"
|
2012-10-12 17:22:53 +00:00
|
|
|
#include "../util/Loader.h"
|
|
|
|
#include "../util/ResourceManager.h"
|
2012-09-09 20:50:15 +00:00
|
|
|
|
2012-10-12 17:22:53 +00:00
|
|
|
const String Bullet::KEY_DAMAGE = "damage";
|
|
|
|
const String Bullet::KEY_SPEED = "speed";
|
2012-09-09 20:50:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Places a bullet in the world.
|
|
|
|
*
|
|
|
|
* @param position World position of the bullet.
|
|
|
|
* @param world Box2d world.
|
|
|
|
* @param texture Texture to display for bullet.
|
|
|
|
*/
|
2012-10-12 17:22:53 +00:00
|
|
|
Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction,
|
|
|
|
const Yaml& config) :
|
2012-10-13 10:48:16 +00:00
|
|
|
Particle(config, PhysicalData(position, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
|
|
|
|
true, true, true)),
|
2012-09-11 14:55:04 +00:00
|
|
|
mShooter(shooter),
|
2012-10-12 17:22:53 +00:00
|
|
|
mDamage(config.get<int>(KEY_DAMAGE)),
|
|
|
|
mSpeed(config.get<int>(KEY_SPEED)) {
|
|
|
|
setSpeed(angle(direction), mSpeed);
|
2012-09-09 20:50:15 +00:00
|
|
|
setAngle(direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copydoc Physical::onCollide
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Bullet::onCollide(Physical& other, uint16 type) {
|
|
|
|
// Make sure we do not damage twice.
|
|
|
|
if (!getDelete()) {
|
2012-09-12 12:21:57 +00:00
|
|
|
// Call onShot on other, with damage as param.
|
2012-09-11 14:48:28 +00:00
|
|
|
if (type == CATEGORY_ACTOR) {
|
2012-10-01 09:02:44 +00:00
|
|
|
Character& a = dynamic_cast<Character&>(other);
|
2012-09-11 14:55:04 +00:00
|
|
|
a.onDamage(mDamage);
|
2012-09-12 12:21:57 +00:00
|
|
|
}
|
2012-09-09 20:50:15 +00:00
|
|
|
setDelete(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Bullet::doesCollide(Physical& other) {
|
|
|
|
return &other != &mShooter;
|
|
|
|
}
|