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();
|
||||
|
|
14
source/abstract/Actor.cpp → source/abstract/Character.cpp
Executable file → Normal file
14
source/abstract/Actor.cpp → source/abstract/Character.cpp
Executable file → Normal file
|
@ -5,17 +5,17 @@
|
|||
* Author: Felix
|
||||
*/
|
||||
|
||||
#include "Actor.h"
|
||||
#include "Character.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
std::vector<Actor*> Actor::mInstances = std::vector<Actor*>();
|
||||
std::vector<Character*> Character::mInstances = std::vector<Character*>();
|
||||
|
||||
/**
|
||||
* Saves pointer to this instance in static var for think().
|
||||
*/
|
||||
Actor::Actor(int health) :
|
||||
Character::Character(int health) :
|
||||
mMaxHealth(health),
|
||||
mCurrentHealth(health) {
|
||||
mInstances.push_back(this);
|
||||
|
@ -24,7 +24,7 @@ Actor::Actor(int health) :
|
|||
/**
|
||||
* Deletes pointer from think() static var.
|
||||
*/
|
||||
Actor::~Actor() {
|
||||
Character::~Character() {
|
||||
auto it = std::find(mInstances.begin(), mInstances.end(), this);
|
||||
assert(it != mInstances.end());
|
||||
mInstances.erase(it);
|
||||
|
@ -36,7 +36,7 @@ Actor::~Actor() {
|
|||
* @param elapsedTime Amount of time to simulate.
|
||||
*/
|
||||
void
|
||||
Actor::think(float elapsedTime) {
|
||||
Character::think(float elapsedTime) {
|
||||
for (auto i : mInstances) {
|
||||
i->onThink(elapsedTime);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ Actor::think(float elapsedTime) {
|
|||
* @param damage Amount of health to subtract.
|
||||
*/
|
||||
void
|
||||
Actor::onDamage(int damage) {
|
||||
Character::onDamage(int damage) {
|
||||
mCurrentHealth -= damage;
|
||||
if (mCurrentHealth <= 0) {
|
||||
mCurrentHealth = 0;
|
||||
|
@ -60,5 +60,5 @@ Actor::onDamage(int damage) {
|
|||
* Called when health reaches zero. Does nothing by default.
|
||||
*/
|
||||
void
|
||||
Actor::onDeath() {
|
||||
Character::onDeath() {
|
||||
}
|
8
source/abstract/Actor.h → source/abstract/Character.h
Executable file → Normal file
8
source/abstract/Actor.h → source/abstract/Character.h
Executable file → Normal file
|
@ -13,11 +13,11 @@
|
|||
/**
|
||||
* Provides think function for AI.
|
||||
*/
|
||||
class Actor {
|
||||
class Character {
|
||||
// Public functions.
|
||||
public:
|
||||
Actor(int health);
|
||||
virtual ~Actor() = 0;
|
||||
Character(int health);
|
||||
virtual ~Character() = 0;
|
||||
|
||||
static void think(float elapsedTime);
|
||||
|
||||
|
@ -36,7 +36,7 @@ protected:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
static std::vector<Actor*> mInstances;
|
||||
static std::vector<Character*> mInstances;
|
||||
|
||||
const int mMaxHealth;
|
||||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
|
@ -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