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

View file

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

View file

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

View file

@ -9,15 +9,13 @@
#define DG_ENEMY_H
#include "../abstract/Character.h"
#include "../abstract/Sprite.h"
#include "../util/Collection.h"
#include "../util/Vector.h"
class Character;
class Sprite;
class Collection;
class Enemy : public Sprite, public Character {
class Enemy : public Character {
// Public functions.
public:
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,
Pathfinder& pathfinder) :
Sprite("player.png", PhysicalData(position, SIZE, world,
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
Character(100),
Character("player.png", PhysicalData(position, SIZE, world,
CATEGORY_ACTOR, MASK_ALL, true, false, true), 100),
mWeapon(*this, collection, world, SIZE),
mDirection(0),
mPathfinder(pathfinder) {

View file

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