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/items/Weapon.cpp
2012-10-04 19:10:12 +02:00

51 lines
1.2 KiB
C++
Executable file

/*
* Weapon.cpp
*
* Created on: 12.08.2012
* Author: Felix
*/
#include "Weapon.h"
#include <algorithm>
#include <thor/Vectors.hpp>
#include "../util/Collection.h"
#include "../effects/Bullet.h"
#include "../util/Loader.h"
#include "../util/ResourceManager.h"
const int Weapon::BULLET_DAMAGE = 10;
Weapon::Weapon(const Instances& instances, Physical& holder, const Vector2i& holderSize) :
Emitter(instances.collection),
mHolder(holder),
mBulletTexture(ResourceManager::i()
.acquire(Loader::i().fromFile<sf::Texture>("bullet.png"))),
mWorld(instances.world),
mOffset(0, std::max(holderSize.x, holderSize.y) / 2 +
b2_linearSlop +
std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2) {
}
Weapon::~Weapon() {
}
/**
* Call on any button press/refire.
*/
void
Weapon::fire() {
// Only call if has ammo, consider firing rate etc.
emit();
}
std::shared_ptr<Particle>
Weapon::createParticle() {
// Minus to account for positive y-axis going downwards in SFML.
Vector2f offset(- mOffset);
thor::rotate(offset, mHolder.getAngle());
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition() + offset,
mWorld, mBulletTexture, mHolder, mHolder.getAngle(), BULLET_DAMAGE));
}