Changed folder structure, moved files.

This commit is contained in:
Felix Ableitner 2012-10-14 18:14:06 +02:00
parent 2be3f13810
commit bb3ecf637b
28 changed files with 677 additions and 678 deletions

View file

@ -9,13 +9,13 @@
#include <Thor/Graphics.hpp> #include <Thor/Graphics.hpp>
#include "util/Instances.h"
#include "abstract/Character.h" #include "abstract/Character.h"
#include "sprite/Cover.h" #include "sprites/Cover.h"
#include "sprite/Enemy.h" #include "sprites/Enemy.h"
#include "types/Instances.h"
#include "types/String.h"
#include "util/Loader.h" #include "util/Loader.h"
#include "util/ResourceManager.h" #include "util/ResourceManager.h"
#include "util/String.h"
/// Goal amount of frames per second. /// Goal amount of frames per second.
const int Game::FPS_GOAL = 60; const int Game::FPS_GOAL = 60;

View file

@ -15,11 +15,11 @@
#include <Box2D/Box2D.h> #include <Box2D/Box2D.h>
#include "Pathfinder.h" #include "sprites/TileManager.h"
#include "TileManager.h" #include "sprites/Player.h"
#include "sprite/Player.h" #include "types/String.h"
#include "util/Collection.h" #include "util/Collection.h"
#include "util/String.h" #include "util/Pathfinder.h"
class Player; class Player;
class Collection; class Collection;

View file

@ -12,7 +12,7 @@
#include <Thor/Vectors.hpp> #include <Thor/Vectors.hpp>
#include "../sprite/Body.h" #include "../sprites/Body.h"
#include "../util/Log.h" #include "../util/Log.h"
const String Character::KEY_HEALTH = "health"; const String Character::KEY_HEALTH = "health";

View file

@ -12,8 +12,8 @@
#include "Sprite.h" #include "Sprite.h"
#include "../items/Weapon.h" #include "../items/Weapon.h"
#include "../util/Instances.h" #include "../types/Instances.h"
#include "../util/String.h" #include "../types/String.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Weapon; class Weapon;

View file

@ -10,8 +10,8 @@
#include <Box2D/Box2D.h> #include <Box2D/Box2D.h>
#include "../util/String.h" #include "../types/String.h"
#include "../util/Vector.h" #include "../types/Vector.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Yaml; class Yaml;

View file

@ -1,44 +1,44 @@
/* /*
* Singleton.h * Singleton.h
* *
* Created on: 04.07.2012 * Created on: 04.07.2012
* Author: Felix * Author: Felix
*/ */
#ifndef DG_SINGLETON_H_ #ifndef DG_SINGLETON_H_
#define DG_SINGLETON_H_ #define DG_SINGLETON_H_
#include <SFML/System.hpp> #include <SFML/System.hpp>
/** /**
* Template class for inheriting singleton behaviour. * Template class for inheriting singleton behaviour.
* *
* This uses lazy initialization and should be thread safe in C++11 (untested). * This uses lazy initialization and should be thread safe in C++11 (untested).
* To use, just make a subclass with only a private default constructor and Singleton<T> * To use, just make a subclass with only a private default constructor and Singleton<T>
* as friend class. * as friend class.
* *
* @code * @code
* class MyClass : public Singleton<MyClass> { * class MyClass : public Singleton<MyClass> {
* private: * private:
* friend class Singleton<MyClass>; * friend class Singleton<MyClass>;
* MyClass() = default; * MyClass() = default;
* }; * };
* @endcode * @endcode
*/ */
template <class T> template <class T>
class Singleton : public sf::NonCopyable { class Singleton : public sf::NonCopyable {
// Public functions. // Public functions.
public: public:
static T& i(); static T& i();
}; };
/** /**
* Returns the instance of T. * Returns the instance of T.
*/ */
template <class T> template <class T>
T& Singleton<T>::i() { T& Singleton<T>::i() {
static T s; static T s;
return s; return s;
}; };
#endif /* DG_SINGLETON_H_ */ #endif /* DG_SINGLETON_H_ */

View file

@ -13,8 +13,8 @@
#include <Thor/Resources.hpp> #include <Thor/Resources.hpp>
#include "Physical.h" #include "Physical.h"
#include "../util/String.h" #include "../types/String.h"
#include "../util/Vector.h" #include "../types/Vector.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Physical; class Physical;

View file

@ -9,7 +9,7 @@
#define DG_BULLET_H_ #define DG_BULLET_H_
#include "../particle/Particle.h" #include "../particle/Particle.h"
#include "../util/String.h" #include "../types/String.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Particle; class Particle;

View file

@ -10,9 +10,9 @@
#include <Thor/Particles.hpp> #include <Thor/Particles.hpp>
#include "../util/Instances.h"
#include "../abstract/Physical.h" #include "../abstract/Physical.h"
#include "../particle/Emitter.h" #include "../particle/Emitter.h"
#include "../types/Instances.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Emitter; class Emitter;

26
source/sprite/Body.cpp → source/sprites/Body.cpp Executable file → Normal file
View file

@ -1,13 +1,13 @@
/* /*
* Body.cpp * Body.cpp
* *
* Created on: 13.09.2012 * Created on: 13.09.2012
* Author: Felix * Author: Felix
*/ */
#include "Body.h" #include "Body.h"
Body::Body(b2World& world, const Vector2f& position, const Yaml& config) : Body::Body(b2World& world, const Vector2f& position, const Yaml& config) :
Sprite(config, PhysicalData(position, world, CATEGORY_NONSOLID, MASK_NONE, false)) { Sprite(config, PhysicalData(position, world, CATEGORY_NONSOLID, MASK_NONE, false)) {
} }

46
source/sprite/Body.h → source/sprites/Body.h Executable file → Normal file
View file

@ -1,23 +1,23 @@
/* /*
* Body.h * Body.h
* *
* Created on: 13.09.2012 * Created on: 13.09.2012
* Author: Felix * Author: Felix
*/ */
#ifndef DG_BODY_H_ #ifndef DG_BODY_H_
#define DG_BODY_H_ #define DG_BODY_H_
#include "../abstract/Sprite.h" #include "../abstract/Sprite.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Sprite; class Sprite;
class Yaml; class Yaml;
class Body : public Sprite { class Body : public Sprite {
// Public functions. // Public functions.
public: public:
Body(b2World& world, const Vector2f& position, const Yaml& config); Body(b2World& world, const Vector2f& position, const Yaml& config);
}; };
#endif /* DG_BODY_H_ */ #endif /* DG_BODY_H_ */

26
source/sprite/Cover.cpp → source/sprites/Cover.cpp Executable file → Normal file
View file

@ -1,13 +1,13 @@
/* /*
* Cover.cpp * Cover.cpp
* *
* Created on: 12.08.2012 * Created on: 12.08.2012
* Author: Felix * Author: Felix
*/ */
#include "Cover.h" #include "Cover.h"
Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) : Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) :
Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) { Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) {
} }

52
source/sprite/Cover.h → source/sprites/Cover.h Executable file → Normal file
View file

@ -1,26 +1,26 @@
/* /*
* Cover.h * Cover.h
* *
* Created on: 12.08.2012 * Created on: 12.08.2012
* Author: Felix * Author: Felix
*/ */
#ifndef DG_COVER_H_ #ifndef DG_COVER_H_
#define DG_COVER_H_ #define DG_COVER_H_
#include "../abstract/Sprite.h" #include "../abstract/Sprite.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Sprite; class Sprite;
class Yaml; class Yaml;
/** /**
* A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size. * A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size.
*/ */
class Cover : public Sprite { class Cover : public Sprite {
// Public functions. // Public functions.
public: public:
Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config); Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config);
}; };
#endif /* DG_COVER_H_ */ #endif /* DG_COVER_H_ */

View file

@ -1,21 +1,21 @@
/* /*
* Enemy.cpp * Enemy.cpp
* *
* Created on: 10.09.2012 * Created on: 10.09.2012
* Author: Felix * Author: Felix
*/ */
#include "Enemy.h" #include "Enemy.h"
#include "Body.h" #include "Body.h"
Enemy::Enemy(const Instances& instances, const Vector2f& position, const Yaml& config) : Enemy::Enemy(const Instances& instances, const Vector2f& position, const Yaml& config) :
Character(instances, "enemy.png", PhysicalData(position, instances.world, Character(instances, "enemy.png", PhysicalData(position, instances.world,
CATEGORY_ACTOR, MASK_ALL, true, false, true), config), CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
mWorld(instances.world), mWorld(instances.world),
mCollection(instances.collection) { mCollection(instances.collection) {
} }
void void
Enemy::onThink(float elapsedTime) { Enemy::onThink(float elapsedTime) {
} }

View file

@ -1,37 +1,37 @@
/* /*
* Enemy.h * Enemy.h
* *
* Created on: 10.09.2012 * Created on: 10.09.2012
* Author: Felix * Author: Felix
*/ */
#ifndef DG_ENEMY_H_ #ifndef DG_ENEMY_H_
#define DG_ENEMY_H #define DG_ENEMY_H
#include "../util/Instances.h" #include "../types/Instances.h"
#include "../abstract/Character.h" #include "../abstract/Character.h"
#include "../util/Collection.h" #include "../util/Collection.h"
#include "../util/Vector.h" #include "../types/Vector.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Character; class Character;
class Collection; class Collection;
class Instances; class Instances;
class Yaml; class Yaml;
class Enemy : public Character { class Enemy : public Character {
// Public functions. // Public functions.
public: public:
Enemy(const Instances& instances, const Vector2f& position, const Yaml& config); Enemy(const Instances& instances, const Vector2f& position, const Yaml& config);
// Private functions. // Private functions.
private: private:
void onThink(float elapsedTime); void onThink(float elapsedTime);
// Private variablese. // Private variablese.
private: private:
b2World& mWorld; b2World& mWorld;
Collection& mCollection; Collection& mCollection;
}; };
#endif /* DG_ENEMY_H_ */ #endif /* DG_ENEMY_H_ */

View file

@ -1,106 +1,106 @@
/* /*
* Player.cpp * Player.cpp
* *
* Created on: 21.07.2012 * Created on: 21.07.2012
* Author: Felix * Author: Felix
*/ */
#include "Player.h" #include "Player.h"
#include <Thor/Vectors.hpp> #include <Thor/Vectors.hpp>
#include "../util/Vector.h" #include "../items/Weapon.h"
#include "../items/Weapon.h" #include "../types/String.h"
#include "../util/String.h" #include "../types/Vector.h"
/** /**
* Initializes Sprite. * Initializes Sprite.
*/
Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) :
Character(instances, "player.png", PhysicalData(position, instances.world,
CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
mDirection(0) {
}
/**
* Sets the point where to look and shoot at.
*
* @param Absolute world coordinates of the crosshair.
*/ */
Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) :
Character(instances, "player.png", PhysicalData(position, instances.world,
CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
mDirection(0) {
}
/**
* Sets the point where to look and shoot at.
*
* @param Absolute world coordinates of the crosshair.
*/
void
Player::setCrosshairPosition(const Vector2f& position) {
mCrosshairPosition = position - getPosition();
}
/**
* Fires the attached Weapon, emitting a Bullet object.
*/
void
Player::fire() {
Character::fire();
}
/**
* Moves the player to a destination point.
* Disables any previous calls to Player::setDirection().
*
* @param destination Absolute world coordinate of the destination point.
*/
void void
Player::move(const Vector2f& destination) { Player::setCrosshairPosition(const Vector2f& position) {
mCrosshairPosition = position - getPosition();
}
/**
* Fires the attached Weapon, emitting a Bullet object.
*/
void
Player::fire() {
Character::fire();
}
/**
* Moves the player to a destination point.
* Disables any previous calls to Player::setDirection().
*
* @param destination Absolute world coordinate of the destination point.
*/
void
Player::move(const Vector2f& destination) {
setDestination(destination); setDestination(destination);
} }
/** /**
* Sets the movement direction. This is destined for input via keys (eg. WASD). * Sets the movement direction. This is destined for input via keys (eg. WASD).
* Disables any previous commands via Player::move(). * Disables any previous commands via Player::move().
* *
* @param direction The direction to move to. * @param direction The direction to move to.
* @param unset False to start movement into the direction, true to stop it. * @param unset False to start movement into the direction, true to stop it.
*/ */
void void
Player::setDirection(Direction direction, bool unset) { Player::setDirection(Direction direction, bool unset) {
if (unset) { if (unset) {
mDirection = mDirection & ~(uint8) direction; mDirection = mDirection & ~(uint8) direction;
} else { } else {
mDirection = mDirection | (uint8) direction; mDirection = mDirection | (uint8) direction;
} }
// Convert directions into a vector. // Convert directions into a vector.
Vector2f dirVec(0, 0); Vector2f dirVec(0, 0);
if (mDirection & (uint8) Direction::RIGHT) { if (mDirection & (uint8) Direction::RIGHT) {
dirVec.x += 1.0f; dirVec.x += 1.0f;
} }
if (mDirection & (uint8) Direction::LEFT) { if (mDirection & (uint8) Direction::LEFT) {
dirVec.x += - 1.0f; dirVec.x += - 1.0f;
} }
if (mDirection & (uint8) Direction::DOWN) { if (mDirection & (uint8) Direction::DOWN) {
dirVec.y += 1.0f; dirVec.y += 1.0f;
} }
if (mDirection & (uint8) Direction::UP) { if (mDirection & (uint8) Direction::UP) {
dirVec.y += - 1.0f; dirVec.y += - 1.0f;
} }
setSpeed(dirVec, getMovementSpeed()); setSpeed(dirVec, getMovementSpeed());
} }
/** /**
* Check if we arrived at destination, turn towards cursor. * Check if we arrived at destination, turn towards cursor.
*/ */
void void
Player::onThink(float elapsedTime) { Player::onThink(float elapsedTime) {
if (!mDirection) { if (!mDirection) {
// Only use path finding movement if no direct input movement active. // Only use path finding movement if no direct input movement active.
Character::move(); Character::move();
} }
// Look towards crosshair. // Look towards crosshair.
setAngle(angle(mCrosshairPosition)); setAngle(angle(mCrosshairPosition));
} }
/** /**
* Stop movement if we collide with anything except bullets. * Stop movement if we collide with anything except bullets.
*/ */
void void
Player::onCollide(Physical& other, uint16 category) { Player::onCollide(Physical& other, uint16 category) {
if (category != CATEGORY_PARTICLE) { if (category != CATEGORY_PARTICLE) {
setDestination(getPosition()); setDestination(getPosition());
} }
} }

View file

@ -1,63 +1,63 @@
/* /*
* Player.h * Player.h
* *
* Created on: 21.07.2012 * Created on: 21.07.2012
* Author: Felix * Author: Felix
*/ */
#ifndef DG_PLAYER_H_ #ifndef DG_PLAYER_H_
#define DG_PLAYER_H_ #define DG_PLAYER_H_
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "../util/Instances.h" #include "../abstract/Character.h"
#include "../Pathfinder.h" #include "../items/Weapon.h"
#include "../abstract/Character.h" #include "../types/Instances.h"
#include "../items/Weapon.h" #include "../types/Vector.h"
#include "../util/Vector.h" #include "../util/Pathfinder.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Character; class Character;
class Instances; class Instances;
class Pathfinder; class Pathfinder;
class Weapon; class Weapon;
class Yaml; class Yaml;
/** /**
* Player object. * Player object.
*/ */
class Player : public Character { class Player : public Character {
// Public types. // Public types.
public: public:
/** /**
* Movement directions that can be set via Player::setDirection(). * Movement directions that can be set via Player::setDirection().
*/ */
enum class Direction : uint8 { enum class Direction : uint8 {
RIGHT = 1 << 0, RIGHT = 1 << 0,
LEFT = 1 << 1, LEFT = 1 << 1,
UP = 1 << 2, UP = 1 << 2,
DOWN = 1 << 3 DOWN = 1 << 3
}; };
// Public functions. // Public functions.
public: public:
Player(const Instances& instances, const Vector2f& position, const Yaml& config); Player(const Instances& instances, const Vector2f& position, const Yaml& config);
void setCrosshairPosition(const Vector2f& position); void setCrosshairPosition(const Vector2f& position);
void fire(); void fire();
void move(const Vector2f& destination); void move(const Vector2f& destination);
void setDirection(Direction direction, bool unset); void setDirection(Direction direction, bool unset);
// Private functions. // Private functions.
private: private:
void onCollide(Physical& other, uint16 category); void onCollide(Physical& other, uint16 category);
void onThink(float elapsedTime); void onThink(float elapsedTime);
// Private variables. // Private variables.
private: private:
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor). Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
uint8 mDirection; //< Current movement direction for direct control. uint8 mDirection; //< Current movement direction for direct control.
}; };
#endif /* DG_PLAYER_H_ */ #endif /* DG_PLAYER_H_ */

194
source/TileManager.cpp → source/sprites/TileManager.cpp Executable file → Normal file
View file

@ -1,103 +1,103 @@
/* /*
* TileManager.cpp * TileManager.cpp
* *
* Created on: 08.08.2012 * Created on: 08.08.2012
* Author: Felix * Author: Felix
*/ */
#include "TileManager.h" #include "TileManager.h"
#include <Thor/Resources.hpp> #include <Thor/Resources.hpp>
#include "abstract/Sprite.h" #include "../abstract/Sprite.h"
#include "util/Loader.h" #include "../types/String.h"
#include "util/ResourceManager.h" #include "../util/Loader.h"
#include "util/String.h" #include "../util/ResourceManager.h"
const Vector2i TileManager::TILE_SIZE = Vector2i(100, 100); const Vector2i TileManager::TILE_SIZE = Vector2i(100, 100);
/** /**
* Loads tile resources. * Loads tile resources.
* *
* @param world Box2D world to create (physical) tiles in. * @param world Box2D world to create (physical) tiles in.
*/ */
TileManager::TileManager(b2World& world) : TileManager::TileManager(b2World& world) :
mWorld(world) { mWorld(world) {
} }
/** /**
* Constructs a tile. * Constructs a tile.
* *
* @param pType Type of the tile to create. * @param pType Type of the tile to create.
* @param pPosition Position of the tile in tile coordinates. * @param pPosition Position of the tile in tile coordinates.
* @param world Box2D world object. * @param world Box2D world object.
*/ */
TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) : TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) :
Sprite(Yaml(getConfig(type)), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), Sprite(Yaml(getConfig(type)), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y),
world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)), world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)),
mType(type) { mType(type) {
} }
/** /**
* Returns a texture key for a certain tile type. * Returns a texture key for a certain tile type.
* *
* @param type The type of tile to load a resource key for. * @param type The type of tile to load a resource key for.
* @return Resource key to the correct texture. * @return Resource key to the correct texture.
*/ */
String String
TileManager::Tile::getConfig(Type type) { TileManager::Tile::getConfig(Type type) {
String filename; String filename;
switch (type) { switch (type) {
case Type::FLOOR: case Type::FLOOR:
filename = "tile_floor.yaml"; filename = "tile_floor.yaml";
break; break;
case Type::WALL: case Type::WALL:
filename = "tile_wall.yaml"; filename = "tile_wall.yaml";
break; break;
default: default:
throw new aurora::Exception("Invalid tile type."); throw new aurora::Exception("Invalid tile type.");
} }
return filename; return filename;
} }
/** /**
* Returns the Type of this tile. * Returns the Type of this tile.
*/ */
TileManager::Type TileManager::Type
TileManager::Tile::getType() const { TileManager::Tile::getType() const {
return mType; return mType;
} }
/** /**
* Returns the position of the tile with tile width/height as a unit. * Returns the position of the tile with tile width/height as a unit.
*/ */
TileManager::TilePosition TileManager::TilePosition
TileManager::Tile::getTilePosition() const { TileManager::Tile::getTilePosition() const {
return TilePosition(getPosition().x / TILE_SIZE.x, getPosition().y / TILE_SIZE.y); return TilePosition(getPosition().x / TILE_SIZE.x, getPosition().y / TILE_SIZE.y);
} }
/** /**
* Insert a tile at the position. Deletes an existing tile first if one is at the position. * Insert a tile at the position. Deletes an existing tile first if one is at the position.
* *
* @param position Grid coordinate of the tile (not pixel coordinate). * @param position Grid coordinate of the tile (not pixel coordinate).
* @param type Type of tile to be inserted. * @param type Type of tile to be inserted.
*/ */
void void
TileManager::setTile(const TilePosition& position, Type type) { TileManager::setTile(const TilePosition& position, Type type) {
for (auto it = mTiles.begin(); it != mTiles.end(); it++) { for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
if ((*it)->getTilePosition() == position) { if ((*it)->getTilePosition() == position) {
mTiles.erase(it); mTiles.erase(it);
} }
} }
mTiles.push_back(std::unique_ptr<Tile>(new Tile(type, position, mWorld))); mTiles.push_back(std::unique_ptr<Tile>(new Tile(type, position, mWorld)));
} }
/** /**
* \copydoc sf::Drawable::draw * \copydoc sf::Drawable::draw
*/ */
void void
TileManager::draw(sf::RenderTarget& target, sf::RenderStates states) const { TileManager::draw(sf::RenderTarget& target, sf::RenderStates states) const {
for (auto it = mTiles.begin(); it != mTiles.end(); it++) { for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
target.draw((**it), states); target.draw((**it), states);
} }
} }

154
source/TileManager.h → source/sprites/TileManager.h Executable file → Normal file
View file

@ -1,79 +1,79 @@
/* /*
* TileManager.h * TileManager.h
* *
* Created on: 08.08.2012 * Created on: 08.08.2012
* Author: Felix * Author: Felix
*/ */
#ifndef DG_TILEMANAGER_H_ #ifndef DG_TILEMANAGER_H_
#define DG_TILEMANAGER_H_ #define DG_TILEMANAGER_H_
#include <map> #include <map>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <Box2D/Box2D.h> #include <Box2D/Box2D.h>
#include "util/Vector.h" #include "../abstract/Sprite.h"
#include "abstract/Sprite.h" #include "../types/Vector.h"
#include "util/String.h" #include "../types/String.h"
class Sprite; class Sprite;
class TileManager : public sf::Drawable { class TileManager : public sf::Drawable {
// Public types. // Public types.
public: public:
enum class Type { enum class Type {
FLOOR, FLOOR,
WALL WALL
}; };
/** /**
* Uses the length/width of a tile as a unit. * Uses the length/width of a tile as a unit.
*/ */
typedef Vector2i TilePosition; typedef Vector2i TilePosition;
// Public variables. // Public variables.
public: public:
/// The size of a single tile (pixels). /// The size of a single tile (pixels).
static const Vector2i TILE_SIZE; static const Vector2i TILE_SIZE;
// Public functions. // Public functions.
public: public:
TileManager(b2World& world); TileManager(b2World& world);
void setTile(const TilePosition& position, Type type); void setTile(const TilePosition& position, Type type);
// Private types. // Private types.
private: private:
class Tile; class Tile;
// Private functions. // Private functions.
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const; void draw(sf::RenderTarget& target, sf::RenderStates states) const;
// Private variables. // Private variables.
private: private:
b2World& mWorld; b2World& mWorld;
std::vector<std::unique_ptr<Tile> > mTiles; std::vector<std::unique_ptr<Tile> > mTiles;
}; };
/** /**
* Holds information about a single tile. * Holds information about a single tile.
*/ */
class TileManager::Tile : public Sprite { class TileManager::Tile : public Sprite {
// Public functions. // Public functions.
public: public:
Tile(Type type, const TilePosition& position, b2World& world); Tile(Type type, const TilePosition& position, b2World& world);
Type getType() const; Type getType() const;
TilePosition getTilePosition() const; TilePosition getTilePosition() const;
static String getConfig(Type type); static String getConfig(Type type);
// Private variables. // Private variables.
private: private:
Type mType; Type mType;
}; };
#endif /* DG_TILEMANAGER_H_ */ #endif /* DG_TILEMANAGER_H_ */

View file

@ -10,9 +10,9 @@
#include <Box2D/Box2D.h> #include <Box2D/Box2D.h>
#include "../Pathfinder.h" #include "../sprites/TileManager.h"
#include "../TileManager.h" #include "../util/Collection.h"
#include "Collection.h" #include "../util/Pathfinder.h"
class Pathfinder; class Pathfinder;
class TileManager; class TileManager;

View file

@ -1,50 +1,50 @@
/* /*
* String.h * String.h
* *
* Created on: 19.07.2012 * Created on: 19.07.2012
* Author: Felix * Author: Felix
*/ */
/** /**
* Use this as a replacement for std::to_string as MingW does not support it. * Use this as a replacement for std::to_string as MingW does not support it.
*/ */
#ifndef DG_STRING_H_ #ifndef DG_STRING_H_
#define DG_STRING_H_ #define DG_STRING_H_
#include <sstream> #include <sstream>
#include <string> #include <string>
typedef std::string String; typedef std::string String;
/** /**
* Converts any value to a string. * Converts any value to a string.
* *
* @param val Any variable. * @param val Any variable.
* @return val converted to string. * @return val converted to string.
*/ */
template <typename T> template <typename T>
String String
str(T val) { str(T val) {
std::stringstream out; std::stringstream out;
out << val; out << val;
return out.str(); return out.str();
} }
/** /**
* Converts floating point variable to string, * Converts floating point variable to string,
* *
* @param val Any floating point variable. * @param val Any floating point variable.
* @param digits Number of decimal places to round to. * @param digits Number of decimal places to round to.
* @return val converted to string. * @return val converted to string.
*/ */
template <typename T> template <typename T>
String String
str(T val, int digits) { str(T val, int digits) {
std::stringstream out; std::stringstream out;
out.precision(digits); out.precision(digits);
out << val; out << val;
return out.str(); return out.str();
} }
#endif /* DG_STRING_H_ */ #endif /* DG_STRING_H_ */

168
source/util/Vector.h → source/types/Vector.h Executable file → Normal file
View file

@ -1,84 +1,84 @@
/* /*
* Vector.h * Vector.h
* *
* Created on: 03.08.2012 * Created on: 03.08.2012
* Author: Felix * Author: Felix
*/ */
#ifndef VECTOR_H_ #ifndef VECTOR_H_
#define VECTOR_H_ #define VECTOR_H_
#include <math.h> #include <math.h>
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <Box2D/Box2D.h> #include <Box2D/Box2D.h>
#include <Thor/Vectors.hpp> #include <Thor/Vectors.hpp>
/** /**
* 2D floating point vector with x/y members. * 2D floating point vector with x/y members.
*/ */
typedef sf::Vector2f Vector2f; typedef sf::Vector2f Vector2f;
/** /**
* 2D integer vector with x/y members. * 2D integer vector with x/y members.
*/ */
typedef sf::Vector2i Vector2i; typedef sf::Vector2i Vector2i;
/** /**
* Constant for conversion between Box2D vectors and SFML vectors. * Constant for conversion between Box2D vectors and SFML vectors.
*/ */
static const int PIXELS_PER_METER = 25; static const int PIXELS_PER_METER = 25;
/** /**
* Converts a distance from pixels to meters. * Converts a distance from pixels to meters.
*/ */
inline float inline float
pixelToMeter(float in) { pixelToMeter(float in) {
return in / PIXELS_PER_METER; return in / PIXELS_PER_METER;
} }
/** /**
* Converts a distance from meters to pixels. * Converts a distance from meters to pixels.
*/ */
inline float inline float
meterToPixel(float in) { meterToPixel(float in) {
return in * PIXELS_PER_METER; return in * PIXELS_PER_METER;
} }
/** /**
* Converts Box2D metric vector to SFML pixel vector. * Converts Box2D metric vector to SFML pixel vector.
*/ */
inline Vector2f inline Vector2f
vector(const b2Vec2& in) { vector(const b2Vec2& in) {
return Vector2f(meterToPixel(in.x), meterToPixel(in.y)); return Vector2f(meterToPixel(in.x), meterToPixel(in.y));
} }
/** /**
* Converts SFML pixel vector to Box2D metric vector. * Converts SFML pixel vector to Box2D metric vector.
*/ */
inline b2Vec2 inline b2Vec2
vector(const Vector2f& in) { vector(const Vector2f& in) {
return b2Vec2(pixelToMeter(in.x), pixelToMeter(in.y)); return b2Vec2(pixelToMeter(in.x), pixelToMeter(in.y));
} }
/** /**
* Converts a vector to an SFML angle with the same direction. * Converts a vector to an SFML angle with the same direction.
*/ */
inline float inline float
angle(Vector2f in) { angle(Vector2f in) {
return 180 - thor::toDegree(atan2(in.x, in.y)); return 180 - thor::toDegree(atan2(in.x, in.y));
} }
/** /**
* Converts an SFML angle to a unit vector with the same direction. * Converts an SFML angle to a unit vector with the same direction.
*/ */
inline Vector2f inline Vector2f
angle(float in) { angle(float in) {
in = thor::toRadian(180 - in); in = thor::toRadian(180 - in);
return Vector2f(sin(in), cos(in)); return Vector2f(sin(in), cos(in));
} }
#endif /* VECTOR_H_ */ #endif /* VECTOR_H_ */

View file

@ -16,7 +16,7 @@
#include <Thor/Resources.hpp> #include <Thor/Resources.hpp>
#include "Singleton.h" #include "../abstract/Singleton.h"
template <class T> template <class T>
class Singleton; class Singleton;

View file

@ -10,7 +10,7 @@
#include <iostream> #include <iostream>
#include "Vector.h" #include "../types/Vector.h"
/** /**
* Logging functions for different levels. * Logging functions for different levels.

View file

@ -23,8 +23,7 @@
#include <boost/graph/filtered_graph.hpp> #include <boost/graph/filtered_graph.hpp>
#include <boost/graph/astar_search.hpp> #include <boost/graph/astar_search.hpp>
#include "util/Log.h" #include "../util/Log.h"
#include <typeinfo>
// Boost interface type declarations. // Boost interface type declarations.
enum class Direction; enum class Direction;

View file

@ -10,8 +10,8 @@
#include <Box2D/Box2D.h> #include <Box2D/Box2D.h>
#include "abstract/Physical.h" #include "../abstract/Physical.h"
#include "util/Vector.h" #include "../types/Vector.h"
/** /**
* Interface class for Boost Graph A* library. * Interface class for Boost Graph A* library.

View file

@ -12,7 +12,7 @@
#include <Thor/Resources.hpp> #include <Thor/Resources.hpp>
#include "Singleton.h" #include "../abstract/Singleton.h"
template <class T> template <class T>
class Singleton; class Singleton;

View file

@ -12,8 +12,8 @@
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "String.h" #include "../types/String.h"
#include "Vector.h" #include "../types/Vector.h"
namespace details {}; namespace details {};