From 4067d351e5ce2f26d2f3202e4c50e9977e46ffcf Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 2 May 2013 13:31:26 +0200 Subject: [PATCH] Changed Character subclasses to not have config as parameter. --- source/Game.cpp | 2 +- source/abstract/Character.cpp | 2 +- source/sprites/Corpse.cpp | 8 ++++++-- source/sprites/Corpse.h | 7 ++++--- source/sprites/Enemy.cpp | 8 ++++++-- source/sprites/Enemy.h | 8 +++++--- source/sprites/Player.cpp | 8 ++++++-- source/sprites/Player.h | 5 +++-- 8 files changed, 32 insertions(+), 16 deletions(-) diff --git a/source/Game.cpp b/source/Game.cpp index 2b65e55..92aef4a 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -28,7 +28,7 @@ Game::Game(sf::RenderWindow& window) : mGenerator.generateTiles(sf::IntRect(-32, -32, 64, 64)); mPlayer = std::shared_ptr(new Player(mWorld, mPathfinder, - mGenerator.getPlayerSpawn(), Yaml("player.yaml"))); + mGenerator.getPlayerSpawn())); mWorld.insertCharacter(mPlayer); } diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index 3f7d718..c8e58c2 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -71,7 +71,7 @@ Character::onThink(int elapsed) { */ void Character::onDeath() { - mWorld.insert(std::shared_ptr(new Corpse(getPosition(), Yaml("body.yaml")))); + mWorld.insert(std::shared_ptr(new Corpse(getPosition()))); } /** diff --git a/source/sprites/Corpse.cpp b/source/sprites/Corpse.cpp index 0649928..5a6505d 100644 --- a/source/sprites/Corpse.cpp +++ b/source/sprites/Corpse.cpp @@ -7,7 +7,11 @@ #include "Corpse.h" -Corpse::Corpse(const sf::Vector2f& position, const Yaml& config) : - Sprite(Data(position, CATEGORY_NONSOLID, MASK_NONE), config) { +#include "../util/Yaml.h" + +const std::string Corpse::CONFIG = "corpse.yaml"; + +Corpse::Corpse(const sf::Vector2f& position) : + Sprite(Data(position, CATEGORY_NONSOLID, MASK_NONE), Yaml(CONFIG)) { } diff --git a/source/sprites/Corpse.h b/source/sprites/Corpse.h index 074e01b..5435dd1 100644 --- a/source/sprites/Corpse.h +++ b/source/sprites/Corpse.h @@ -10,11 +10,12 @@ #include "../abstract/Sprite.h" -class Yaml; - class Corpse : public Sprite { public: - explicit Corpse(const sf::Vector2f& position, const Yaml& config); + explicit Corpse(const sf::Vector2f& position); + +private: + static const std::string CONFIG; }; #endif /* DG_CORPSE_H_ */ diff --git a/source/sprites/Enemy.cpp b/source/sprites/Enemy.cpp index df7f63a..173000b 100644 --- a/source/sprites/Enemy.cpp +++ b/source/sprites/Enemy.cpp @@ -9,10 +9,14 @@ #include +#include "../util/Yaml.h" + +const std::string Enemy::CONFIG = "enemy.yaml"; + Enemy::Enemy(World& world, Pathfinder& pathfinder, - const sf::Vector2f& position, const Yaml& config) : + const sf::Vector2f& position) : Character(world, pathfinder, Data(position, CATEGORY_ACTOR, MASK_ALL), - config) { + Yaml(CONFIG)) { } void diff --git a/source/sprites/Enemy.h b/source/sprites/Enemy.h index 09f9077..d3dd5a4 100644 --- a/source/sprites/Enemy.h +++ b/source/sprites/Enemy.h @@ -11,15 +11,17 @@ #include "../abstract/Character.h" class World; -class Yaml; class Enemy : public Character { public: explicit Enemy(World& world, Pathfinder& pathfinder, - const sf::Vector2f& position, const Yaml& config); + const sf::Vector2f& position); -protected: +private: virtual void onThink(int elapsed); + +private: + static const std::string CONFIG; }; #endif /* DG_ENEMY_H_ */ diff --git a/source/sprites/Player.cpp b/source/sprites/Player.cpp index 34ffaea..3de5249 100644 --- a/source/sprites/Player.cpp +++ b/source/sprites/Player.cpp @@ -9,13 +9,17 @@ #include +#include "../util/Yaml.h" + +const std::string Player::CONFIG = "player.yaml"; + /** * Initializes Sprite. */ Player::Player(World& world, Pathfinder& pathfinder, - const sf::Vector2f& position, const Yaml& config) : + const sf::Vector2f& position) : Character(world, pathfinder, - Data(position, CATEGORY_ACTOR, MASK_ALL), config), + Data(position, CATEGORY_ACTOR, MASK_ALL), Yaml(CONFIG)), mDirection(0) { } diff --git a/source/sprites/Player.h b/source/sprites/Player.h index 7b66aff..c369016 100644 --- a/source/sprites/Player.h +++ b/source/sprites/Player.h @@ -10,7 +10,6 @@ #include "../abstract/Character.h" -class Yaml; class World; /** @@ -30,7 +29,7 @@ public: public: explicit Player(World& world, Pathfinder& pathfinder, - const sf::Vector2f& position, const Yaml& config); + const sf::Vector2f& position); void setCrosshairPosition(const sf::Vector2f& position); void pullTrigger(); @@ -42,6 +41,8 @@ private: void onThink(int elapsed); private: + static const std::string CONFIG; + sf::Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor). unsigned char mDirection; //< Current movement direction for direct control. };