Made Character a subclass of Sprite.

This commit is contained in:
Felix Ableitner 2012-10-01 11:13:26 +02:00
parent 484bba13c8
commit f4bb9a5dae
6 changed files with 17 additions and 18 deletions

View file

@ -15,10 +15,11 @@ std::vector<Character*> Character::mInstances = 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(int health) : Character::Character(const sf::String& texturePath, const PhysicalData& data, int health) :
mMaxHealth(health), Sprite(texturePath, data),
mCurrentHealth(health) { mMaxHealth(health),
mInstances.push_back(this); mCurrentHealth(health) {
mInstances.push_back(this);
} }
/** /**

View file

@ -10,13 +10,17 @@
#include <vector> #include <vector>
#include "Sprite.h"
class Sprite;
/** /**
* Provides think function for AI. * Provides think function for AI.
*/ */
class Character { class Character : public Sprite {
// Public functions. // Public functions.
public: public:
Character(int health); Character(const sf::String& texturePath, const PhysicalData& data, int health);
virtual ~Character() = 0; virtual ~Character() = 0;
static void think(float elapsedTime); static void think(float elapsedTime);

View file

@ -10,9 +10,8 @@
#include "Body.h" #include "Body.h"
Enemy::Enemy(b2World& world, const Vector2f& position, Collection& collection) : Enemy::Enemy(b2World& world, const Vector2f& position, Collection& collection) :
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world, Character("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
CATEGORY_ACTOR, MASK_ALL, true, false, true)), CATEGORY_ACTOR, MASK_ALL, true, false, true), 100),
Character(100),
mWorld(world), mWorld(world),
mCollection(collection) { mCollection(collection) {

View file

@ -9,15 +9,13 @@
#define DG_ENEMY_H #define DG_ENEMY_H
#include "../abstract/Character.h" #include "../abstract/Character.h"
#include "../abstract/Sprite.h"
#include "../util/Collection.h" #include "../util/Collection.h"
#include "../util/Vector.h" #include "../util/Vector.h"
class Character; class Character;
class Sprite;
class Collection; class Collection;
class Enemy : public Sprite, public Character { class Enemy : public Character {
// Public functions. // Public functions.
public: public:
Enemy(b2World& world, const Vector2f& position, Collection& collection); Enemy(b2World& world, const Vector2f& position, Collection& collection);

View file

@ -21,9 +21,8 @@ const float Player::POINT_REACHED_DISTANCE = 1.0f;
*/ */
Player::Player(b2World& world, Collection& collection, const Vector2f& position, Player::Player(b2World& world, Collection& collection, const Vector2f& position,
Pathfinder& pathfinder) : Pathfinder& pathfinder) :
Sprite("player.png", PhysicalData(position, SIZE, world, Character("player.png", PhysicalData(position, SIZE, world,
CATEGORY_ACTOR, MASK_ALL, true, false, true)), CATEGORY_ACTOR, MASK_ALL, true, false, true), 100),
Character(100),
mWeapon(*this, collection, world, SIZE), mWeapon(*this, collection, world, SIZE),
mDirection(0), mDirection(0),
mPathfinder(pathfinder) { mPathfinder(pathfinder) {

View file

@ -13,19 +13,17 @@
#include "../Pathfinder.h" #include "../Pathfinder.h"
#include "../abstract/Character.h" #include "../abstract/Character.h"
#include "../abstract/Sprite.h"
#include "../items/Weapon.h" #include "../items/Weapon.h"
#include "../util/Vector.h" #include "../util/Vector.h"
class Character; class Character;
class Pathfinder; class Pathfinder;
class Sprite;
class Weapon; class Weapon;
/** /**
* Player object. * Player object.
*/ */
class Player : public Sprite, public Character { class Player : public Character {
// Public types. // Public types.
public: public:
/** /**