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 <Thor/Graphics.hpp>
|
||||||
|
|
||||||
#include "abstract/Actor.h"
|
#include "abstract/Character.h"
|
||||||
#include "sprite/Cover.h"
|
#include "sprite/Cover.h"
|
||||||
#include "sprite/Enemy.h"
|
#include "sprite/Enemy.h"
|
||||||
#include "util/Loader.h"
|
#include "util/Loader.h"
|
||||||
|
@ -83,7 +83,7 @@ Game::loop() {
|
||||||
input();
|
input();
|
||||||
|
|
||||||
for (; !mPaused && (left >= TICKS_GOAL); left -= TICKS_GOAL) {
|
for (; !mPaused && (left >= TICKS_GOAL); left -= TICKS_GOAL) {
|
||||||
Actor::think(TICKS_GOAL);
|
Character::think(TICKS_GOAL);
|
||||||
mWorld.Step(1.0f / FPS_GOAL, 8, 3);
|
mWorld.Step(1.0f / FPS_GOAL, 8, 3);
|
||||||
|
|
||||||
mCollection.checkDelete();
|
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
|
* Author: Felix
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Actor.h"
|
#include "Character.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <assert.h>
|
#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().
|
* Saves pointer to this instance in static var for think().
|
||||||
*/
|
*/
|
||||||
Actor::Actor(int health) :
|
Character::Character(int health) :
|
||||||
mMaxHealth(health),
|
mMaxHealth(health),
|
||||||
mCurrentHealth(health) {
|
mCurrentHealth(health) {
|
||||||
mInstances.push_back(this);
|
mInstances.push_back(this);
|
||||||
|
@ -24,7 +24,7 @@ Actor::Actor(int health) :
|
||||||
/**
|
/**
|
||||||
* Deletes pointer from think() static var.
|
* Deletes pointer from think() static var.
|
||||||
*/
|
*/
|
||||||
Actor::~Actor() {
|
Character::~Character() {
|
||||||
auto it = std::find(mInstances.begin(), mInstances.end(), this);
|
auto it = std::find(mInstances.begin(), mInstances.end(), this);
|
||||||
assert(it != mInstances.end());
|
assert(it != mInstances.end());
|
||||||
mInstances.erase(it);
|
mInstances.erase(it);
|
||||||
|
@ -36,7 +36,7 @@ Actor::~Actor() {
|
||||||
* @param elapsedTime Amount of time to simulate.
|
* @param elapsedTime Amount of time to simulate.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Actor::think(float elapsedTime) {
|
Character::think(float elapsedTime) {
|
||||||
for (auto i : mInstances) {
|
for (auto i : mInstances) {
|
||||||
i->onThink(elapsedTime);
|
i->onThink(elapsedTime);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ Actor::think(float elapsedTime) {
|
||||||
* @param damage Amount of health to subtract.
|
* @param damage Amount of health to subtract.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Actor::onDamage(int damage) {
|
Character::onDamage(int damage) {
|
||||||
mCurrentHealth -= damage;
|
mCurrentHealth -= damage;
|
||||||
if (mCurrentHealth <= 0) {
|
if (mCurrentHealth <= 0) {
|
||||||
mCurrentHealth = 0;
|
mCurrentHealth = 0;
|
||||||
|
@ -60,5 +60,5 @@ Actor::onDamage(int damage) {
|
||||||
* Called when health reaches zero. Does nothing by default.
|
* Called when health reaches zero. Does nothing by default.
|
||||||
*/
|
*/
|
||||||
void
|
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.
|
* Provides think function for AI.
|
||||||
*/
|
*/
|
||||||
class Actor {
|
class Character {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Actor(int health);
|
Character(int health);
|
||||||
virtual ~Actor() = 0;
|
virtual ~Character() = 0;
|
||||||
|
|
||||||
static void think(float elapsedTime);
|
static void think(float elapsedTime);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ protected:
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
static std::vector<Actor*> mInstances;
|
static std::vector<Character*> mInstances;
|
||||||
|
|
||||||
const int mMaxHealth;
|
const int mMaxHealth;
|
||||||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
|
|
||||||
#include "../abstract/Actor.h"
|
#include "../abstract/Character.h"
|
||||||
|
|
||||||
const Vector2i Bullet::SIZE = Vector2i(20, 20);
|
const Vector2i Bullet::SIZE = Vector2i(20, 20);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ Bullet::onCollide(Physical& other, uint16 type) {
|
||||||
if (!getDelete()) {
|
if (!getDelete()) {
|
||||||
// Call onShot on other, with damage as param.
|
// Call onShot on other, with damage as param.
|
||||||
if (type == CATEGORY_ACTOR) {
|
if (type == CATEGORY_ACTOR) {
|
||||||
Actor& a = dynamic_cast<Actor&>(other);
|
Character& a = dynamic_cast<Character&>(other);
|
||||||
a.onDamage(mDamage);
|
a.onDamage(mDamage);
|
||||||
}
|
}
|
||||||
setDelete(true);
|
setDelete(true);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
Enemy::Enemy(b2World& world, const Vector2f& position, Collection& collection) :
|
Enemy::Enemy(b2World& world, const Vector2f& position, Collection& collection) :
|
||||||
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
|
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
|
||||||
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
|
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
|
||||||
Actor(100),
|
Character(100),
|
||||||
mWorld(world),
|
mWorld(world),
|
||||||
mCollection(collection) {
|
mCollection(collection) {
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,16 @@
|
||||||
#ifndef DG_ENEMY_H_
|
#ifndef DG_ENEMY_H_
|
||||||
#define DG_ENEMY_H
|
#define DG_ENEMY_H
|
||||||
|
|
||||||
#include "../abstract/Actor.h"
|
#include "../abstract/Character.h"
|
||||||
#include "../abstract/Sprite.h"
|
#include "../abstract/Sprite.h"
|
||||||
#include "../util/Collection.h"
|
#include "../util/Collection.h"
|
||||||
#include "../util/Vector.h"
|
#include "../util/Vector.h"
|
||||||
|
|
||||||
class Actor;
|
class Character;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Collection;
|
class Collection;
|
||||||
|
|
||||||
class Enemy : public Sprite, public Actor {
|
class Enemy : public Sprite, public Character {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Enemy(b2World& world, const Vector2f& position, Collection& collection);
|
Enemy(b2World& world, const Vector2f& position, Collection& collection);
|
||||||
|
|
|
@ -23,7 +23,7 @@ Player::Player(b2World& world, Collection& collection, const Vector2f& position,
|
||||||
Pathfinder& pathfinder) :
|
Pathfinder& pathfinder) :
|
||||||
Sprite("player.png", PhysicalData(position, SIZE, world,
|
Sprite("player.png", PhysicalData(position, SIZE, world,
|
||||||
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
|
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
|
||||||
Actor(100),
|
Character(100),
|
||||||
mWeapon(*this, collection, world, SIZE),
|
mWeapon(*this, collection, world, SIZE),
|
||||||
mDirection(0),
|
mDirection(0),
|
||||||
mPathfinder(pathfinder) {
|
mPathfinder(pathfinder) {
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
#include "../Pathfinder.h"
|
#include "../Pathfinder.h"
|
||||||
#include "../abstract/Actor.h"
|
#include "../abstract/Character.h"
|
||||||
#include "../abstract/Sprite.h"
|
#include "../abstract/Sprite.h"
|
||||||
#include "../items/Weapon.h"
|
#include "../items/Weapon.h"
|
||||||
#include "../util/Vector.h"
|
#include "../util/Vector.h"
|
||||||
|
|
||||||
class Actor;
|
class Character;
|
||||||
class Pathfinder;
|
class Pathfinder;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Weapon;
|
class Weapon;
|
||||||
|
@ -25,7 +25,7 @@ class Weapon;
|
||||||
/**
|
/**
|
||||||
* Player object.
|
* Player object.
|
||||||
*/
|
*/
|
||||||
class Player : public Sprite, public Actor {
|
class Player : public Sprite, public Character {
|
||||||
// Public types.
|
// Public types.
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue