Made Character a subclass of Sprite.
This commit is contained in:
parent
484bba13c8
commit
f4bb9a5dae
6 changed files with 17 additions and 18 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
Reference in a new issue