From 1f3c1f32f4d5c37820b20f8477d442384a74fec0 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 16 Nov 2014 22:40:13 +1100 Subject: [PATCH] Moved 'renderable' stuff to 'entities' --- .../base_character.cpp | 0 .../base_character.hpp | 4 +- .../{renderable => entities}/base_monster.cpp | 0 .../{renderable => entities}/base_monster.hpp | 4 +- .../renderable.cpp => entities/entity.cpp} | 37 ++++++++++++++-- .../renderable.hpp => entities/entity.hpp} | 38 +++++++++------- client/{renderable => entities}/makefile | 0 client/renderable/local_character.cpp | 23 ---------- client/renderable/local_character.hpp | 44 ------------------- 9 files changed, 60 insertions(+), 90 deletions(-) rename client/{renderable => entities}/base_character.cpp (100%) rename client/{renderable => entities}/base_character.hpp (95%) rename client/{renderable => entities}/base_monster.cpp (100%) rename client/{renderable => entities}/base_monster.hpp (94%) rename client/{renderable/renderable.cpp => entities/entity.cpp} (64%) rename client/{renderable/renderable.hpp => entities/entity.hpp} (73%) rename client/{renderable => entities}/makefile (100%) delete mode 100644 client/renderable/local_character.cpp delete mode 100644 client/renderable/local_character.hpp diff --git a/client/renderable/base_character.cpp b/client/entities/base_character.cpp similarity index 100% rename from client/renderable/base_character.cpp rename to client/entities/base_character.cpp diff --git a/client/renderable/base_character.hpp b/client/entities/base_character.hpp similarity index 95% rename from client/renderable/base_character.hpp rename to client/entities/base_character.hpp index 1531ba3..8c44ce3 100644 --- a/client/renderable/base_character.hpp +++ b/client/entities/base_character.hpp @@ -24,12 +24,12 @@ //components #include "character_defines.hpp" -#include "renderable.hpp" +#include "entity.hpp" //std namespace #include -class BaseCharacter : public Renderable { +class BaseCharacter : public Entity { public: BaseCharacter() = default; virtual ~BaseCharacter() = default; diff --git a/client/renderable/base_monster.cpp b/client/entities/base_monster.cpp similarity index 100% rename from client/renderable/base_monster.cpp rename to client/entities/base_monster.cpp diff --git a/client/renderable/base_monster.hpp b/client/entities/base_monster.hpp similarity index 94% rename from client/renderable/base_monster.hpp rename to client/entities/base_monster.hpp index 15cea7d..ddcc876 100644 --- a/client/renderable/base_monster.hpp +++ b/client/entities/base_monster.hpp @@ -22,9 +22,9 @@ #ifndef BASEMONSTER_HPP_ #define BASEMONSTER_HPP_ -#include "renderable.hpp" +#include "entity.hpp" -class BaseMonster { +class BaseMonster : public Entity { public: BaseMonster() = default; virtual ~BaseMonster() = default; diff --git a/client/renderable/renderable.cpp b/client/entities/entity.cpp similarity index 64% rename from client/renderable/renderable.cpp rename to client/entities/entity.cpp index 46d319d..5509604 100644 --- a/client/renderable/renderable.cpp +++ b/client/entities/entity.cpp @@ -19,13 +19,44 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "renderable.hpp" +#include "entity.hpp" -void Renderable::Update() { +void Entity::Update() { origin += motion; sprite.Update(0.016); } -void Renderable::DrawTo(SDL_Surface* const dest, int camX, int camY) { +void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, origin.x - camX, origin.y - camY); +} + +int Entity::SetEntityIndex(int i) { + return entityIndex = i; +} + +int Entity::SetRoomIndex(int i) { + return roomIndex = i; +} + +Vector2 Entity::SetOrigin(Vector2 v) { + return origin = v; +} + +Vector2 Entity::SetMotion(Vector2 v) { + return motion = v; +} +int Entity::GetEntityIndex() { + return entityIndex; +} + +int Entity::GetRoomIndex() { + return roomIndex; +} + +Vector2 Entity::GetOrigin() { + return origin; +} + +Vector2 Entity::GetMotion() { + return motion; } \ No newline at end of file diff --git a/client/renderable/renderable.hpp b/client/entities/entity.hpp similarity index 73% rename from client/renderable/renderable.hpp rename to client/entities/entity.hpp index d78cde2..a73d3eb 100644 --- a/client/renderable/renderable.hpp +++ b/client/entities/entity.hpp @@ -19,37 +19,43 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef RENDERABLE_HPP_ -#define RENDERABLE_HPP_ +#ifndef ENTITY_HPP_ +#define ENTITY_HPP_ #include "bounding_box.hpp" #include "sprite_sheet.hpp" #include "vector2.hpp" -class Renderable { +//The base class for all objects in the world +class Entity { public: - Renderable() = default; - virtual ~Renderable() = default; - virtual void Update(); virtual void DrawTo(SDL_Surface* const, int camX, int camY); SpriteSheet* GetSprite() { return &sprite; } - //position - Vector2 SetOrigin(Vector2 v) { return origin = v; } - Vector2 GetOrigin() const { return origin; } - Vector2 SetMotion(Vector2 v) { return motion = v; } - Vector2 GetMotion() const { return motion; } - - //collision + //accessors & mutators + int SetEntityIndex(int i); + int SetRoomIndex(int i); + Vector2 SetOrigin(Vector2 v); + Vector2 SetMotion(Vector2 v); BoundingBox SetBounds(BoundingBox b) { return bounds = b; } + + int GetEntityIndex(); + int GetRoomIndex(); + Vector2 GetOrigin(); + Vector2 GetMotion(); BoundingBox GetBounds() { return bounds; } -protected: //TODO: should be private +protected: + Entity() = default; + ~Entity() = default; + SpriteSheet sprite; - Vector2 origin = {0, 0}; - Vector2 motion = {0, 0}; + int entityIndex = -1; + int roomIndex = -1; + Vector2 origin; + Vector2 motion; BoundingBox bounds; }; diff --git a/client/renderable/makefile b/client/entities/makefile similarity index 100% rename from client/renderable/makefile rename to client/entities/makefile diff --git a/client/renderable/local_character.cpp b/client/renderable/local_character.cpp deleted file mode 100644 index 211a6bc..0000000 --- a/client/renderable/local_character.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "local_character.hpp" - diff --git a/client/renderable/local_character.hpp b/client/renderable/local_character.hpp deleted file mode 100644 index 37e90de..0000000 --- a/client/renderable/local_character.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef LOCALCHARACTER_HPP_ -#define LOCALCHARACTER_HPP_ - -#include "base_character.hpp" -#include "statistics.hpp" - -class LocalCharacter : public BaseCharacter { -public: - LocalCharacter() = default; - ~LocalCharacter() = default; - - int SetRoomIndex(int i) { return roomIndex = i; } - int GetRoomIndex() { return roomIndex; } - - Statistics* GetBaseStats() { return &baseStats; } - -private: - int roomIndex = -1; - Statistics baseStats; - //TODO: weapons, armour, buffs, debuffs, etc. -}; - -#endif