Added rotating shield gadget.
This commit is contained in:
parent
16ad937c57
commit
f160cfb2f3
12 changed files with 117 additions and 11 deletions
BIN
resources/textures/shield.png
Normal file
BIN
resources/textures/shield.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 677 B |
3
resources/yaml/rotating_shield.yaml
Normal file
3
resources/yaml/rotating_shield.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
name: Shield
|
||||
texture: shield.png
|
||||
size: [75, 5]
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "generator/Generator.h"
|
||||
#include "items/Heal.h"
|
||||
#include "items/Shield.h"
|
||||
#include "sprites/Enemy.h"
|
||||
#include "sprites/Player.h"
|
||||
#include "util/Yaml.h"
|
||||
|
@ -33,7 +34,7 @@ Game::Game(tgui::Window& window) :
|
|||
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 Heal()));
|
||||
mPlayer->setRightGadget(std::shared_ptr<Gadget>(new Shield()));
|
||||
mWorld.insertCharacter(mPlayer);
|
||||
|
||||
mHealth = window.add<tgui::Label>();
|
||||
|
|
|
@ -156,7 +156,7 @@ World::raycast(const sf::Vector2f& lineStart,
|
|||
assert(lineStart != lineEnd);
|
||||
sf::Vector2f lineCenter = lineStart + 0.5f * (lineEnd - lineStart);
|
||||
for (const auto& it : mDrawables.at(Sprite::Category::CATEGORY_WORLD)) {
|
||||
if (dynamic_cast<Tile*>(it.get())->getType() != Tile::Type::WALL)
|
||||
if (!it->collisionEnabled(Sprite::CATEGORY_ACTOR))
|
||||
continue;
|
||||
sf::Vector2f axis = it->getPosition() - lineCenter;
|
||||
if (axis == sf::Vector2f())
|
||||
|
|
|
@ -68,6 +68,8 @@ private:
|
|||
void move();
|
||||
|
||||
private:
|
||||
friend class Shield;
|
||||
|
||||
/// Distance to a path point where it will be considered as reached (to
|
||||
/// avoid floating point equality check).
|
||||
static const float POINT_REACHED_DISTANCE;
|
||||
|
|
|
@ -56,7 +56,7 @@ Sprite::getSpeed() const {
|
|||
*/
|
||||
sf::Vector2f
|
||||
Sprite::getDirection() const {
|
||||
return thor::rotatedVector(sf::Vector2f(1, 0), mShape.getRotation());
|
||||
return thor::rotatedVector(sf::Vector2f(0, - 1), mShape.getRotation());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
36
source/items/Shield.cpp
Normal file
36
source/items/Shield.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Shield.cpp
|
||||
*
|
||||
* Created on: 06.07.2013
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#include "Shield.h"
|
||||
|
||||
#include "../abstract/Character.h"
|
||||
#include "../sprites/RotatingShield.h"
|
||||
#include "../World.h"
|
||||
|
||||
void
|
||||
Shield::onUse(Character& character) {
|
||||
mCharacter = &character;
|
||||
if (mRotatingShield)
|
||||
mRotatingShield->setDelete(true);
|
||||
sf::Vector2f offset = mCharacter->getDirection() * mCharacter->getRadius();
|
||||
mRotatingShield = std::shared_ptr<RotatingShield>(
|
||||
new RotatingShield(mCharacter->getPosition() + offset));
|
||||
mCharacter->mWorld.insert(mRotatingShield);
|
||||
}
|
||||
|
||||
void
|
||||
Shield::onThink(int elapsed) {
|
||||
if (mRotatingShield) {
|
||||
mRotatingShield->setDirection(mCharacter->getPosition() -
|
||||
mRotatingShield->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
sf::Time
|
||||
Shield::getCooldownTime() {
|
||||
return sf::seconds(10);
|
||||
}
|
27
source/items/Shield.h
Normal file
27
source/items/Shield.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Shield.h
|
||||
*
|
||||
* Created on: 06.07.2013
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#ifndef DG_SHIELD_H_
|
||||
#define DG_SHIELD_H_
|
||||
|
||||
#include "Gadget.h"
|
||||
|
||||
class RotatingShield;
|
||||
class Sprite;
|
||||
|
||||
class Shield : public Gadget {
|
||||
protected:
|
||||
void onUse(Character& character) override;
|
||||
void onThink(int elapsed) override;
|
||||
sf::Time getCooldownTime() override;
|
||||
|
||||
private:
|
||||
Character* mCharacter;
|
||||
std::shared_ptr<RotatingShield> mRotatingShield;
|
||||
};
|
||||
|
||||
#endif /* DG_SHIELD_H_ */
|
|
@ -148,18 +148,14 @@ Weapon::cancelReload() {
|
|||
*/
|
||||
void
|
||||
Weapon::insertProjectile(float angle) {
|
||||
// Minus to account for positive y-axis going downwards in SFML.
|
||||
sf::Vector2f offset(0, - mHolder.getRadius());
|
||||
thor::rotate(offset, thor::polarAngle(mHolder.getDirection()));
|
||||
sf::Vector2f offset(mHolder.getDirection() * mHolder.getRadius());
|
||||
|
||||
float spread = (mHolder.getSpeed() == sf::Vector2f())
|
||||
? mSpread
|
||||
: mSpreadMoving;
|
||||
std::uniform_real_distribution<float> distribution(- spread, spread);
|
||||
angle += distribution(mGenerator);
|
||||
angle += distribution(mGenerator) + 90.0f;
|
||||
|
||||
//float random = ((float) rand()) / (float) RAND_MAX;
|
||||
//angle += random * 2 * mSpread - mSpread;
|
||||
sf::Vector2f direction(thor::rotatedVector(mHolder.getDirection(), angle));
|
||||
|
||||
std::shared_ptr<Sprite> projectile(new Bullet(mHolder.getPosition() + offset,
|
||||
|
|
15
source/sprites/RotatingShield.cpp
Normal file
15
source/sprites/RotatingShield.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* RotatingShield.cpp
|
||||
*
|
||||
* Created on: 06.07.2013
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#include "RotatingShield.h"
|
||||
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
RotatingShield::RotatingShield(const sf::Vector2f& position) :
|
||||
Rectangle(position, CATEGORY_WORLD, MASK_ALL,
|
||||
Yaml("rotating_shield.yaml")) {
|
||||
}
|
25
source/sprites/RotatingShield.h
Normal file
25
source/sprites/RotatingShield.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* RotatingShield.h
|
||||
*
|
||||
* Created on: 06.07.2013
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#ifndef DG_ROTATINGSHIELD_H_
|
||||
#define DG_ROTATINGSHIELD_H_
|
||||
|
||||
#include "../abstract/Rectangle.h"
|
||||
|
||||
class RotatingShield : public Rectangle {
|
||||
public:
|
||||
explicit RotatingShield(const sf::Vector2f& position);
|
||||
|
||||
private:
|
||||
using Sprite::setDelete;
|
||||
using Sprite::setDirection;
|
||||
using Sprite::getPosition;
|
||||
|
||||
friend class Shield;
|
||||
};
|
||||
|
||||
#endif /* DG_ROTATINGSHIELD_H_ */
|
|
@ -50,7 +50,8 @@ Tile::isSolid(Type type) {
|
|||
switch (type) {
|
||||
case Type::FLOOR:
|
||||
return false;
|
||||
case Type::WALL: // falltrough
|
||||
case Type::WALL:
|
||||
// falltrough
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
|
Reference in a new issue