Removed string/vector typedefs.
This commit is contained in:
parent
a157f0857d
commit
7c4eb47f2e
27 changed files with 125 additions and 203 deletions
|
@ -7,11 +7,12 @@
|
|||
|
||||
#include "Game.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Thor/Graphics.hpp>
|
||||
|
||||
#include "abstract/Character.h"
|
||||
#include "sprites/Enemy.h"
|
||||
#include "types/String.h"
|
||||
#include "util/Loader.h"
|
||||
#include "util/ResourceManager.h"
|
||||
|
||||
|
@ -23,7 +24,7 @@ const int Game::FPS_GOAL = 60;
|
|||
*/
|
||||
Game::Game(sf::RenderWindow& window) :
|
||||
mWindow(window),
|
||||
mView(Vector2f(0, 0), mWindow.getView().getSize()),
|
||||
mView(sf::Vector2f(0, 0), mWindow.getView().getSize()),
|
||||
mTileManager(mWorld),
|
||||
mQuit(false),
|
||||
mPaused(false) {
|
||||
|
@ -50,10 +51,10 @@ Game::generate() {
|
|||
mTileManager.setTile(TileManager::TilePosition(x, 4), TileManager::Type::WALL);
|
||||
|
||||
mWorld.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, mPathfinder,
|
||||
Vector2f(400.0f, 200.0f), Yaml("enemy.yaml"))));
|
||||
sf::Vector2f(400.0f, 200.0f), Yaml("enemy.yaml"))));
|
||||
|
||||
mPlayer = std::shared_ptr<Player>(new Player(mWorld, mPathfinder,
|
||||
Vector2f(200.0f, 100.0f), Yaml("player.yaml")));
|
||||
sf::Vector2f(200.0f, 100.0f), Yaml("player.yaml")));
|
||||
mWorld.insert(mPlayer);
|
||||
}
|
||||
/**
|
||||
|
@ -172,7 +173,7 @@ Game::keyDown(const sf::Event& event) {
|
|||
*/
|
||||
sf::Vector2<float>
|
||||
Game::convertCoordinates(int x, int y) {
|
||||
return mWindow.convertCoords(Vector2i(x, y), mView);
|
||||
return mWindow.convertCoords(sf::Vector2i(x, y), mView);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#ifndef DG_GAME_H_
|
||||
#define DG_GAME_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
@ -15,7 +17,6 @@
|
|||
|
||||
#include "sprites/TileManager.h"
|
||||
#include "sprites/Player.h"
|
||||
#include "types/String.h"
|
||||
#include "World.h"
|
||||
#include "util/Pathfinder.h"
|
||||
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
|
||||
#include <Thor/Vectors.hpp>
|
||||
|
||||
const String Body::KEY_SIZE = "size";
|
||||
const Vector2i Body::DEFAULT_SIZE = Vector2i(50, 50);
|
||||
const std::string Body::KEY_SIZE = "size";
|
||||
const sf::Vector2i Body::DEFAULT_SIZE = sf::Vector2i(50, 50);
|
||||
|
||||
/**
|
||||
* Initializes Box2D body.
|
||||
*
|
||||
* @param data Data needed for construction.
|
||||
*/
|
||||
Body::Body(const Data& data, const Yaml& config, const Vector2i& pSize) :
|
||||
Body::Body(const Data& data, const Yaml& config, const sf::Vector2i& pSize) :
|
||||
mPosition(data.position),
|
||||
mSize(config.get(KEY_SIZE, DEFAULT_SIZE)),
|
||||
mAngle(0),
|
||||
|
@ -37,7 +37,7 @@ Body::~Body() {
|
|||
/**
|
||||
* Initializes container.
|
||||
*/
|
||||
Body::Data::Data(const Vector2f& position, float angle,
|
||||
Body::Data::Data(const sf::Vector2f& position, float angle,
|
||||
Category category, unsigned short maskExclude) :
|
||||
position(position),
|
||||
angle(angle),
|
||||
|
@ -48,7 +48,7 @@ Body::Data::Data(const Vector2f& position, float angle,
|
|||
/**
|
||||
* Returns the position of the sprite (center).
|
||||
*/
|
||||
Vector2f
|
||||
sf::Vector2f
|
||||
Body::getPosition() const {
|
||||
return mPosition;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ Body::getPosition() const {
|
|||
/**
|
||||
* Returns the movement speed of the body.
|
||||
*/
|
||||
Vector2f
|
||||
sf::Vector2f
|
||||
Body::getSpeed() const {
|
||||
return mSpeed;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ Body::getCategory() const {
|
|||
/**
|
||||
* Returns the size of the body as a vector.
|
||||
*/
|
||||
Vector2i
|
||||
sf::Vector2i
|
||||
Body::getSize() const {
|
||||
return mSize;
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ Body::setDelete(bool value) {
|
|||
* @param speed The value of the movement speed to be used.
|
||||
*/
|
||||
void
|
||||
Body::setSpeed(Vector2f direction, float speed) {
|
||||
if (direction != Vector2f()) {
|
||||
Body::setSpeed(sf::Vector2f direction, float speed) {
|
||||
if (direction != sf::Vector2f()) {
|
||||
thor::setLength(direction, speed);
|
||||
}
|
||||
mSpeed = direction;
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#ifndef DG_BODY_H_
|
||||
#define DG_BODY_H_
|
||||
|
||||
#include "../types/String.h"
|
||||
#include "../types/Vector.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
class Yaml;
|
||||
|
@ -42,8 +40,8 @@ public:
|
|||
class Data {
|
||||
public:
|
||||
Data() = default;
|
||||
Data(const Vector2f& position, float angle, Category category, unsigned short maskExclude);
|
||||
const Vector2f& position;
|
||||
Data(const sf::Vector2f& position, float angle, Category category, unsigned short maskExclude);
|
||||
const sf::Vector2f& position;
|
||||
float angle;
|
||||
Category category;
|
||||
unsigned short mask;
|
||||
|
@ -59,35 +57,35 @@ public:
|
|||
|
||||
// Public functions.
|
||||
public:
|
||||
Body(const Data& data, const Yaml& config, const Vector2i& pSize = Vector2i());
|
||||
Body(const Data& data, const Yaml& config, const sf::Vector2i& pSize = sf::Vector2i());
|
||||
virtual ~Body() = 0;
|
||||
|
||||
Vector2f getPosition() const;
|
||||
Vector2f getSpeed() const;
|
||||
sf::Vector2f getPosition() const;
|
||||
sf::Vector2f getSpeed() const;
|
||||
float getAngle() const;
|
||||
bool getDelete() const;
|
||||
Category getCategory() const;
|
||||
Vector2i getSize() const;
|
||||
sf::Vector2i getSize() const;
|
||||
|
||||
virtual bool doesCollide(Body& other);
|
||||
virtual void onCollide(Body& other, Category category);
|
||||
|
||||
// Public variables.
|
||||
public:
|
||||
static const String KEY_SIZE;
|
||||
static const Vector2i DEFAULT_SIZE;
|
||||
static const std::string KEY_SIZE;
|
||||
static const sf::Vector2i DEFAULT_SIZE;
|
||||
|
||||
// Protected functions.
|
||||
protected:
|
||||
void setDelete(bool value);
|
||||
void setSpeed(Vector2f direction, float speed);
|
||||
void setSpeed(sf::Vector2f direction, float speed);
|
||||
void setAngle(float angle);
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
Vector2f mPosition;
|
||||
Vector2i mSize;
|
||||
Vector2f mSpeed;
|
||||
sf::Vector2f mPosition;
|
||||
sf::Vector2i mSize;
|
||||
sf::Vector2f mSpeed;
|
||||
float mAngle;
|
||||
Category mCategory;
|
||||
unsigned short mMask;
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
#include "../sprites/Corpse.h"
|
||||
#include "../util/Log.h"
|
||||
|
||||
const String Character::KEY_HEALTH = "health";
|
||||
const std::string Character::KEY_HEALTH = "health";
|
||||
const int Character::DEFAULT_HEALTH = 100;
|
||||
const String Character::KEY_SPEED = "speed";
|
||||
const std::string Character::KEY_SPEED = "speed";
|
||||
const float Character::DEFAULT_SPEED = 100;
|
||||
const float Character::POINT_REACHED_DISTANCE = 1.0f;
|
||||
std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>();
|
||||
|
@ -116,7 +116,7 @@ Character::fire() {
|
|||
* @return True if a path was found.
|
||||
*/
|
||||
bool
|
||||
Character::setDestination(const Vector2f& destination) {
|
||||
Character::setDestination(const sf::Vector2f& destination) {
|
||||
mPath = mPathfinder.getPath(*this, destination);
|
||||
// Make sure we found a path.
|
||||
if (mPath.empty()) {
|
||||
|
@ -146,7 +146,7 @@ Character::move() {
|
|||
}
|
||||
else {
|
||||
LOG_I("Reached destination.");
|
||||
setSpeed(Vector2f(), 0);
|
||||
setSpeed(sf::Vector2f(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
#ifndef DG_ACTOR_H_
|
||||
#define DG_ACTOR_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Sprite.h"
|
||||
#include "../World.h"
|
||||
#include "../items/Weapon.h"
|
||||
#include "../types/String.h"
|
||||
#include "../util/Pathfinder.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
|
@ -44,14 +44,14 @@ protected:
|
|||
virtual void onDeath();
|
||||
float getMovementSpeed() const;
|
||||
void fire();
|
||||
bool setDestination(const Vector2f& destination);
|
||||
bool setDestination(const sf::Vector2f& destination);
|
||||
void move();
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static const String KEY_HEALTH;
|
||||
static const std::string KEY_HEALTH;
|
||||
static const int DEFAULT_HEALTH;
|
||||
static const String KEY_SPEED;
|
||||
static const std::string KEY_SPEED;
|
||||
static const float DEFAULT_SPEED;
|
||||
/// The distance to a point where it is considered reached.
|
||||
static const float POINT_REACHED_DISTANCE;
|
||||
|
@ -65,7 +65,7 @@ private:
|
|||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
||||
const float mMovementSpeed;
|
||||
Weapon mWeapon;
|
||||
std::vector<Vector2f> mPath; //< Contains nodes to reach a set destination.
|
||||
std::vector<sf::Vector2f> mPath; //< Contains nodes to reach a set destination.
|
||||
bool mStartPathfinding; //< True if a movement destination was just set.
|
||||
};
|
||||
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
#include "../util/ResourceManager.h"
|
||||
#include "../util/Log.h"
|
||||
|
||||
const String Sprite::KEY_TEXTURE = "texture";
|
||||
const String Sprite::DEFAULT_TEXTURE = "";
|
||||
const std::string Sprite::KEY_TEXTURE = "texture";
|
||||
const std::string Sprite::DEFAULT_TEXTURE = "";
|
||||
|
||||
/**
|
||||
* Loads sprite from ResourceManager, sets world position.
|
||||
*
|
||||
* @param texturePath Relative path to the texture file in the resource folder.
|
||||
*/
|
||||
Sprite::Sprite(const Yaml& config, const Data& data, const Vector2i& size) :
|
||||
Sprite::Sprite(const Yaml& config, const Data& data, const sf::Vector2i& size) :
|
||||
Body(data, config, size),
|
||||
mSize(Vector2i(getSize())) {
|
||||
String texture = config.get(KEY_TEXTURE, DEFAULT_TEXTURE);
|
||||
mSize(sf::Vector2i(getSize())) {
|
||||
std::string texture = config.get(KEY_TEXTURE, DEFAULT_TEXTURE);
|
||||
if (texture == "") {
|
||||
LOG_E("Failed to read texture from YAML file " << config.getFilename());
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ Sprite::~Sprite() {
|
|||
void
|
||||
Sprite::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
// Create a temporary shape to apply box2d body transformations to.
|
||||
sf::RectangleShape shape = sf::RectangleShape(Vector2f(mSize));
|
||||
sf::RectangleShape shape = sf::RectangleShape(sf::Vector2f(mSize));
|
||||
shape.setTexture(&*mTexture, true);
|
||||
shape.setOrigin(Vector2f(mSize.x / 2, mSize.y / 2));
|
||||
shape.setTextureRect(sf::IntRect(Vector2i(0, 0), mSize));
|
||||
shape.setOrigin(sf::Vector2f(mSize.x / 2, mSize.y / 2));
|
||||
shape.setTextureRect(sf::IntRect(sf::Vector2i(0, 0), mSize));
|
||||
|
||||
shape.setPosition(getPosition());
|
||||
shape.setRotation(getAngle());
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
#include <Thor/Resources.hpp>
|
||||
|
||||
#include "Body.h"
|
||||
#include "../types/String.h"
|
||||
#include "../types/Vector.h"
|
||||
#include <string>
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
class Body;
|
||||
|
@ -28,7 +27,7 @@ class Yaml;
|
|||
class Sprite : public sf::Drawable, public Body {
|
||||
// Public functions.
|
||||
public:
|
||||
Sprite(const Yaml& config, const Data& data, const Vector2i& size = Vector2i());
|
||||
Sprite(const Yaml& config, const Data& data, const sf::Vector2i& size = sf::Vector2i());
|
||||
Sprite(const std::shared_ptr<sf::Texture>& texture, const Data& data);
|
||||
virtual ~Sprite() = 0;
|
||||
|
||||
|
@ -38,11 +37,11 @@ protected:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
static const String KEY_TEXTURE;
|
||||
static const String DEFAULT_TEXTURE;
|
||||
static const std::string KEY_TEXTURE;
|
||||
static const std::string DEFAULT_TEXTURE;
|
||||
|
||||
std::shared_ptr<sf::Texture> mTexture;
|
||||
Vector2i mSize;
|
||||
sf::Vector2i mSize;
|
||||
};
|
||||
|
||||
#endif /* DG_SPRITE_H_ */
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
#include "../util/Loader.h"
|
||||
#include "../util/ResourceManager.h"
|
||||
|
||||
const String Bullet::KEY_DAMAGE = "damage";
|
||||
const std::string Bullet::KEY_DAMAGE = "damage";
|
||||
const int Bullet::DEFAULT_DAMAGE = 10;
|
||||
const String Bullet::KEY_SPEED = "speed";
|
||||
const std::string Bullet::KEY_SPEED = "speed";
|
||||
const float Bullet::DEFAULT_SPEED = 500;
|
||||
|
||||
/**
|
||||
|
@ -25,13 +25,13 @@ const float Bullet::DEFAULT_SPEED = 500;
|
|||
* @param world Box2d world.
|
||||
* @param texture Texture to display for bullet.
|
||||
*/
|
||||
Bullet::Bullet(const Vector2f& position, Body& shooter, float direction,
|
||||
Bullet::Bullet(const sf::Vector2f& position, Body& shooter, float direction,
|
||||
const Yaml& config) :
|
||||
Particle(config, Data(position, 0, CATEGORY_PARTICLE, CATEGORY_PARTICLE)),
|
||||
mShooter(shooter),
|
||||
mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)),
|
||||
mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) {
|
||||
Vector2f dir(1.0f, 0);
|
||||
sf::Vector2f dir(1.0f, 0);
|
||||
thor::setPolarAngle(dir, direction);
|
||||
setSpeed(dir, mSpeed);
|
||||
setAngle(direction);
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
#ifndef DG_BULLET_H_
|
||||
#define DG_BULLET_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../particle/Particle.h"
|
||||
#include "../types/String.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
class Particle;
|
||||
|
@ -21,7 +22,7 @@ class Yaml;
|
|||
class Bullet : public Particle {
|
||||
// Public functions.
|
||||
public:
|
||||
Bullet(const Vector2f& position, Body& shooter, float direction,
|
||||
Bullet(const sf::Vector2f& position, Body& shooter, float direction,
|
||||
const Yaml& config);
|
||||
|
||||
void onCollide(Body& other, Category category);
|
||||
|
@ -29,9 +30,9 @@ public:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
static const String KEY_DAMAGE;
|
||||
static const std::string KEY_DAMAGE;
|
||||
static const int DEFAULT_DAMAGE;
|
||||
static const String KEY_SPEED;
|
||||
static const std::string KEY_SPEED;
|
||||
static const float DEFAULT_SPEED;
|
||||
|
||||
Body& mShooter;
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
#include "../World.h"
|
||||
#include "../effects/Bullet.h"
|
||||
|
||||
const String Weapon::KEY_BULLET = "bullet";
|
||||
const String Weapon::DEFAULT_BULLET = "bullet.yaml";
|
||||
const String Weapon::KEY_INTERVAL = "interval";
|
||||
const std::string Weapon::KEY_BULLET = "bullet";
|
||||
const std::string Weapon::DEFAULT_BULLET = "bullet.yaml";
|
||||
const std::string Weapon::KEY_INTERVAL = "interval";
|
||||
const int Weapon::DEFAULT_INTERVAL = 250;
|
||||
|
||||
Weapon::Weapon(World& world, Body& holder, const Yaml& config) :
|
||||
|
@ -25,10 +25,10 @@ Weapon::Weapon(World& world, Body& holder, const Yaml& config) :
|
|||
mHolder(holder),
|
||||
mBullet(config.get(KEY_BULLET, DEFAULT_BULLET)),
|
||||
mTimer(sf::milliseconds(config.get(KEY_INTERVAL, DEFAULT_INTERVAL))) {
|
||||
Vector2i holderSize = mHolder.getSize();
|
||||
sf::Vector2i holderSize = mHolder.getSize();
|
||||
Yaml bullet(mBullet);
|
||||
Vector2i bulletSize = bullet.get(Body::KEY_SIZE, Vector2i());
|
||||
mOffset = Vector2f(0,
|
||||
sf::Vector2i bulletSize = bullet.get(Body::KEY_SIZE, sf::Vector2i());
|
||||
mOffset = sf::Vector2f(0,
|
||||
std::max(holderSize.x, holderSize.y) / 2 +
|
||||
std::max(bulletSize.x, bulletSize.y) / 2);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ Weapon::fire() {
|
|||
std::shared_ptr<Particle>
|
||||
Weapon::createParticle() {
|
||||
// Minus to account for positive y-axis going downwards in SFML.
|
||||
Vector2f offset(- mOffset);
|
||||
sf::Vector2f offset(- mOffset);
|
||||
thor::rotate(offset, mHolder.getAngle());
|
||||
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition() + offset,
|
||||
mHolder, mHolder.getAngle(), Yaml(mBullet)));
|
||||
|
|
|
@ -39,16 +39,16 @@ protected:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
static const String KEY_BULLET;
|
||||
static const String DEFAULT_BULLET;
|
||||
static const String KEY_INTERVAL;
|
||||
static const std::string KEY_BULLET;
|
||||
static const std::string DEFAULT_BULLET;
|
||||
static const std::string KEY_INTERVAL;
|
||||
static const int DEFAULT_INTERVAL;
|
||||
|
||||
World& mWorld;
|
||||
Body& mHolder;
|
||||
|
||||
Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
|
||||
const String mBullet;
|
||||
sf::Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
|
||||
const std::string mBullet;
|
||||
Timer mTimer;
|
||||
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "Corpse.h"
|
||||
|
||||
Corpse::Corpse(const Vector2f& position, const Yaml& config) :
|
||||
Corpse::Corpse(const sf::Vector2f& position, const Yaml& config) :
|
||||
Sprite(config, Data(position, 0, CATEGORY_NONSOLID, MASK_NONE)) {
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class Yaml;
|
|||
class Corpse : public Sprite {
|
||||
// Public functions.
|
||||
public:
|
||||
Corpse(const Vector2f& position, const Yaml& config);
|
||||
Corpse(const sf::Vector2f& position, const Yaml& config);
|
||||
};
|
||||
|
||||
#endif /* DG_CORPSE_H_ */
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "Corpse.h"
|
||||
|
||||
Enemy::Enemy(World& collection, Pathfinder& pathfinder,
|
||||
const Vector2f& position, const Yaml& config) :
|
||||
const sf::Vector2f& position, const Yaml& config) :
|
||||
Character(collection, pathfinder,
|
||||
Data(position, 0, CATEGORY_ACTOR, MASK_ALL),
|
||||
config) {
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
#ifndef DG_ENEMY_H_
|
||||
#define DG_ENEMY_H
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
#include "../abstract/Character.h"
|
||||
#include "../World.h"
|
||||
#include "../types/Vector.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
class Character;
|
||||
|
@ -22,7 +23,7 @@ class Enemy : public Character {
|
|||
// Public functions.
|
||||
public:
|
||||
Enemy(World& collection, Pathfinder& pathfinder,
|
||||
const Vector2f& position, const Yaml& config);
|
||||
const sf::Vector2f& position, const Yaml& config);
|
||||
|
||||
// Private functions.
|
||||
private:
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
|
||||
#include "Player.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Thor/Vectors.hpp>
|
||||
|
||||
#include "../items/Weapon.h"
|
||||
#include "../types/String.h"
|
||||
#include "../types/Vector.h"
|
||||
|
||||
/**
|
||||
* Initializes Sprite.
|
||||
*/
|
||||
Player::Player(World& world, Pathfinder& pathfinder,
|
||||
const Vector2f& position, const Yaml& config) :
|
||||
const sf::Vector2f& position, const Yaml& config) :
|
||||
Character(world, pathfinder,
|
||||
Data(position, 0, CATEGORY_ACTOR, MASK_ALL),
|
||||
config),
|
||||
|
@ -30,7 +30,7 @@ Player::Player(World& world, Pathfinder& pathfinder,
|
|||
* @param Absolute world coordinates of the crosshair.
|
||||
*/
|
||||
void
|
||||
Player::setCrosshairPosition(const Vector2f& position) {
|
||||
Player::setCrosshairPosition(const sf::Vector2f& position) {
|
||||
mCrosshairPosition = position - getPosition();
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ Player::fire() {
|
|||
* @param destination Absolute world coordinate of the destination point.
|
||||
*/
|
||||
void
|
||||
Player::move(const Vector2f& destination) {
|
||||
Player::move(const sf::Vector2f& destination) {
|
||||
setDestination(destination);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ Player::setDirection(Direction direction, bool unset) {
|
|||
mDirection = mDirection | direction;
|
||||
}
|
||||
// Convert directions into a vector.
|
||||
Vector2f dirVec(0, 0);
|
||||
sf::Vector2f dirVec(0, 0);
|
||||
if (mDirection & Direction::RIGHT) {
|
||||
dirVec.x += 1.0f;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ Player::onThink(float elapsedTime) {
|
|||
Character::move();
|
||||
}
|
||||
// Look towards crosshair.
|
||||
if (mCrosshairPosition != Vector2f()) {
|
||||
if (mCrosshairPosition != sf::Vector2f()) {
|
||||
setAngle(thor::polarAngle(mCrosshairPosition) + 90);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#include "../abstract/Character.h"
|
||||
#include "../items/Weapon.h"
|
||||
#include "../types/Vector.h"
|
||||
#include "../util/Pathfinder.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
|
@ -42,11 +41,11 @@ public:
|
|||
// Public functions.
|
||||
public:
|
||||
Player(World& world, Pathfinder& pathfinder,
|
||||
const Vector2f& position, const Yaml& config);
|
||||
const sf::Vector2f& position, const Yaml& config);
|
||||
|
||||
void setCrosshairPosition(const Vector2f& position);
|
||||
void setCrosshairPosition(const sf::Vector2f& position);
|
||||
void fire();
|
||||
void move(const Vector2f& destination);
|
||||
void move(const sf::Vector2f& destination);
|
||||
void setDirection(Direction direction, bool unset);
|
||||
|
||||
// Private functions.
|
||||
|
@ -56,7 +55,7 @@ private:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
|
||||
sf::Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
|
||||
unsigned char mDirection; //< Current movement direction for direct control.
|
||||
};
|
||||
|
||||
|
|
|
@ -7,14 +7,15 @@
|
|||
|
||||
#include "TileManager.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Thor/Resources.hpp>
|
||||
|
||||
#include "../abstract/Sprite.h"
|
||||
#include "../types/String.h"
|
||||
#include "../util/Loader.h"
|
||||
#include "../util/ResourceManager.h"
|
||||
|
||||
const Vector2i TileManager::TILE_SIZE = Vector2i(100, 100);
|
||||
const sf::Vector2i TileManager::TILE_SIZE = sf::Vector2i(100, 100);
|
||||
|
||||
/**
|
||||
* Loads tile resources.
|
||||
|
@ -34,7 +35,7 @@ TileManager::TileManager(World& world) :
|
|||
*/
|
||||
TileManager::Tile::Tile(Type type, const TilePosition& position) :
|
||||
Sprite(Yaml(getConfig(type)), Data(
|
||||
Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), 0,
|
||||
sf::Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), 0,
|
||||
CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL)),
|
||||
mType(type) {
|
||||
}
|
||||
|
@ -45,9 +46,9 @@ TileManager::Tile::Tile(Type type, const TilePosition& position) :
|
|||
* @param type The type of tile to load a resource key for.
|
||||
* @return Resource key to the correct texture.
|
||||
*/
|
||||
String
|
||||
std::string
|
||||
TileManager::Tile::getConfig(Type type) {
|
||||
String filename;
|
||||
std::string filename;
|
||||
switch (type) {
|
||||
case Type::FLOOR:
|
||||
filename = "tile_floor.yaml";
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
|
||||
#include "../World.h"
|
||||
#include "../abstract/Sprite.h"
|
||||
#include "../types/Vector.h"
|
||||
#include "../types/String.h"
|
||||
#include <string>
|
||||
|
||||
class World;
|
||||
class Sprite;
|
||||
|
@ -30,12 +29,12 @@ public:
|
|||
/**
|
||||
* Uses the length/width of a tile as a unit.
|
||||
*/
|
||||
typedef Vector2i TilePosition;
|
||||
typedef sf::Vector2i TilePosition;
|
||||
|
||||
// Public variables.
|
||||
public:
|
||||
/// The size of a single tile (pixels).
|
||||
static const Vector2i TILE_SIZE;
|
||||
static const sf::Vector2i TILE_SIZE;
|
||||
|
||||
// Public functions.
|
||||
public:
|
||||
|
@ -68,7 +67,7 @@ public:
|
|||
Type getType() const;
|
||||
TilePosition getTilePosition() const;
|
||||
|
||||
static String getConfig(Type type);
|
||||
static std::string getConfig(Type type);
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* String.h
|
||||
*
|
||||
* Created on: 19.07.2012
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
/**
|
||||
* Use this as a replacement for std::to_string as MingW does not support it.
|
||||
*/
|
||||
|
||||
#ifndef DG_STRING_H_
|
||||
#define DG_STRING_H_
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
typedef std::string String;
|
||||
|
||||
/**
|
||||
* Converts any value to a string.
|
||||
*
|
||||
* @param val Any variable.
|
||||
* @return val converted to string.
|
||||
*/
|
||||
template <typename T>
|
||||
String
|
||||
str(T val) {
|
||||
std::stringstream out;
|
||||
out << val;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts floating point variable to string,
|
||||
*
|
||||
* @param val Any floating point variable.
|
||||
* @param digits Number of decimal places to round to.
|
||||
* @return val converted to string.
|
||||
*/
|
||||
template <typename T>
|
||||
String
|
||||
str(T val, int digits) {
|
||||
std::stringstream out;
|
||||
out.precision(digits);
|
||||
out << val;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
#endif /* DG_STRING_H_ */
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Vector.h
|
||||
*
|
||||
* Created on: 03.08.2012
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#ifndef DG_VECTOR_H_
|
||||
#define DG_VECTOR_H_
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
#include <Thor/Vectors.hpp>
|
||||
|
||||
/**
|
||||
* 2D floating point vector with x/y members.
|
||||
*/
|
||||
typedef sf::Vector2f Vector2f;
|
||||
|
||||
/**
|
||||
* 2D integer vector with x/y members.
|
||||
*/
|
||||
typedef sf::Vector2i Vector2i;
|
||||
|
||||
#endif /* DG_VECTOR_H_ */
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "../types/Vector.h"
|
||||
|
||||
/**
|
||||
* Logging functions for different levels.
|
||||
*
|
||||
|
@ -46,19 +44,19 @@
|
|||
#define LOG_I(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Info: " << str << std::endl
|
||||
|
||||
/**
|
||||
* Adds an output operator specalization for Vector2f.
|
||||
* Adds an output operator specalization for sf::Vector2f.
|
||||
*/
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& os, const Vector2f& vector) {
|
||||
operator<<(std::ostream& os, const sf::Vector2f& vector) {
|
||||
os << "(" << vector.x << ", " << vector.y << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an output operator specalization for Vector2i
|
||||
* Adds an output operator specalization for sf::Vector2i
|
||||
*/
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& os, const Vector2i& vector) {
|
||||
operator<<(std::ostream& os, const sf::Vector2i& vector) {
|
||||
os << "(" << vector.x << ", " << vector.y << ")";
|
||||
return os;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
Pathfinder::Pathfinder() {
|
||||
}
|
||||
|
||||
std::vector<Vector2f>
|
||||
Pathfinder::getPath(Body& physical, const Vector2f& destination) {
|
||||
return std::vector<Vector2f>();
|
||||
std::vector<sf::Vector2f>
|
||||
Pathfinder::getPath(Body& physical, const sf::Vector2f& destination) {
|
||||
return std::vector<sf::Vector2f>();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
#ifndef PATHFINDER_H_
|
||||
#define PATHFINDER_H_
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
#include "../abstract/Body.h"
|
||||
#include "../types/Vector.h"
|
||||
|
||||
class Body;
|
||||
|
||||
|
@ -18,7 +19,7 @@ class Pathfinder {
|
|||
public:
|
||||
Pathfinder();
|
||||
|
||||
std::vector<Vector2f> getPath(Body& physical, const Vector2f& destination);
|
||||
std::vector<sf::Vector2f> getPath(Body& physical, const sf::Vector2f& destination);
|
||||
};
|
||||
|
||||
#endif /* PATHFINDER_H_ */
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
|
||||
#include "../util/Log.h"
|
||||
|
||||
String Yaml::mFolder = "";
|
||||
std::string Yaml::mFolder = "";
|
||||
|
||||
/**
|
||||
* Creates a readable object from a YAML file. The path must be relative to the directory
|
||||
* set in setFolder().
|
||||
*/
|
||||
Yaml::Yaml(const String& filename) :
|
||||
Yaml::Yaml(const std::string& filename) :
|
||||
mFilename(mFolder+filename),
|
||||
mFile(mFilename) {
|
||||
if (mFile.fail()) {
|
||||
|
@ -32,7 +32,7 @@ Yaml::~Yaml() {
|
|||
/**
|
||||
* Return path and name of the file opened in this object.
|
||||
*/
|
||||
String
|
||||
std::string
|
||||
Yaml::getFilename() const {
|
||||
return mFilename;
|
||||
}
|
||||
|
@ -42,6 +42,6 @@ Yaml::getFilename() const {
|
|||
* shorter strings as this does not have to be added everywhere.
|
||||
*/
|
||||
void
|
||||
Yaml::setFolder(const String& folder) {
|
||||
Yaml::setFolder(const std::string& folder) {
|
||||
mFolder = folder;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
#ifndef DG_YAML_H_
|
||||
#define DG_YAML_H_
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "../types/String.h"
|
||||
#include "../types/Vector.h"
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
/**
|
||||
* Interface to a YAML file.
|
||||
|
@ -21,21 +21,21 @@
|
|||
class Yaml {
|
||||
// Public functions.
|
||||
public:
|
||||
Yaml(const String& filename);
|
||||
Yaml(const std::string& filename);
|
||||
~Yaml();
|
||||
|
||||
String getFilename() const;
|
||||
std::string getFilename() const;
|
||||
|
||||
static void setFolder(const String& folder);
|
||||
static void setFolder(const std::string& folder);
|
||||
|
||||
template <typename T>
|
||||
T get(const String& key, const T& defaultValue) const;
|
||||
T get(const std::string& key, const T& defaultValue) const;
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static String mFolder;
|
||||
static std::string mFolder;
|
||||
|
||||
String mFilename;
|
||||
std::string mFilename;
|
||||
std::ifstream mFile;
|
||||
YAML::Node mNode;
|
||||
};
|
||||
|
@ -44,12 +44,12 @@ private:
|
|||
* Stream output operators to specialize Yaml::get for other types.
|
||||
*/
|
||||
namespace {
|
||||
void operator>>(const YAML::Node& node, Vector2i& vector) {
|
||||
void operator>>(const YAML::Node& node, sf::Vector2i& vector) {
|
||||
node[0] >> vector.x;
|
||||
node[1] >> vector.y;
|
||||
}
|
||||
|
||||
void operator>>(const YAML::Node& node, Vector2f& vector) {
|
||||
void operator>>(const YAML::Node& node, sf::Vector2f& vector) {
|
||||
node[0] >> vector.x;
|
||||
node[1] >> vector.y;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace {
|
|||
* @return The value of the specified key.
|
||||
*/
|
||||
template <typename T>
|
||||
T Yaml::get(const String& key, const T& defaultValue) const {
|
||||
T Yaml::get(const std::string& key, const T& defaultValue) const {
|
||||
if (const YAML::Node* node = mNode.FindValue(key)) {
|
||||
T value;
|
||||
*node >> value;
|
||||
|
|
Reference in a new issue