diff --git a/docs/diagrams/classes.svg b/docs/diagrams/classes.svg
index f1154c0..d68ab02 100644
--- a/docs/diagrams/classes.svg
+++ b/docs/diagrams/classes.svg
@@ -1 +1 @@
-Game Game() : void ~Game() : void addTile(int id, int x, int y) : void clean() : void getWinner() : bool handleEvents() : void init(const char * title, int xpos, int ypos, int width, int height, bool fullscreen) : void render() : void running() const : bool update() : void assets : AssetManager * colliders : std::vector<ColliderComponent *> counter : int event : SDL_Event isRunning : bool renderer : SDL_Renderer * window : SDL_Window * winner : bool cmp_str operator()(const char * a, const char * b) const : bool TextureManager TextureManager() : void TextureManager(const TextureManager &) = deleted : void ~TextureManager() : void operator=(const TextureManager &) = deleted : void draw(SDL_Texture * texture, SDL_Rect src, SDL_Rect dest) : void get() : TextureManager & loadTexture(const char * fileName) : SDL_Texture * splitSpriteSheet(SDL_Texture * spriteSheet, int width, int height, int spritesOnSheet) : std::vector<SDL_Rect> texture_cache : std::map<const char *,SDL_Texture *,cmp_str> Manager addEntity() : Entity & addToGroup(Entity * mEntity, Group mGroup) : void draw() : void getGroup(Group mGroup) : std::vector<Entity *> & refresh() : void update() : void entities : std::vector<std::unique_ptr<Entity>> groupedEntities : std::array<std::vector<Entity *>,MAX_GROUPS> Map Map() = default : void ~Map() constexpr = default : void loadMap(const char * path, int sizeX, int sizeY) : void GroupLabel MAP PLAYERS ENEMIES COLLIDERS PROJECTILE HEARTS Component ~Component() constexpr = default : void draw() : void init() : void update() : void entity : Entity * Animation Animation() : void Animation(int i, int f, int s) : void frames : int index : int speed : int AnimationType IDLE WALK SpriteComponent SpriteComponent() = default : void SpriteComponent(const char * path) : void SpriteComponent(const char * path, bool isAnimated) : void ~SpriteComponent() : void draw() : void init() : void play(AnimationType type) : void setTexture(const char * path) : void update() : void animated : bool animationIndex : int animations : std::map<AnimationType,Animation *> destRect : SDL_Rect frames : int speed : int srcRect : SDL_Rect texture : SDL_Texture * transform : TransformComponent * Entity Entity(Manager & mManager) : void addComponent<T,TArgs...>(TArgs &&... mArgs) : T & addGroup(Group mGroup) : void delGroup(Group mGroup) : void destroy() : void draw() const : void getComponent<T>() const : T & hasComponent<T>() const : _Bool hasGroup(Group mGroup) : bool isActive() const : bool update() const : void active : bool componentArray : ComponentArray componentBitSet : ComponentBitSet components : std::vector<std::unique_ptr<Component>> groupBitSet : GroupBitSet manager : Manager & Vector2D Vector2D() : void Vector2D(float x, float y) : void operator*(const int & i) : Vector2D & zero() : Vector2D & x : float y : float TransformComponent TransformComponent() : void TransformComponent(int scale) : void TransformComponent(float x, float y) : void TransformComponent(float x, float y, int scale) : void TransformComponent(float x, float y, int w, int h, int scale) : void init() : void update() : void height : int position : Vector2D scale : int speed : int velocity : Vector2D width : int TextureDict textureDictionary : const std::map<int,std::string> TileComponent TileComponent() = default : void TileComponent(int x, int y, int w, int h, int id) : void ~TileComponent() = default : void init() : void path : const char * sprite : SpriteComponent * textureDict : TextureDict tileID : int tileRect : SDL_Rect transform : TransformComponent * ColliderComponent ColliderComponent(const char * tag) : void init() : void removeCollision() : void update() : void collider : SDL_Rect hasCollision : bool tag : const char * transform : TransformComponent * KeyboardController KeyboardController() = default : void KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity) : void ~KeyboardController() constexpr = default : void init() : void update() : void down : SDL_Scancode fire : SDL_Scancode fireCooldown : Uint32 fireVelocity : Vector2D keystates : const Uint8 * lastFireTime : Uint32 left : SDL_Scancode player : TransformComponent * right : SDL_Scancode sprite : SpriteComponent * transform : TransformComponent * up : SDL_Scancode ProjectileComponent ProjectileComponent(int range, int speed, Vector2D velocity, bool source) : void ~ProjectileComponent() : void getSource() : bool init() : void update() : void distance : int range : int source : const bool speed : int transformComponent : TransformComponent * velocity : Vector2D HealthComponent HealthComponent(int health, Manager * manager, bool player) : void ~HealthComponent() : void createAllHearts() : void createHeartComponents(int x) : void getDamage() : void getHealth() : int init() : void health : int manager : Manager * player : bool AssetManager AssetManager(Manager * manager) : void ~AssetManager() : void addTexture(std::string id, const char * path) : void createProjectile(Vector2D pos, Vector2D velocity, bool source, int scale, int range, int speed, const char * texturePath) : void getTexture(std::string id) : SDL_Texture * man : Manager * textures : std::map<std::string,SDL_Texture *> GameObject GameObject(const char * texturesheet, int x, int y) : void ~GameObject() constexpr = default : void render() : void update() : void destRect : SDL_Rect objTexture : SDL_Texture * srcRect : SDL_Rect xPos : int yPos : int colliders assets manager entity transform position velocity transform sprite textureDict transform transform player sprite fireVelocity transformComponent velocity manager man
\ No newline at end of file
+Game Game() : void ~Game() : void addTile(int id, int x, int y) : void clean() : void getWinner() : bool handleEvents() : void init(const char * title, int xpos, int ypos, int width, int height, bool fullscreen) : void render() : void running() const : bool update() : void assets : AssetManager * colliders : std::vector<ColliderComponent *> counter : int event : SDL_Event isRunning : bool renderer : SDL_Renderer * window : SDL_Window * winner : bool GroupLabel MAP PLAYERS ENEMIES COLLIDERS PROJECTILE HEARTS Component ~Component() constexpr = default : void draw() : void init() : void update() : void entity : Entity * Manager addEntity() : Entity & addToGroup(Entity * mEntity, Group mGroup) : void draw() : void getGroup(Group mGroup) : std::vector<Entity *> & refresh() : void update() : void entities : std::vector<std::unique_ptr<Entity>> groupedEntities : std::array<std::vector<Entity *>,MAX_GROUPS> Entity Entity(Manager & mManager) : void addComponent<T,TArgs...>(TArgs &&... mArgs) : T & addGroup(Group mGroup) : void delGroup(Group mGroup) : void destroy() : void draw() const : void getComponent<T>() const : T & hasComponent<T>() const : _Bool hasGroup(Group mGroup) : bool isActive() const : bool update() const : void active : bool componentArray : ComponentArray componentBitSet : ComponentBitSet components : std::vector<std::unique_ptr<Component>> groupBitSet : GroupBitSet manager : Manager & Vector2D Vector2D() : void Vector2D(float x, float y) : void operator*(const int & i) : Vector2D & zero() : Vector2D & x : float y : float TransformComponent TransformComponent() : void TransformComponent(int scale) : void TransformComponent(float x, float y) : void TransformComponent(float x, float y, int scale) : void TransformComponent(float x, float y, int w, int h, int scale) : void init() : void update() : void height : int position : Vector2D scale : int speed : int velocity : Vector2D width : int Animation Animation() : void Animation(int i, int f, int s) : void frames : int index : int speed : int AnimationType IDLE WALK SpriteComponent SpriteComponent() = default : void SpriteComponent(const char * path) : void SpriteComponent(const char * path, bool isAnimated) : void ~SpriteComponent() : void draw() : void init() : void play(AnimationType type) : void setTexture(const char * path) : void update() : void animated : bool animationIndex : int animations : std::map<AnimationType,Animation *> destRect : SDL_Rect frames : int speed : int srcRect : SDL_Rect texture : SDL_Texture * transform : TransformComponent * KeyboardController KeyboardController() = default : void KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity) : void ~KeyboardController() constexpr = default : void init() : void update() : void down : SDL_Scancode fire : SDL_Scancode fireCooldown : Uint32 fireVelocity : Vector2D keystates : const Uint8 * lastFireTime : Uint32 left : SDL_Scancode player : TransformComponent * right : SDL_Scancode sprite : SpriteComponent * transform : TransformComponent * up : SDL_Scancode ColliderComponent ColliderComponent(const char * tag) : void init() : void removeCollision() : void update() : void collider : SDL_Rect hasCollision : bool tag : const char * transform : TransformComponent * TextureDict textureDictionary : const std::map<int,std::string> TileComponent TileComponent() = default : void TileComponent(int x, int y, int w, int h, int id) : void ~TileComponent() = default : void init() : void path : const char * sprite : SpriteComponent * textureDict : TextureDict tileID : int tileRect : SDL_Rect transform : TransformComponent * ProjectileComponent ProjectileComponent(int range, int speed, Vector2D velocity, bool source) : void ~ProjectileComponent() : void getSource() : bool init() : void update() : void distance : int range : int source : const bool speed : int transformComponent : TransformComponent * velocity : Vector2D HealthComponent HealthComponent(int health, Manager * manager, bool player) : void ~HealthComponent() : void createAllHearts() : void createHeartComponents(int x) : void getDamage() : void getHealth() : int init() : void health : int manager : Manager * player : bool AssetManager AssetManager(Manager * manager) : void ~AssetManager() : void addTexture(std::string id, const char * path) : void createProjectile(Vector2D pos, Vector2D velocity, bool source, int scale, int range, int speed, const char * texturePath) : void getTexture(std::string id) : SDL_Texture * man : Manager * textures : std::map<std::string,SDL_Texture *> Map Map() = default : void ~Map() constexpr = default : void loadMap(const char * path, int sizeX, int sizeY) : void cmp_str operator()(const char * a, const char * b) const : bool TextureManager TextureManager() : void TextureManager(const TextureManager &) = deleted : void ~TextureManager() : void operator=(const TextureManager &) = deleted : void draw(SDL_Texture * texture, SDL_Rect src, SDL_Rect dest) : void get() : TextureManager & loadTexture(const char * fileName) : SDL_Texture * splitSpriteSheet(SDL_Texture * spriteSheet, int width, int height, int spritesOnSheet) : std::vector<SDL_Rect> texture_cache : std::map<const char *,SDL_Texture *,cmp_str> GameObject GameObject(const char * texturesheet, int x, int y) : void ~GameObject() constexpr = default : void render() : void update() : void destRect : SDL_Rect objTexture : SDL_Texture * srcRect : SDL_Rect xPos : int yPos : int colliders assets entity manager position velocity transform transform player sprite fireVelocity transform transform sprite textureDict transformComponent velocity manager man
\ No newline at end of file
diff --git a/docs/diagrams/includes.svg b/docs/diagrams/includes.svg
index b2c3675..959b2df 100644
--- a/docs/diagrams/includes.svg
+++ b/docs/diagrams/includes.svg
@@ -1 +1 @@
-src include Game.cpp ECS.cpp TextureManager.cpp Map.cpp GameObject.cpp KeyboardController.cpp main.cpp Vector2D.cpp Game.h TextureManager.h Manager.h Constants.h Map.h Entity.h Component.h SpriteComponent.h AnimationHandler.h ECS.h TransformComponent.h Vector2D.h TileComponent.h TextureDict.h ColliderComponent.h KeyboardController.h AssetManager.h Components.h ProjectileComponent.h HealthComponent.h GameObject.h stdio.h iostream SDL.h SDL_image.h vector string.h SDL_render.h map array memory bitset algorithm string cstdio stdexcept fstream
\ No newline at end of file
+src include Game.cpp ECS.cpp TextureManager.cpp Map.cpp GameObject.cpp KeyboardController.cpp main.cpp Vector2D.cpp Game.h Components.h ECS.h Component.h Constants.h Manager.h Entity.h TransformComponent.h Vector2D.h SpriteComponent.h AnimationHandler.h KeyboardController.h ColliderComponent.h TileComponent.h TextureDict.h ProjectileComponent.h HealthComponent.h AssetManager.h Map.h TextureManager.h GameObject.h SDL.h SDL_image.h vector cstddef iostream array memory bitset map SDL_render.h string stdexcept fstream
\ No newline at end of file
diff --git a/docs/diagrams/includes_no_external.svg b/docs/diagrams/includes_no_external.svg
index fa6e813..3e4ed8b 100644
--- a/docs/diagrams/includes_no_external.svg
+++ b/docs/diagrams/includes_no_external.svg
@@ -1 +1 @@
-src include Game.cpp ECS.cpp TextureManager.cpp Map.cpp GameObject.cpp KeyboardController.cpp main.cpp Vector2D.cpp Game.h TextureManager.h Manager.h Constants.h Map.h Entity.h Component.h SpriteComponent.h AnimationHandler.h ECS.h TransformComponent.h Vector2D.h TileComponent.h TextureDict.h ColliderComponent.h KeyboardController.h AssetManager.h Components.h ProjectileComponent.h HealthComponent.h GameObject.h
\ No newline at end of file
+src include Game.cpp ECS.cpp TextureManager.cpp Map.cpp GameObject.cpp KeyboardController.cpp main.cpp Vector2D.cpp Game.h Components.h ECS.h Component.h Constants.h Manager.h Entity.h TransformComponent.h Vector2D.h SpriteComponent.h AnimationHandler.h KeyboardController.h ColliderComponent.h TileComponent.h TextureDict.h ProjectileComponent.h HealthComponent.h AssetManager.h Map.h TextureManager.h GameObject.h
\ No newline at end of file
diff --git a/docs/diagrams/load_map_example_sequence.svg b/docs/diagrams/load_map_example_sequence.svg
new file mode 100644
index 0000000..a396b19
--- /dev/null
+++ b/docs/diagrams/load_map_example_sequence.svg
@@ -0,0 +1 @@
+Map Map Game Game Manager Manager Entity Entity TileComponent TileComponent getComponentTypeID<TileComponent>() getComponentTypeID<TileComponent>() getNewComponentTypeID() getNewComponentTypeID() ColliderComponent ColliderComponent getComponentTypeID<ColliderComponent>() getComponentTypeID<ColliderComponent>() loadMap(const char *,int,int) loop loop addTile(int,int,int) addEntity() addComponent(int &,int &,const int &,const int &,int &) TileComponent(int,int,int,int,int) init() alt addComponent(const char (&)[6]) ColliderComponent(const char *) init() addGroup(Group)
\ No newline at end of file
diff --git a/include/AssetManager.h b/include/AssetManager.h
index 43cefe8..61b94d2 100644
--- a/include/AssetManager.h
+++ b/include/AssetManager.h
@@ -1,13 +1,12 @@
+#include
#include
#include
-#include "TextureManager.h"
-#include "Vector2D.h"
-#include "Components.h"
-#include "ECS.h"
-
-class AssetManager {
+class Vector2D;
+class Manager;
+class AssetManager
+{
public:
AssetManager(Manager* manager);
diff --git a/include/ColliderComponent.h b/include/ColliderComponent.h
index a2ebe50..a4f286d 100644
--- a/include/ColliderComponent.h
+++ b/include/ColliderComponent.h
@@ -1,5 +1,7 @@
#pragma once
-#include "SDL.h"
+
+#include
+
#include "Component.h"
class TransformComponent;
diff --git a/include/Component.h b/include/Component.h
index e0effab..bc788ac 100644
--- a/include/Component.h
+++ b/include/Component.h
@@ -17,20 +17,9 @@ class Component
public:
Entity* entity;
- virtual void init()
- {
- // implementation in derived classes (when neccessary)
- }
-
- virtual void update()
- {
- // implementation in derived classes (when neccessary)
- }
-
- virtual void draw()
- {
- // implementation in derived classes (when neccessary)
- }
+ virtual void init() {}
+ virtual void update() {}
+ virtual void draw() {}
virtual ~Component() = default;
};
\ No newline at end of file
diff --git a/include/Components.h b/include/Components.h
index d488af8..b6f506f 100644
--- a/include/Components.h
+++ b/include/Components.h
@@ -1,4 +1,5 @@
#pragma once
+
#include "ECS.h"
#include "Component.h"
#include "Manager.h"
diff --git a/include/Constants.h b/include/Constants.h
index 1e8720f..502bd2b 100644
--- a/include/Constants.h
+++ b/include/Constants.h
@@ -1,5 +1,6 @@
#pragma once
-#include
+
+#include
using Group = std::size_t;
diff --git a/include/ECS.h b/include/ECS.h
index 4ee7c72..53517ec 100644
--- a/include/ECS.h
+++ b/include/ECS.h
@@ -1,14 +1,8 @@
#pragma once
-#include
-#include
-#include
-#include
-#include
-#include
+#include "Component.h"
#include "Constants.h"
-
class Component;
class Entity;
class Manager;
diff --git a/include/Entity.h b/include/Entity.h
index 9244252..326ff7c 100644
--- a/include/Entity.h
+++ b/include/Entity.h
@@ -1,13 +1,15 @@
#pragma once
+
#include
-#include
+#include
#include
-#include "Constants.h"
-#include "Component.h"
-#include "SpriteComponent.h"
+#include
+
#include "ECS.h"
+#include "Constants.h"
class Manager;
+class Component;
using ComponentBitSet = std::bitset;
using GroupBitSet = std::bitset;
diff --git a/include/Game.h b/include/Game.h
index 71b6824..ed07f38 100644
--- a/include/Game.h
+++ b/include/Game.h
@@ -1,42 +1,39 @@
#pragma once
-#include
-#include
+
#include
#include
#include
-#include
-
class AssetManager;
class ColliderComponent;
class Game
{
- public:
- Game();
- ~Game();
+public:
+ Game();
+ ~Game();
- void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
+ void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
- void handleEvents();
- void update();
- void render();
- void clean();
- bool running() const;
+ void handleEvents();
+ void update();
+ void render();
+ void clean();
+ bool running() const;
- static void addTile(int id, int x, int y);
- static SDL_Renderer* renderer;
- static SDL_Event event;
- static std::vector colliders;
- static AssetManager* assets;
+ static void addTile(int id, int x, int y);
+ static SDL_Renderer* renderer;
+ static SDL_Event event;
+ static std::vector colliders;
+ static AssetManager* assets;
+
+ bool getWinner();
- bool getWinner();
+private:
+ int counter = 0;
+ bool isRunning = false;
+ SDL_Window* window;
- private:
- int counter = 0;
- bool isRunning = false;
- SDL_Window* window;
-
- //true for player1 win / false for player2 win;
- bool winner;
+ //true for player1 win / false for player2 win;
+ bool winner;
};
diff --git a/include/GameObject.h b/include/GameObject.h
index b8879ba..1c209ae 100644
--- a/include/GameObject.h
+++ b/include/GameObject.h
@@ -3,19 +3,19 @@
class GameObject
{
- public:
- GameObject(const char* texturesheet, int x, int y);
- ~GameObject() = default;
+public:
+ GameObject(const char* texturesheet, int x, int y);
+ ~GameObject() = default;
- void update();
- void render();
+ void update();
+ void render();
- private:
- int xPos;
- int yPos;
+private:
+ int xPos;
+ int yPos;
- SDL_Texture* objTexture;
- SDL_Rect srcRect;
- SDL_Rect destRect;
+ SDL_Texture* objTexture;
+ SDL_Rect srcRect;
+ SDL_Rect destRect;
};
diff --git a/include/HealthComponent.h b/include/HealthComponent.h
index db456dd..7cfd2e7 100644
--- a/include/HealthComponent.h
+++ b/include/HealthComponent.h
@@ -1,65 +1,29 @@
-#include "Components.h"
+#pragma once
-class HealthComponent : public Component {
+#include "Component.h"
+class Manager;
+
+class HealthComponent : public Component
+{
public:
HealthComponent(int health, Manager* manager, bool player) : health(health), manager(manager), player(player) {}
-
~HealthComponent() {}
- void getDamage() {
- this->health--;
- }
+ void getDamage() { this->health--; }
+ int getHealth() { return this->health; }
- int getHealth() {
- return this->health;
- }
+ void init() override;
- void init() override
- {
- createAllHearts();
- }
-
- void createAllHearts() {
-
- int x; //starting position for first health icon
-
- if(player) {
- x = 10;
- } else {
- x = 730;
- }
-
- for(int i = 0; i < health; i++) {
-
- //checks for player side
- if(player) {
- createHeartComponents(x);
- x += 50;
- continue;
- }
-
- createHeartComponents(x);
- x -= 50;
- }
- }
-
- void createHeartComponents(int x) {
-
- auto& heart(manager->addEntity());
- heart.addComponent(x,5,2);
- heart.addComponent("assets/heart.png");
- heart.addGroup((size_t)GroupLabel::HEARTS);
- }
+ void createAllHearts();
+ void createHeartComponents(int x);
private:
int health;
-
Manager* manager;
-
bool player; //true if player1 / false if player2
};
\ No newline at end of file
diff --git a/include/KeyboardController.h b/include/KeyboardController.h
index b353183..4677ad6 100644
--- a/include/KeyboardController.h
+++ b/include/KeyboardController.h
@@ -1,5 +1,6 @@
#pragma once
#include
+
#include "Component.h"
#include "Vector2D.h"
diff --git a/include/Manager.h b/include/Manager.h
index f606619..f85f3b8 100644
--- a/include/Manager.h
+++ b/include/Manager.h
@@ -3,6 +3,7 @@
#include
#include
#include
+
#include "Constants.h"
class Entity;
diff --git a/include/ProjectileComponent.h b/include/ProjectileComponent.h
index 911a03b..73088c1 100644
--- a/include/ProjectileComponent.h
+++ b/include/ProjectileComponent.h
@@ -1,46 +1,24 @@
#pragma once
-#include "ECS.h"
-#include "Components.h"
+#include "Component.h"
#include "Vector2D.h"
-class ProjectileComponent : public Component {
+class TransformComponent;
+class ProjectileComponent : public Component
+{
//can maybe be split in separate .cpp file
public:
-
- ProjectileComponent(int range, int speed, Vector2D velocity, bool source) : range(range), speed(speed), velocity(velocity), source(source) {
-
- }
-
+ ProjectileComponent(int range, int speed, Vector2D velocity, bool source) : range(range), speed(speed), velocity(velocity), source(source) {}
~ProjectileComponent() {}
- void init() override {
- transformComponent = &entity->getComponent();
- }
-
- void update() override {
-
- transformComponent->velocity = velocity;
-
- distance += speed;
-
- if (distance > range) {
- entity->destroy();
- entity->getComponent().removeCollision();
- //std::cout << "out of range" << std::endl;
- }
-
- }
-
- bool getSource() {
- return this->source;
- }
+ void init() override;
+ void update() override;
+ bool getSource() { return this->source; }
private:
-
TransformComponent* transformComponent;
int range = 0;
diff --git a/include/SpriteComponent.h b/include/SpriteComponent.h
index 18b849d..5a51c59 100644
--- a/include/SpriteComponent.h
+++ b/include/SpriteComponent.h
@@ -1,37 +1,39 @@
#pragma once
+
+#include
+#include
+
#include "AnimationHandler.h"
#include "Component.h"
-#include "Game.h"
-#include
class TransformComponent;
class SpriteComponent : public Component
{
- public:
- int animationIndex = 0;
+public:
+ int animationIndex = 0;
- std::map animations;
+ std::map animations;
- private:
- TransformComponent* transform;
- SDL_Texture* texture;
- SDL_Rect srcRect, destRect;
+private:
+ TransformComponent* transform;
+ SDL_Texture* texture;
+ SDL_Rect srcRect, destRect;
- bool animated = false;
- int frames = 0;
- int speed = 100;
+ bool animated = false;
+ int frames = 0;
+ int speed = 100;
- public:
- SpriteComponent() = default;
- SpriteComponent(const char* path);
- SpriteComponent(const char* path, bool isAnimated);
- ~SpriteComponent();
+public:
+ SpriteComponent() = default;
+ SpriteComponent(const char* path);
+ SpriteComponent(const char* path, bool isAnimated);
+ ~SpriteComponent();
- void setTexture(const char* path);
+ void setTexture(const char* path);
- void init() override;
- void update() override;
- void draw() override;
- void play(AnimationType type);
+ void init() override;
+ void update() override;
+ void draw() override;
+ void play(AnimationType type);
};
diff --git a/include/TextureDict.h b/include/TextureDict.h
index d9c8d53..847e649 100644
--- a/include/TextureDict.h
+++ b/include/TextureDict.h
@@ -1,12 +1,12 @@
#pragma once
+
#include
#include
class TextureDict
{
public:
- const std::map textureDictionary =
- {
+ const std::map textureDictionary = {
{1, "assets/water.png"},
{2, "assets/dirt.png"},
{3, "assets/grass.png"},
diff --git a/include/TileComponent.h b/include/TileComponent.h
index 8f570cd..c0a9e1b 100644
--- a/include/TileComponent.h
+++ b/include/TileComponent.h
@@ -1,5 +1,7 @@
#pragma once
-#include "SDL.h"
+
+#include
+
#include "Component.h"
#include "TextureDict.h"
diff --git a/include/TransformComponent.h b/include/TransformComponent.h
index 4d9b077..04b193f 100644
--- a/include/TransformComponent.h
+++ b/include/TransformComponent.h
@@ -1,11 +1,11 @@
#pragma once
-#include "Vector2D.h"
+
#include "Component.h"
+#include "Vector2D.h"
class TransformComponent : public Component
{
public:
-
Vector2D position;
Vector2D velocity;
diff --git a/include/Vector2D.h b/include/Vector2D.h
index 8da3016..96380f8 100644
--- a/include/Vector2D.h
+++ b/include/Vector2D.h
@@ -2,18 +2,18 @@
class Vector2D
{
- public:
- float x;
- float y;
+public:
+ float x;
+ float y;
- Vector2D();
- Vector2D(float x, float y);
+ Vector2D();
+ Vector2D(float x, float y);
- friend Vector2D& operator+(Vector2D& vector1, const Vector2D& vector2);
- friend Vector2D& operator-(Vector2D& vector1, const Vector2D& vector2);
- friend Vector2D& operator*(Vector2D& vector1, const Vector2D& vector2);
- friend Vector2D& operator/(Vector2D& vector1, const Vector2D& vector2);
+ friend Vector2D& operator+(Vector2D& vector1, const Vector2D& vector2);
+ friend Vector2D& operator-(Vector2D& vector1, const Vector2D& vector2);
+ friend Vector2D& operator*(Vector2D& vector1, const Vector2D& vector2);
+ friend Vector2D& operator/(Vector2D& vector1, const Vector2D& vector2);
- Vector2D& operator*(const int& i);
- Vector2D& zero();
+ Vector2D& operator*(const int& i);
+ Vector2D& zero();
};
\ No newline at end of file
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index c1a7cff..63a76c6 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -1,11 +1,9 @@
#include "AssetManager.h"
-#include "Component.h"
+
+#include "TextureManager.h"
#include "Components.h"
-#include
-AssetManager::AssetManager(Manager* manager) : man(manager) {
-
-}
+AssetManager::AssetManager(Manager* manager) : man(manager) {}
AssetManager::~AssetManager() {}
diff --git a/src/ColliderComponent.cpp b/src/ColliderComponent.cpp
index e4cadfd..6418aea 100644
--- a/src/ColliderComponent.cpp
+++ b/src/ColliderComponent.cpp
@@ -1,7 +1,8 @@
#include "ColliderComponent.h"
-#include "TransformComponent.h"
+
#include "Entity.h"
#include "Game.h"
+#include "TransformComponent.h"
ColliderComponent::ColliderComponent(const char* tag)
{
@@ -11,10 +12,10 @@ ColliderComponent::ColliderComponent(const char* tag)
void ColliderComponent::init()
{
- if (!entity->hasComponent())
- {
+ if (!entity->hasComponent()) {
entity->addComponent();
}
+
transform = &entity->getComponent();
Game::colliders.push_back(this);
}
diff --git a/src/Entity.cpp b/src/Entity.cpp
index 5f199ea..8ec725d 100644
--- a/src/Entity.cpp
+++ b/src/Entity.cpp
@@ -1,5 +1,5 @@
-#pragma once
#include "Entity.h"
+
#include "Manager.h"
#include "Component.h"
diff --git a/src/Game.cpp b/src/Game.cpp
index b6adde5..26fa8d0 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -1,15 +1,10 @@
#include "Game.h"
-#include "TextureManager.h"
-#include "Manager.h"
-#include "Map.h"
-#include "Entity.h"
-#include "Component.h"
-#include "TransformComponent.h"
-#include "TileComponent.h"
-#include "ColliderComponent.h"
-#include "SpriteComponent.h"
-#include "KeyboardController.h"
+
+#include "Components.h"
+
#include "AssetManager.h"
+#include "Map.h"
+#include "TextureManager.h"
Map* map;
Manager manager;
diff --git a/src/GameObject.cpp b/src/GameObject.cpp
index 4a5f59c..af866d1 100644
--- a/src/GameObject.cpp
+++ b/src/GameObject.cpp
@@ -1,4 +1,5 @@
#include "GameObject.h"
+
#include "TextureManager.h"
#include "Game.h"
diff --git a/src/HealthComponent.cpp b/src/HealthComponent.cpp
new file mode 100644
index 0000000..67b2070
--- /dev/null
+++ b/src/HealthComponent.cpp
@@ -0,0 +1,40 @@
+#include "HealthComponent.h"
+
+#include "Components.h"
+
+void HealthComponent::init()
+{
+ createAllHearts();
+}
+
+void HealthComponent::createAllHearts()
+{
+ int x; //starting position for first health icon
+
+ if(player) {
+ x = 10;
+ } else {
+ x = 730;
+ }
+
+ for(int i = 0; i < health; i++) {
+
+ //checks for player side
+ if(player) {
+ createHeartComponents(x);
+ x += 50;
+ continue;
+ }
+
+ createHeartComponents(x);
+ x -= 50;
+ }
+}
+
+ void HealthComponent::createHeartComponents(int x)
+{
+ auto& heart(manager->addEntity());
+ heart.addComponent(x,5,2);
+ heart.addComponent("assets/heart.png");
+ heart.addGroup((size_t)GroupLabel::HEARTS);
+}
\ No newline at end of file
diff --git a/src/KeyboardController.cpp b/src/KeyboardController.cpp
index 8ddd753..b44e61d 100644
--- a/src/KeyboardController.cpp
+++ b/src/KeyboardController.cpp
@@ -1,8 +1,8 @@
#include "KeyboardController.h"
-#include "TransformComponent.h"
-#include "Entity.h"
+
+#include "Game.h"
+#include "Components.h"
#include "AssetManager.h"
-#include "SpriteComponent.h"
KeyboardController::KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity)
{
diff --git a/src/Manager.cpp b/src/Manager.cpp
index f247a7f..ba800b1 100644
--- a/src/Manager.cpp
+++ b/src/Manager.cpp
@@ -1,4 +1,7 @@
#include "Manager.h"
+
+#include
+
#include "Entity.h"
void Manager::update()
diff --git a/src/Map.cpp b/src/Map.cpp
index 0c8327c..859bd4e 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -1,5 +1,7 @@
#include "Map.h"
+
#include
+
#include "Constants.h"
#include "Game.h"
diff --git a/src/ProjectileComponent.cpp b/src/ProjectileComponent.cpp
new file mode 100644
index 0000000..ad50e39
--- /dev/null
+++ b/src/ProjectileComponent.cpp
@@ -0,0 +1,21 @@
+#include "ProjectileComponent.h"
+
+#include "Components.h"
+
+void ProjectileComponent::init()
+{
+ transformComponent = &entity->getComponent();
+}
+
+void ProjectileComponent::update()
+{
+ transformComponent->velocity = velocity;
+
+ distance += speed;
+
+ if (distance > range) {
+ entity->destroy();
+ entity->getComponent().removeCollision();
+ //std::cout << "out of range" << std::endl;
+ }
+}
\ No newline at end of file
diff --git a/src/SpriteComponent.cpp b/src/SpriteComponent.cpp
index 1afe232..15ab921 100644
--- a/src/SpriteComponent.cpp
+++ b/src/SpriteComponent.cpp
@@ -1,7 +1,10 @@
-#include "AnimationHandler.h"
-#include "TransformComponent.h"
-#include "Entity.h"
+#include "SpriteComponent.h"
+
+#include
+
#include "TextureManager.h"
+#include "Entity.h"
+#include "TransformComponent.h"
SpriteComponent::SpriteComponent(const char* path)
{
diff --git a/src/TextureManager.cpp b/src/TextureManager.cpp
index 1874384..b364214 100644
--- a/src/TextureManager.cpp
+++ b/src/TextureManager.cpp
@@ -1,7 +1,8 @@
#include "TextureManager.h"
-#include
+
#include
#include
+
#include "Game.h"
SDL_Texture* TextureManager::loadTexture(const char* fileName)
diff --git a/src/TileComponent.cpp b/src/TileComponent.cpp
index 220bc73..accd38a 100644
--- a/src/TileComponent.cpp
+++ b/src/TileComponent.cpp
@@ -1,6 +1,11 @@
#include "TileComponent.h"
+
+#include
+
#include "Entity.h"
#include "TransformComponent.h"
+#include "SpriteComponent.h"
+#include "TileComponent.h"
TileComponent::TileComponent(int x, int y, int w, int h, int id)
{
@@ -11,8 +16,7 @@ TileComponent::TileComponent(int x, int y, int w, int h, int id)
tileID = id;
auto it = textureDict.textureDictionary.find(tileID); //every id has its own distinct texture (in texturedict.h)
- if (it == textureDict.textureDictionary.end())
- {
+ if (it == textureDict.textureDictionary.end()) {
std::cout << "it end" << std::endl;
return;
}