Renamed Actor to Character.
This commit is contained in:
parent
a5386c7682
commit
484bba13c8
8 changed files with 112 additions and 112 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Thor/Graphics.hpp>
|
||||
|
||||
#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();
|
||||
|
|
120
source/abstract/Actor.cpp → source/abstract/Character.cpp
Executable file → Normal file
120
source/abstract/Actor.cpp → source/abstract/Character.cpp
Executable file → Normal file
|
@ -1,64 +1,64 @@
|
|||
/*
|
||||
* Actor.cpp
|
||||
*
|
||||
* Created on: 02.09.2012
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#include "Actor.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
std::vector<Actor*> Actor::mInstances = std::vector<Actor*>();
|
||||
|
||||
/**
|
||||
* 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 <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
}
|
80
source/abstract/Actor.h → source/abstract/Character.h
Executable file → Normal file
80
source/abstract/Actor.h → source/abstract/Character.h
Executable file → Normal file
|
@ -1,45 +1,45 @@
|
|||
/*
|
||||
* Actor.h
|
||||
*
|
||||
* Created on: 02.09.2012
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#ifndef DG_ACTOR_H_
|
||||
#define DG_ACTOR_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* 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 <vector>
|
||||
|
||||
/**
|
||||
* 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<Actor*> 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<Character*> mInstances;
|
||||
|
||||
const int mMaxHealth;
|
||||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
||||
};
|
||||
|
||||
#endif /* DG_ACTOR_H_ */
|
||||
};
|
||||
|
||||
#endif /* DG_ACTOR_H_ */
|
|
@ -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<Actor&>(other);
|
||||
Character& a = dynamic_cast<Character&>(other);
|
||||
a.onDamage(mDamage);
|
||||
}
|
||||
setDelete(true);
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#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:
|
||||
/**
|
||||
|
|
Reference in a new issue