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 "util/Instances.h"
#include "abstract/Character.h"
#include "sprite/Cover.h"
#include "sprite/Enemy.h"
#include "sprites/Cover.h"
#include "sprites/Enemy.h"
#include "types/Instances.h"
#include "types/String.h"
#include "util/Loader.h"
#include "util/ResourceManager.h"
#include "util/String.h"
/// Goal amount of frames per second.
const int Game::FPS_GOAL = 60;

View file

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

View file

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

View file

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

View file

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

View file

@ -1,44 +1,44 @@
/*
* Singleton.h
*
* Created on: 04.07.2012
* Author: Felix
*/
#ifndef DG_SINGLETON_H_
#define DG_SINGLETON_H_
#include <SFML/System.hpp>
/**
* Template class for inheriting singleton behaviour.
*
* 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>
* as friend class.
*
* @code
* class MyClass : public Singleton<MyClass> {
* private:
* friend class Singleton<MyClass>;
* MyClass() = default;
* };
* @endcode
*/
template <class T>
class Singleton : public sf::NonCopyable {
// Public functions.
public:
static T& i();
};
/**
* Returns the instance of T.
*/
template <class T>
T& Singleton<T>::i() {
static T s;
return s;
};
#endif /* DG_SINGLETON_H_ */
/*
* Singleton.h
*
* Created on: 04.07.2012
* Author: Felix
*/
#ifndef DG_SINGLETON_H_
#define DG_SINGLETON_H_
#include <SFML/System.hpp>
/**
* Template class for inheriting singleton behaviour.
*
* 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>
* as friend class.
*
* @code
* class MyClass : public Singleton<MyClass> {
* private:
* friend class Singleton<MyClass>;
* MyClass() = default;
* };
* @endcode
*/
template <class T>
class Singleton : public sf::NonCopyable {
// Public functions.
public:
static T& i();
};
/**
* Returns the instance of T.
*/
template <class T>
T& Singleton<T>::i() {
static T s;
return s;
};
#endif /* DG_SINGLETON_H_ */

View file

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

View file

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

View file

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

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

@ -1,13 +1,13 @@
/*
* Body.cpp
*
* Created on: 13.09.2012
* Author: Felix
*/
#include "Body.h"
Body::Body(b2World& world, const Vector2f& position, const Yaml& config) :
Sprite(config, PhysicalData(position, world, CATEGORY_NONSOLID, MASK_NONE, false)) {
}
/*
* Body.cpp
*
* Created on: 13.09.2012
* Author: Felix
*/
#include "Body.h"
Body::Body(b2World& world, const Vector2f& position, const Yaml& config) :
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
*
* Created on: 13.09.2012
* Author: Felix
*/
#ifndef DG_BODY_H_
#define DG_BODY_H_
#include "../abstract/Sprite.h"
#include "../util/Yaml.h"
class Sprite;
class Yaml;
class Body : public Sprite {
// Public functions.
public:
Body(b2World& world, const Vector2f& position, const Yaml& config);
};
#endif /* DG_BODY_H_ */
/*
* Body.h
*
* Created on: 13.09.2012
* Author: Felix
*/
#ifndef DG_BODY_H_
#define DG_BODY_H_
#include "../abstract/Sprite.h"
#include "../util/Yaml.h"
class Sprite;
class Yaml;
class Body : public Sprite {
// Public functions.
public:
Body(b2World& world, const Vector2f& position, const Yaml& config);
};
#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
*
* Created on: 12.08.2012
* Author: Felix
*/
#include "Cover.h"
Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) :
Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) {
}
/*
* Cover.cpp
*
* Created on: 12.08.2012
* Author: Felix
*/
#include "Cover.h"
Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) :
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
*
* Created on: 12.08.2012
* Author: Felix
*/
#ifndef DG_COVER_H_
#define DG_COVER_H_
#include "../abstract/Sprite.h"
#include "../util/Yaml.h"
class Sprite;
class Yaml;
/**
* A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size.
*/
class Cover : public Sprite {
// Public functions.
public:
Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config);
};
#endif /* DG_COVER_H_ */
/*
* Cover.h
*
* Created on: 12.08.2012
* Author: Felix
*/
#ifndef DG_COVER_H_
#define DG_COVER_H_
#include "../abstract/Sprite.h"
#include "../util/Yaml.h"
class Sprite;
class Yaml;
/**
* A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size.
*/
class Cover : public Sprite {
// Public functions.
public:
Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config);
};
#endif /* DG_COVER_H_ */

View file

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

View file

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

View file

@ -1,106 +1,106 @@
/*
* Player.cpp
*
* Created on: 21.07.2012
* Author: Felix
*/
#include "Player.h"
#include <Thor/Vectors.hpp>
#include "../util/Vector.h"
#include "../items/Weapon.h"
#include "../util/String.h"
/**
* Initializes Sprite.
/*
* Player.cpp
*
* Created on: 21.07.2012
* Author: Felix
*/
#include "Player.h"
#include <Thor/Vectors.hpp>
#include "../items/Weapon.h"
#include "../types/String.h"
#include "../types/Vector.h"
/**
* 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
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);
}
/**
* Sets the movement direction. This is destined for input via keys (eg. WASD).
* Disables any previous commands via Player::move().
*
* @param direction The direction to move to.
* @param unset False to start movement into the direction, true to stop it.
*/
void
Player::setDirection(Direction direction, bool unset) {
if (unset) {
mDirection = mDirection & ~(uint8) direction;
} else {
mDirection = mDirection | (uint8) direction;
}
// Convert directions into a vector.
Vector2f dirVec(0, 0);
if (mDirection & (uint8) Direction::RIGHT) {
dirVec.x += 1.0f;
}
if (mDirection & (uint8) Direction::LEFT) {
dirVec.x += - 1.0f;
}
if (mDirection & (uint8) Direction::DOWN) {
dirVec.y += 1.0f;
}
if (mDirection & (uint8) Direction::UP) {
dirVec.y += - 1.0f;
}
setSpeed(dirVec, getMovementSpeed());
}
/**
* Check if we arrived at destination, turn towards cursor.
*/
void
Player::onThink(float elapsedTime) {
if (!mDirection) {
// Only use path finding movement if no direct input movement active.
Character::move();
}
// Look towards crosshair.
setAngle(angle(mCrosshairPosition));
}
/**
* Stop movement if we collide with anything except bullets.
*/
void
Player::onCollide(Physical& other, uint16 category) {
if (category != CATEGORY_PARTICLE) {
setDestination(getPosition());
}
}
}
/**
* Sets the movement direction. This is destined for input via keys (eg. WASD).
* Disables any previous commands via Player::move().
*
* @param direction The direction to move to.
* @param unset False to start movement into the direction, true to stop it.
*/
void
Player::setDirection(Direction direction, bool unset) {
if (unset) {
mDirection = mDirection & ~(uint8) direction;
} else {
mDirection = mDirection | (uint8) direction;
}
// Convert directions into a vector.
Vector2f dirVec(0, 0);
if (mDirection & (uint8) Direction::RIGHT) {
dirVec.x += 1.0f;
}
if (mDirection & (uint8) Direction::LEFT) {
dirVec.x += - 1.0f;
}
if (mDirection & (uint8) Direction::DOWN) {
dirVec.y += 1.0f;
}
if (mDirection & (uint8) Direction::UP) {
dirVec.y += - 1.0f;
}
setSpeed(dirVec, getMovementSpeed());
}
/**
* Check if we arrived at destination, turn towards cursor.
*/
void
Player::onThink(float elapsedTime) {
if (!mDirection) {
// Only use path finding movement if no direct input movement active.
Character::move();
}
// Look towards crosshair.
setAngle(angle(mCrosshairPosition));
}
/**
* Stop movement if we collide with anything except bullets.
*/
void
Player::onCollide(Physical& other, uint16 category) {
if (category != CATEGORY_PARTICLE) {
setDestination(getPosition());
}
}

View file

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

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

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

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

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

View file

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

View file

@ -1,50 +1,50 @@
/*
* 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_ */
/*
* 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_ */

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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