Added Ring of Fire gadget.

This commit is contained in:
Felix Ableitner 2013-08-30 15:33:23 +02:00
parent 624ce8daaa
commit 55fbf1be20
4 changed files with 95 additions and 8 deletions

View file

@ -11,7 +11,7 @@
#include "generator/Generator.h"
#include "sprites/items/Heal.h"
#include "sprites/items/Shield.h"
#include "sprites/items/RingOfFire.h"
#include "sprites/Enemy.h"
#include "sprites/Player.h"
#include "util/Loader.h"
@ -58,8 +58,8 @@ Game::Game(tgui::Window& window) :
void Game::initPlayer() {
mPlayer = std::shared_ptr<Player>(new Player(mWorld, mPathfinder,
mGenerator.getPlayerSpawn()));
mPlayer->setLeftGadget(std::shared_ptr < Gadget > (new Heal()));
mPlayer->setRightGadget(std::shared_ptr < Gadget > (new Shield()));
mPlayer->setLeftGadget(std::shared_ptr<Gadget>(new Heal()));
mPlayer->setRightGadget(std::shared_ptr<Gadget>(new RingOfFire(mWorld)));
mWorld.insertCharacter(mPlayer);
}

View file

@ -10,6 +10,7 @@
#include <Thor/Vectors.hpp>
#include "items/Heal.h"
#include "items/RingOfFire.h"
#include "items/Shield.h"
#include "items/Weapon.h"
#include "../util/Yaml.h"
@ -36,14 +37,15 @@ Enemy::Enemy(World& world, Pathfinder& pathfinder,
// Select secondary weapon.
switch (std::uniform_int_distribution<int>(0, 1)(generator)) {
case 0: setSecondWeapon(Weapon::getWeapon(world, *this, Weapon::WeaponType::PISTOL));
case 1: setSecondWeapon(Weapon::getWeapon(world, *this, Weapon::WeaponType::KNIFE));
case 0: setSecondWeapon(Weapon::getWeapon(world, *this, Weapon::WeaponType::PISTOL)); break;
case 1: setSecondWeapon(Weapon::getWeapon(world, *this, Weapon::WeaponType::KNIFE)); break;
}
// Select gadget.
switch (std::uniform_int_distribution<int>(0, 1)(generator)) {
case 0: setLeftGadget(std::shared_ptr<Gadget>(new Heal()));
case 1: setLeftGadget(std::shared_ptr<Gadget>(new Shield()));
switch (std::uniform_int_distribution<int>(0, 2)(generator)) {
case 0: setLeftGadget(std::shared_ptr<Gadget>(new Heal())); break;
case 1: setLeftGadget(std::shared_ptr<Gadget>(new Shield())); break;
case 2: setLeftGadget(std::shared_ptr<Gadget>(new RingOfFire(world))); break;
}
}

View file

@ -0,0 +1,48 @@
/*
* RingOfFire.cpp
*
* Created on: 29.08.2013
* Author: Felix
*/
#include "RingOfFire.h"
#include <Thor/Vectors.hpp>
#include "../effects/Bullet.h"
#include "../../World.h"
RingOfFire::RingOfFire(World& world) :
Gadget("Ring of Fire"),
mWorld(world),
mBullet("bullet.yaml") {
}
void
RingOfFire::onUse(Character& character) {
mCharacter = &character;
mCurrentWave = 0;
}
void
RingOfFire::onThink(int elapsed) {
if (mCurrentWave < WAVES_PER_USE && mTimer.isExpired()) {
for (int angle = mCurrentWave * 10; angle <= 360; angle += 30) {
Vector2f direction(thor::rotatedVector(mCharacter->getDirection(), (float) angle) *
mCharacter->getRadius());
std::shared_ptr<Sprite> projectile(new Bullet(mCharacter->getPosition() + direction,
*mCharacter, direction, mBullet, 200, 20, 0));
mWorld.insert(projectile);
}
mTimer.restart(sf::milliseconds(500));
mCurrentWave++;
}
}
sf::Time
RingOfFire::getCooldownTime() {
return sf::seconds(5);
}

View file

@ -0,0 +1,37 @@
/*
* RingOfFire.h
*
* Created on: 29.08.2013
* Author: Felix
*/
#ifndef DG_RINGOFFIRE_H_
#define DG_RINGOFFIRE_H_
#include "Gadget.h"
#include "../abstract/Character.h"
#include "../../util/Yaml.h"
/**
* Gadget that fires bullets in all directions for multiple waves.
*/
class RingOfFire : public Gadget {
public:
RingOfFire(World& world);
protected:
void onUse(Character& character) override;
void onThink(int elapsed) override;
sf::Time getCooldownTime() override;
private:
static const int WAVES_PER_USE = 3;
int mCurrentWave = WAVES_PER_USE + 1;
Character* mCharacter;
thor::Timer mTimer;
World& mWorld;
const Yaml mBullet;
};
#endif /* DG_RINGOFFIRE_H_ */