diff --git a/source/Game.cpp b/source/Game.cpp index 247193d..43a0c68 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -9,7 +9,7 @@ #include -#include "abstract/Actor.h" +#include "abstract/Character.h" #include "sprite/Cover.h" #include "sprite/Enemy.h" #include "util/Loader.h" @@ -83,7 +83,7 @@ Game::loop() { input(); for (; !mPaused && (left >= TICKS_GOAL); left -= TICKS_GOAL) { - Actor::think(TICKS_GOAL); + Character::think(TICKS_GOAL); mWorld.Step(1.0f / FPS_GOAL, 8, 3); mCollection.checkDelete(); diff --git a/source/abstract/Actor.cpp b/source/abstract/Character.cpp old mode 100755 new mode 100644 similarity index 76% rename from source/abstract/Actor.cpp rename to source/abstract/Character.cpp index 764b918..c10b100 --- a/source/abstract/Actor.cpp +++ b/source/abstract/Character.cpp @@ -1,64 +1,64 @@ -/* - * Actor.cpp - * - * Created on: 02.09.2012 - * Author: Felix - */ - -#include "Actor.h" - -#include -#include - -std::vector Actor::mInstances = std::vector(); - -/** - * Saves pointer to this instance in static var for think(). +/* + * Actor.cpp + * + * Created on: 02.09.2012 + * Author: Felix */ -Actor::Actor(int health) : - mMaxHealth(health), + +#include "Character.h" + +#include +#include + +std::vector Character::mInstances = std::vector(); + +/** + * Saves pointer to this instance in static var for think(). + */ +Character::Character(int health) : + mMaxHealth(health), mCurrentHealth(health) { - mInstances.push_back(this); -} - -/** - * Deletes pointer from think() static var. - */ -Actor::~Actor() { - auto it = std::find(mInstances.begin(), mInstances.end(), this); - assert(it != mInstances.end()); - mInstances.erase(it); -} - -/** - * Calls onThink on all Actor instances. - * - * @param elapsedTime Amount of time to simulate. - */ -void -Actor::think(float elapsedTime) { - for (auto i : mInstances) { - i->onThink(elapsedTime); - } + mInstances.push_back(this); } - -/** - * Subtracts health from Actor. - * - * @param damage Amount of health to subtract. - */ -void -Actor::onDamage(int damage) { - mCurrentHealth -= damage; - if (mCurrentHealth <= 0) { - mCurrentHealth = 0; - onDeath(); - } -} - -/** - * Called when health reaches zero. Does nothing by default. - */ -void -Actor::onDeath() { + +/** + * Deletes pointer from think() static var. + */ +Character::~Character() { + auto it = std::find(mInstances.begin(), mInstances.end(), this); + assert(it != mInstances.end()); + mInstances.erase(it); +} + +/** + * Calls onThink on all Actor instances. + * + * @param elapsedTime Amount of time to simulate. + */ +void +Character::think(float elapsedTime) { + for (auto i : mInstances) { + i->onThink(elapsedTime); + } +} + +/** + * Subtracts health from Actor. + * + * @param damage Amount of health to subtract. + */ +void +Character::onDamage(int damage) { + mCurrentHealth -= damage; + if (mCurrentHealth <= 0) { + mCurrentHealth = 0; + onDeath(); + } +} + +/** + * Called when health reaches zero. Does nothing by default. + */ +void +Character::onDeath() { } diff --git a/source/abstract/Actor.h b/source/abstract/Character.h old mode 100755 new mode 100644 similarity index 82% rename from source/abstract/Actor.h rename to source/abstract/Character.h index 346def0..c898f02 --- a/source/abstract/Actor.h +++ b/source/abstract/Character.h @@ -1,45 +1,45 @@ -/* - * Actor.h - * - * Created on: 02.09.2012 - * Author: Felix - */ - -#ifndef DG_ACTOR_H_ -#define DG_ACTOR_H_ - -#include - -/** - * Provides think function for AI. - */ -class Actor { -// Public functions. +/* + * Actor.h + * + * Created on: 02.09.2012 + * Author: Felix + */ + +#ifndef DG_ACTOR_H_ +#define DG_ACTOR_H_ + +#include + +/** + * Provides think function for AI. + */ +class Character { +// Public functions. public: - Actor(int health); - virtual ~Actor() = 0; - - static void think(float elapsedTime); + Character(int health); + virtual ~Character() = 0; - void onDamage(int damage); + static void think(float elapsedTime); -// Protected functions. -protected: - /** - * Implement this function for any (regular) AI computations. - * - * @param elapsedTime Amount of time to simulate. - */ - virtual void onThink(float elapsedTime) = 0; + void onDamage(int damage); - virtual void onDeath(); - -// Private variables. -private: - static std::vector mInstances; - - const int mMaxHealth; +// Protected functions. +protected: + /** + * Implement this function for any (regular) AI computations. + * + * @param elapsedTime Amount of time to simulate. + */ + virtual void onThink(float elapsedTime) = 0; + + virtual void onDeath(); + +// Private variables. +private: + static std::vector mInstances; + + const int mMaxHealth; int mCurrentHealth; //< Current health. Between 0 and mMaxHealth. -}; - -#endif /* DG_ACTOR_H_ */ +}; + +#endif /* DG_ACTOR_H_ */ diff --git a/source/effects/Bullet.cpp b/source/effects/Bullet.cpp index 3c5c19b..5a24487 100755 --- a/source/effects/Bullet.cpp +++ b/source/effects/Bullet.cpp @@ -7,7 +7,7 @@ #include "Bullet.h" -#include "../abstract/Actor.h" +#include "../abstract/Character.h" const Vector2i Bullet::SIZE = Vector2i(20, 20); @@ -39,7 +39,7 @@ Bullet::onCollide(Physical& other, uint16 type) { if (!getDelete()) { // Call onShot on other, with damage as param. if (type == CATEGORY_ACTOR) { - Actor& a = dynamic_cast(other); + Character& a = dynamic_cast(other); a.onDamage(mDamage); } setDelete(true); diff --git a/source/sprite/Enemy.cpp b/source/sprite/Enemy.cpp index 49daf48..102730e 100644 --- a/source/sprite/Enemy.cpp +++ b/source/sprite/Enemy.cpp @@ -12,7 +12,7 @@ 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)), - Actor(100), + Character(100), mWorld(world), mCollection(collection) { diff --git a/source/sprite/Enemy.h b/source/sprite/Enemy.h index 964a1b6..2e40c0a 100644 --- a/source/sprite/Enemy.h +++ b/source/sprite/Enemy.h @@ -8,16 +8,16 @@ #ifndef DG_ENEMY_H_ #define DG_ENEMY_H -#include "../abstract/Actor.h" +#include "../abstract/Character.h" #include "../abstract/Sprite.h" #include "../util/Collection.h" #include "../util/Vector.h" -class Actor; +class Character; class Sprite; class Collection; -class Enemy : public Sprite, public Actor { +class Enemy : public Sprite, public Character { // Public functions. public: Enemy(b2World& world, const Vector2f& position, Collection& collection); diff --git a/source/sprite/Player.cpp b/source/sprite/Player.cpp index 915052f..59cfedd 100644 --- a/source/sprite/Player.cpp +++ b/source/sprite/Player.cpp @@ -23,7 +23,7 @@ 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)), - Actor(100), + Character(100), mWeapon(*this, collection, world, SIZE), mDirection(0), mPathfinder(pathfinder) { diff --git a/source/sprite/Player.h b/source/sprite/Player.h index ae9d71f..05b1092 100644 --- a/source/sprite/Player.h +++ b/source/sprite/Player.h @@ -12,12 +12,12 @@ #include #include "../Pathfinder.h" -#include "../abstract/Actor.h" +#include "../abstract/Character.h" #include "../abstract/Sprite.h" #include "../items/Weapon.h" #include "../util/Vector.h" -class Actor; +class Character; class Pathfinder; class Sprite; class Weapon; @@ -25,7 +25,7 @@ class Weapon; /** * Player object. */ -class Player : public Sprite, public Actor { +class Player : public Sprite, public Character { // Public types. public: /**