Added Yaml config to all Sprite subclasses (except tiles).
This commit is contained in:
parent
f23f2225db
commit
c93a6b0c9e
14 changed files with 38 additions and 22 deletions
|
@ -61,11 +61,11 @@ Game::generate() {
|
||||||
|
|
||||||
Instances instances(mPathfinder, mTileManager, mCollection, mWorld);
|
Instances instances(mPathfinder, mTileManager, mCollection, mWorld);
|
||||||
|
|
||||||
mCollection.insert(std::shared_ptr<Sprite>(new Enemy(instances, Vector2f(400.0f, 200.0f))));
|
mCollection.insert(std::shared_ptr<Sprite>(new Enemy(instances, Vector2f(400.0f, 200.0f), Yaml("enemy.yaml"))));
|
||||||
mCollection.insert(std::shared_ptr<Sprite>(new Cover(Vector2f(300, 200), Vector2i(100, 150),
|
mCollection.insert(std::shared_ptr<Sprite>(new Cover(Vector2f(300, 200), Vector2i(100, 150),
|
||||||
mWorld)));
|
mWorld, Yaml("cover.yaml"))));
|
||||||
|
|
||||||
mPlayer = std::unique_ptr<Player>(new Player(instances, Vector2f(200.0f, 100.0f)));
|
mPlayer = std::unique_ptr<Player>(new Player(instances, Vector2f(200.0f, 100.0f), Yaml("player.yaml")));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Closes window.
|
* Closes window.
|
||||||
|
|
|
@ -12,16 +12,17 @@
|
||||||
|
|
||||||
#include "../sprite/Body.h"
|
#include "../sprite/Body.h"
|
||||||
|
|
||||||
|
const String Character::KEY_HEALTH = "health";
|
||||||
std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>();
|
std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves pointer to this instance in static var for think().
|
* Saves pointer to this instance in static var for think().
|
||||||
*/
|
*/
|
||||||
Character::Character(const Instances& instances, const String& texturePath,
|
Character::Character(const Instances& instances, const String& texturePath,
|
||||||
const PhysicalData& data, int health) :
|
const PhysicalData& data, const Yaml& config) :
|
||||||
Sprite(texturePath, data),
|
Sprite(texturePath, data),
|
||||||
mMaxHealth(health),
|
mMaxHealth(config.get<int>(KEY_HEALTH)),
|
||||||
mCurrentHealth(health),
|
mCurrentHealth(mMaxHealth),
|
||||||
mInstances(instances) {
|
mInstances(instances) {
|
||||||
mCharacterInstances.push_back(this);
|
mCharacterInstances.push_back(this);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +37,7 @@ Character::~Character() {
|
||||||
mCharacterInstances.erase(it);
|
mCharacterInstances.erase(it);
|
||||||
|
|
||||||
mInstances.collection.insert(std::shared_ptr<Sprite>(new Body(mInstances.world,
|
mInstances.collection.insert(std::shared_ptr<Sprite>(new Body(mInstances.world,
|
||||||
getPosition())));
|
getPosition(), Yaml("body.yaml"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
#include "Sprite.h"
|
#include "Sprite.h"
|
||||||
#include "../Instances.h"
|
#include "../Instances.h"
|
||||||
#include "../util/String.h"
|
#include "../util/String.h"
|
||||||
|
#include "../util/Yaml.h"
|
||||||
|
|
||||||
class Instances;
|
class Instances;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
class Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides think function for AI, manages health, drops body on death.
|
* Provides think function for AI, manages health, drops body on death.
|
||||||
|
@ -24,7 +26,7 @@ class Character : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Character(const Instances& instances, const String& texturePath,
|
Character(const Instances& instances, const String& texturePath,
|
||||||
const PhysicalData& data, int health);
|
const PhysicalData& data, const Yaml& config);
|
||||||
virtual ~Character() = 0;
|
virtual ~Character() = 0;
|
||||||
|
|
||||||
static void think(float elapsedTime);
|
static void think(float elapsedTime);
|
||||||
|
@ -38,6 +40,8 @@ protected:
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
|
static const String KEY_HEALTH;
|
||||||
|
|
||||||
static std::vector<Character*> mCharacterInstances;
|
static std::vector<Character*> mCharacterInstances;
|
||||||
|
|
||||||
const int mMaxHealth;
|
const int mMaxHealth;
|
||||||
|
|
|
@ -26,7 +26,7 @@ Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, floa
|
||||||
const Yaml& config) :
|
const Yaml& config) :
|
||||||
Particle(ResourceManager::i().acquire(Loader::i().fromFile<sf::Texture>("bullet.png")),
|
Particle(ResourceManager::i().acquire(Loader::i().fromFile<sf::Texture>("bullet.png")),
|
||||||
PhysicalData(position, SIZE, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
|
PhysicalData(position, SIZE, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
|
||||||
true, true, true)),
|
true, true, true), config),
|
||||||
mShooter(shooter),
|
mShooter(shooter),
|
||||||
mDamage(config.get<int>(KEY_DAMAGE)),
|
mDamage(config.get<int>(KEY_DAMAGE)),
|
||||||
mSpeed(config.get<int>(KEY_SPEED)) {
|
mSpeed(config.get<int>(KEY_SPEED)) {
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
|
|
||||||
Particle::Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data) :
|
Particle::Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data,
|
||||||
|
const Yaml& config) :
|
||||||
Sprite(texture, data) {
|
Sprite(texture, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
#define DG_PARTICLE_H_
|
#define DG_PARTICLE_H_
|
||||||
|
|
||||||
#include "../abstract/Sprite.h"
|
#include "../abstract/Sprite.h"
|
||||||
|
#include "../util/Yaml.h"
|
||||||
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
class Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prototype for a particle.
|
* Prototype for a particle.
|
||||||
|
@ -18,7 +20,8 @@ class Sprite;
|
||||||
class Particle : public Sprite {
|
class Particle : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data);
|
Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data,
|
||||||
|
const Yaml& config);
|
||||||
virtual ~Particle();
|
virtual ~Particle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "Body.h"
|
#include "Body.h"
|
||||||
|
|
||||||
Body::Body(b2World& world, const Vector2f& position) :
|
Body::Body(b2World& world, const Vector2f& position, const Yaml& config) :
|
||||||
Sprite("body.png", PhysicalData(position, Vector2i(50, 50), world,
|
Sprite("body.png", PhysicalData(position, Vector2i(50, 50), world,
|
||||||
CATEGORY_NONSOLID, MASK_NONE, false)) {
|
CATEGORY_NONSOLID, MASK_NONE, false)) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,15 @@
|
||||||
#define DG_BODY_H_
|
#define DG_BODY_H_
|
||||||
|
|
||||||
#include "../abstract/Sprite.h"
|
#include "../abstract/Sprite.h"
|
||||||
|
#include "../util/Yaml.h"
|
||||||
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
class Yaml;
|
||||||
|
|
||||||
class Body : public Sprite {
|
class Body : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Body(b2World& world, const Vector2f& position);
|
Body(b2World& world, const Vector2f& position, const Yaml& config);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DG_BODY_H_ */
|
#endif /* DG_BODY_H_ */
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "Cover.h"
|
#include "Cover.h"
|
||||||
|
|
||||||
Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world) :
|
Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) :
|
||||||
Sprite("cover.png", PhysicalData(position, size, world, CATEGORY_WORLD, MASK_ALL, false)) {
|
Sprite("cover.png", PhysicalData(position, size, world, CATEGORY_WORLD, MASK_ALL, false)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
#define DG_COVER_H_
|
#define DG_COVER_H_
|
||||||
|
|
||||||
#include "../abstract/Sprite.h"
|
#include "../abstract/Sprite.h"
|
||||||
|
#include "../util/Yaml.h"
|
||||||
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
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.
|
||||||
|
@ -18,7 +20,7 @@ class Sprite;
|
||||||
class Cover : public Sprite {
|
class Cover : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Cover(const Vector2f& position, const Vector2i& size, b2World& world);
|
Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DG_COVER_H_ */
|
#endif /* DG_COVER_H_ */
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
#include "Body.h"
|
#include "Body.h"
|
||||||
|
|
||||||
Enemy::Enemy(const Instances& instances, const Vector2f& position) :
|
Enemy::Enemy(const Instances& instances, const Vector2f& position, const Yaml& config) :
|
||||||
Character(instances, "enemy.png", PhysicalData(position, Vector2i(50, 50), instances.world,
|
Character(instances, "enemy.png", PhysicalData(position, Vector2i(50, 50), instances.world,
|
||||||
CATEGORY_ACTOR, MASK_ALL, true, false, true), 100),
|
CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
|
||||||
mWorld(instances.world),
|
mWorld(instances.world),
|
||||||
mCollection(instances.collection) {
|
mCollection(instances.collection) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,17 @@
|
||||||
#include "../abstract/Character.h"
|
#include "../abstract/Character.h"
|
||||||
#include "../util/Collection.h"
|
#include "../util/Collection.h"
|
||||||
#include "../util/Vector.h"
|
#include "../util/Vector.h"
|
||||||
|
#include "../util/Yaml.h"
|
||||||
|
|
||||||
class Character;
|
class Character;
|
||||||
class Collection;
|
class Collection;
|
||||||
class Instances;
|
class Instances;
|
||||||
|
class Yaml;
|
||||||
|
|
||||||
class Enemy : public Character {
|
class Enemy : public Character {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Enemy(const Instances& instances, const Vector2f& position);
|
Enemy(const Instances& instances, const Vector2f& position, const Yaml& config);
|
||||||
|
|
||||||
// Private functions.
|
// Private functions.
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "../util/Vector.h"
|
#include "../util/Vector.h"
|
||||||
#include "../items/Weapon.h"
|
#include "../items/Weapon.h"
|
||||||
#include "../util/String.h"
|
#include "../util/String.h"
|
||||||
#include "../util/Yaml.h"
|
|
||||||
|
|
||||||
const float Player::SPEED = 100.0f;
|
const float Player::SPEED = 100.0f;
|
||||||
const Vector2i Player::SIZE = Vector2i(50, 50);
|
const Vector2i Player::SIZE = Vector2i(50, 50);
|
||||||
|
@ -21,9 +20,9 @@ const float Player::POINT_REACHED_DISTANCE = 1.0f;
|
||||||
/**
|
/**
|
||||||
* Initializes Sprite.
|
* Initializes Sprite.
|
||||||
*/
|
*/
|
||||||
Player::Player(const Instances& instances, const Vector2f& position) :
|
Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) :
|
||||||
Character(instances, "player.png", PhysicalData(position, SIZE, instances.world,
|
Character(instances, "player.png", PhysicalData(position, SIZE, instances.world,
|
||||||
CATEGORY_ACTOR, MASK_ALL, true, false, true), 100),
|
CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
|
||||||
mWeapon(instances, *this, Yaml("weapon.yaml")),
|
mWeapon(instances, *this, Yaml("weapon.yaml")),
|
||||||
mDirection(0),
|
mDirection(0),
|
||||||
mPathfinder(instances.pathfinder) {
|
mPathfinder(instances.pathfinder) {
|
||||||
|
|
|
@ -16,11 +16,13 @@
|
||||||
#include "../abstract/Character.h"
|
#include "../abstract/Character.h"
|
||||||
#include "../items/Weapon.h"
|
#include "../items/Weapon.h"
|
||||||
#include "../util/Vector.h"
|
#include "../util/Vector.h"
|
||||||
|
#include "../util/Yaml.h"
|
||||||
|
|
||||||
class Character;
|
class Character;
|
||||||
class Instances;
|
class Instances;
|
||||||
class Pathfinder;
|
class Pathfinder;
|
||||||
class Weapon;
|
class Weapon;
|
||||||
|
class Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player object.
|
* Player object.
|
||||||
|
@ -40,7 +42,7 @@ public:
|
||||||
|
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Player(const Instances& instances, const Vector2f& position);
|
Player(const Instances& instances, const Vector2f& position, const Yaml& config);
|
||||||
|
|
||||||
void setCrosshairPosition(const Vector2f& position);
|
void setCrosshairPosition(const Vector2f& position);
|
||||||
void fire();
|
void fire();
|
||||||
|
|
Reference in a new issue