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 @@ -GameGame() : void~Game() : voidaddTile(int id, int x, int y) : voidclean() : voidgetWinner() : boolhandleEvents() : voidinit(const char * title, int xpos, int ypos, int width, int height, bool fullscreen) : voidrender() : voidrunning() const : boolupdate() : voidassets : AssetManager *colliders : std::vector<ColliderComponent *>counter : intevent : SDL_EventisRunning : boolrenderer : SDL_Renderer *window : SDL_Window *winner : boolcmp_stroperator()(const char * a, const char * b) const : boolTextureManagerTextureManager() : voidTextureManager(const TextureManager &) = deleted : void~TextureManager() : voidoperator=(const TextureManager &) = deleted : voiddraw(SDL_Texture * texture, SDL_Rect src, SDL_Rect dest) : voidget() : 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>ManageraddEntity() : Entity &addToGroup(Entity * mEntity, Group mGroup) : voiddraw() : voidgetGroup(Group mGroup) : std::vector<Entity *> &refresh() : voidupdate() : voidentities : std::vector<std::unique_ptr<Entity>>groupedEntities : std::array<std::vector<Entity *>,MAX_GROUPS>MapMap() = default : void~Map() constexpr = default : voidloadMap(const char * path, int sizeX, int sizeY) : voidGroupLabelMAPPLAYERSENEMIESCOLLIDERSPROJECTILEHEARTSComponent~Component() constexpr = default : voiddraw() : voidinit() : voidupdate() : voidentity : Entity *AnimationAnimation() : voidAnimation(int i, int f, int s) : voidframes : intindex : intspeed : intAnimationTypeIDLEWALKSpriteComponentSpriteComponent() = default : voidSpriteComponent(const char * path) : voidSpriteComponent(const char * path, bool isAnimated) : void~SpriteComponent() : voiddraw() : voidinit() : voidplay(AnimationType type) : voidsetTexture(const char * path) : voidupdate() : voidanimated : boolanimationIndex : intanimations : std::map<AnimationType,Animation *>destRect : SDL_Rectframes : intspeed : intsrcRect : SDL_Recttexture : SDL_Texture *transform : TransformComponent *EntityEntity(Manager & mManager) : voidaddComponent<T,TArgs...>(TArgs &&... mArgs) : T &addGroup(Group mGroup) : voiddelGroup(Group mGroup) : voiddestroy() : voiddraw() const : voidgetComponent<T>() const : T &hasComponent<T>() const : _BoolhasGroup(Group mGroup) : boolisActive() const : boolupdate() const : voidactive : boolcomponentArray : ComponentArraycomponentBitSet : ComponentBitSetcomponents : std::vector<std::unique_ptr<Component>>groupBitSet : GroupBitSetmanager : Manager &Vector2DVector2D() : voidVector2D(float x, float y) : voidoperator*(const int & i) : Vector2D &zero() : Vector2D &x : floaty : floatTransformComponentTransformComponent() : voidTransformComponent(int scale) : voidTransformComponent(float x, float y) : voidTransformComponent(float x, float y, int scale) : voidTransformComponent(float x, float y, int w, int h, int scale) : voidinit() : voidupdate() : voidheight : intposition : Vector2Dscale : intspeed : intvelocity : Vector2Dwidth : intTextureDicttextureDictionary : const std::map<int,std::string>TileComponentTileComponent() = default : voidTileComponent(int x, int y, int w, int h, int id) : void~TileComponent() = default : voidinit() : voidpath : const char *sprite : SpriteComponent *textureDict : TextureDicttileID : inttileRect : SDL_Recttransform : TransformComponent *ColliderComponentColliderComponent(const char * tag) : voidinit() : voidremoveCollision() : voidupdate() : voidcollider : SDL_RecthasCollision : booltag : const char *transform : TransformComponent *KeyboardControllerKeyboardController() = default : voidKeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity) : void~KeyboardController() constexpr = default : voidinit() : voidupdate() : voiddown : SDL_Scancodefire : SDL_ScancodefireCooldown : Uint32fireVelocity : Vector2Dkeystates : const Uint8 *lastFireTime : Uint32left : SDL_Scancodeplayer : TransformComponent *right : SDL_Scancodesprite : SpriteComponent *transform : TransformComponent *up : SDL_ScancodeProjectileComponentProjectileComponent(int range, int speed, Vector2D velocity, bool source) : void~ProjectileComponent() : voidgetSource() : boolinit() : voidupdate() : voiddistance : intrange : intsource : const boolspeed : inttransformComponent : TransformComponent *velocity : Vector2DHealthComponentHealthComponent(int health, Manager * manager, bool player) : void~HealthComponent() : voidcreateAllHearts() : voidcreateHeartComponents(int x) : voidgetDamage() : voidgetHealth() : intinit() : voidhealth : intmanager : Manager *player : boolAssetManagerAssetManager(Manager * manager) : void~AssetManager() : voidaddTexture(std::string id, const char * path) : voidcreateProjectile(Vector2D pos, Vector2D velocity, bool source, int scale, int range, int speed, const char * texturePath) : voidgetTexture(std::string id) : SDL_Texture *man : Manager *textures : std::map<std::string,SDL_Texture *>GameObjectGameObject(const char * texturesheet, int x, int y) : void~GameObject() constexpr = default : voidrender() : voidupdate() : voiddestRect : SDL_RectobjTexture : SDL_Texture *srcRect : SDL_RectxPos : intyPos : intcollidersassetsmanagerentitytransformpositionvelocitytransformspritetextureDicttransformtransformplayerspritefireVelocitytransformComponentvelocitymanagerman \ No newline at end of file +GameGame() : void~Game() : voidaddTile(int id, int x, int y) : voidclean() : voidgetWinner() : boolhandleEvents() : voidinit(const char * title, int xpos, int ypos, int width, int height, bool fullscreen) : voidrender() : voidrunning() const : boolupdate() : voidassets : AssetManager *colliders : std::vector<ColliderComponent *>counter : intevent : SDL_EventisRunning : boolrenderer : SDL_Renderer *window : SDL_Window *winner : boolGroupLabelMAPPLAYERSENEMIESCOLLIDERSPROJECTILEHEARTSComponent~Component() constexpr = default : voiddraw() : voidinit() : voidupdate() : voidentity : Entity *ManageraddEntity() : Entity &addToGroup(Entity * mEntity, Group mGroup) : voiddraw() : voidgetGroup(Group mGroup) : std::vector<Entity *> &refresh() : voidupdate() : voidentities : std::vector<std::unique_ptr<Entity>>groupedEntities : std::array<std::vector<Entity *>,MAX_GROUPS>EntityEntity(Manager & mManager) : voidaddComponent<T,TArgs...>(TArgs &&... mArgs) : T &addGroup(Group mGroup) : voiddelGroup(Group mGroup) : voiddestroy() : voiddraw() const : voidgetComponent<T>() const : T &hasComponent<T>() const : _BoolhasGroup(Group mGroup) : boolisActive() const : boolupdate() const : voidactive : boolcomponentArray : ComponentArraycomponentBitSet : ComponentBitSetcomponents : std::vector<std::unique_ptr<Component>>groupBitSet : GroupBitSetmanager : Manager &Vector2DVector2D() : voidVector2D(float x, float y) : voidoperator*(const int & i) : Vector2D &zero() : Vector2D &x : floaty : floatTransformComponentTransformComponent() : voidTransformComponent(int scale) : voidTransformComponent(float x, float y) : voidTransformComponent(float x, float y, int scale) : voidTransformComponent(float x, float y, int w, int h, int scale) : voidinit() : voidupdate() : voidheight : intposition : Vector2Dscale : intspeed : intvelocity : Vector2Dwidth : intAnimationAnimation() : voidAnimation(int i, int f, int s) : voidframes : intindex : intspeed : intAnimationTypeIDLEWALKSpriteComponentSpriteComponent() = default : voidSpriteComponent(const char * path) : voidSpriteComponent(const char * path, bool isAnimated) : void~SpriteComponent() : voiddraw() : voidinit() : voidplay(AnimationType type) : voidsetTexture(const char * path) : voidupdate() : voidanimated : boolanimationIndex : intanimations : std::map<AnimationType,Animation *>destRect : SDL_Rectframes : intspeed : intsrcRect : SDL_Recttexture : SDL_Texture *transform : TransformComponent *KeyboardControllerKeyboardController() = default : voidKeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity) : void~KeyboardController() constexpr = default : voidinit() : voidupdate() : voiddown : SDL_Scancodefire : SDL_ScancodefireCooldown : Uint32fireVelocity : Vector2Dkeystates : const Uint8 *lastFireTime : Uint32left : SDL_Scancodeplayer : TransformComponent *right : SDL_Scancodesprite : SpriteComponent *transform : TransformComponent *up : SDL_ScancodeColliderComponentColliderComponent(const char * tag) : voidinit() : voidremoveCollision() : voidupdate() : voidcollider : SDL_RecthasCollision : booltag : const char *transform : TransformComponent *TextureDicttextureDictionary : const std::map<int,std::string>TileComponentTileComponent() = default : voidTileComponent(int x, int y, int w, int h, int id) : void~TileComponent() = default : voidinit() : voidpath : const char *sprite : SpriteComponent *textureDict : TextureDicttileID : inttileRect : SDL_Recttransform : TransformComponent *ProjectileComponentProjectileComponent(int range, int speed, Vector2D velocity, bool source) : void~ProjectileComponent() : voidgetSource() : boolinit() : voidupdate() : voiddistance : intrange : intsource : const boolspeed : inttransformComponent : TransformComponent *velocity : Vector2DHealthComponentHealthComponent(int health, Manager * manager, bool player) : void~HealthComponent() : voidcreateAllHearts() : voidcreateHeartComponents(int x) : voidgetDamage() : voidgetHealth() : intinit() : voidhealth : intmanager : Manager *player : boolAssetManagerAssetManager(Manager * manager) : void~AssetManager() : voidaddTexture(std::string id, const char * path) : voidcreateProjectile(Vector2D pos, Vector2D velocity, bool source, int scale, int range, int speed, const char * texturePath) : voidgetTexture(std::string id) : SDL_Texture *man : Manager *textures : std::map<std::string,SDL_Texture *>MapMap() = default : void~Map() constexpr = default : voidloadMap(const char * path, int sizeX, int sizeY) : voidcmp_stroperator()(const char * a, const char * b) const : boolTextureManagerTextureManager() : voidTextureManager(const TextureManager &) = deleted : void~TextureManager() : voidoperator=(const TextureManager &) = deleted : voiddraw(SDL_Texture * texture, SDL_Rect src, SDL_Rect dest) : voidget() : 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>GameObjectGameObject(const char * texturesheet, int x, int y) : void~GameObject() constexpr = default : voidrender() : voidupdate() : voiddestRect : SDL_RectobjTexture : SDL_Texture *srcRect : SDL_RectxPos : intyPos : intcollidersassetsentitymanagerpositionvelocitytransformtransformplayerspritefireVelocitytransformtransformspritetextureDicttransformComponentvelocitymanagerman \ 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 @@ -srcincludeGame.cppECS.cppTextureManager.cppMap.cppGameObject.cppKeyboardController.cppmain.cppVector2D.cppGame.hTextureManager.hManager.hConstants.hMap.hEntity.hComponent.hSpriteComponent.hAnimationHandler.hECS.hTransformComponent.hVector2D.hTileComponent.hTextureDict.hColliderComponent.hKeyboardController.hAssetManager.hComponents.hProjectileComponent.hHealthComponent.hGameObject.hstdio.hiostreamSDL.hSDL_image.hvectorstring.hSDL_render.hmaparraymemorybitsetalgorithmstringcstdiostdexceptfstream \ No newline at end of file +srcincludeGame.cppECS.cppTextureManager.cppMap.cppGameObject.cppKeyboardController.cppmain.cppVector2D.cppGame.hComponents.hECS.hComponent.hConstants.hManager.hEntity.hTransformComponent.hVector2D.hSpriteComponent.hAnimationHandler.hKeyboardController.hColliderComponent.hTileComponent.hTextureDict.hProjectileComponent.hHealthComponent.hAssetManager.hMap.hTextureManager.hGameObject.hSDL.hSDL_image.hvectorcstddefiostreamarraymemorybitsetmapSDL_render.hstringstdexceptfstream \ 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 @@ -srcincludeGame.cppECS.cppTextureManager.cppMap.cppGameObject.cppKeyboardController.cppmain.cppVector2D.cppGame.hTextureManager.hManager.hConstants.hMap.hEntity.hComponent.hSpriteComponent.hAnimationHandler.hECS.hTransformComponent.hVector2D.hTileComponent.hTextureDict.hColliderComponent.hKeyboardController.hAssetManager.hComponents.hProjectileComponent.hHealthComponent.hGameObject.h \ No newline at end of file +srcincludeGame.cppECS.cppTextureManager.cppMap.cppGameObject.cppKeyboardController.cppmain.cppVector2D.cppGame.hComponents.hECS.hComponent.hConstants.hManager.hEntity.hTransformComponent.hVector2D.hSpriteComponent.hAnimationHandler.hKeyboardController.hColliderComponent.hTileComponent.hTextureDict.hProjectileComponent.hHealthComponent.hAssetManager.hMap.hTextureManager.hGameObject.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 @@ +MapMapGameGameManagerManagerEntityEntityTileComponentTileComponentgetComponentTypeID<TileComponent>()getComponentTypeID<TileComponent>()getNewComponentTypeID()getNewComponentTypeID()ColliderComponentColliderComponentgetComponentTypeID<ColliderComponent>()getComponentTypeID<ColliderComponent>()loadMap(const char *,int,int)looploopaddTile(int,int,int)addEntity()addComponent(int &,int &,const int &,const int &,int &)TileComponent(int,int,int,int,int)init()altaddComponent(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; }