diff --git a/docs/md-pages/entitiesAndComponents.md b/docs/md-pages/entitiesAndComponents.md index 272bdc1..e4b5b7c 100644 --- a/docs/md-pages/entitiesAndComponents.md +++ b/docs/md-pages/entitiesAndComponents.md @@ -1,25 +1,38 @@ # Entities and Components ## Entities In the scope of this library entities essentially function like empty containers that you can add components or properties to. So an entity can be whatever you want it to be, give it a texture, make it pickupable, give it collision or all of the above and more. -Here is a quick overview over relevant classes containing functions pertaining to the creation and editing of entities: -- [Manager](@ref Manager) -- [Entity](@ref Entity) +[Manager](@ref Manager) contains functions responsible for the creation and editing of entities: + +**If you are ever lost when looking for related functionality via search or side bar remember it is all neatly organized on this page for better readability and a better overview** ## Components -The following components are currently available to you to use in your entities (the associated managers/handlers are also linked): +The following components are currently available for you to use in your entities (the associated managers/handlers are also linked): --- -### [Collider Component](@ref ColliderComponent) -see also [Collision Handler](@ref CollisionHandler) +### [Transform Component](@ref TransformComponent) +The Transform Component manages the position and movement of an Entity. Multiple overloaded constructors exist depending on whether or not the entity is stationary -Adds collision functionality to an Entity meaning functionality can be assigned to happen when two Entities collision boxes intersect --> this is used by the library, the developer themselves cannot (yet) add custom functionality to happen on collision unless the [Collision handler](@ref CollisionHandler) itself is directly used. It is used to stop entities from running through tiles given the "collision" tag (see [Tiled](@ref md_docs_2md-pages_2tilemaps) section) and to enable picking up other entities. +--- +### [Sprite Component](@ref SpriteComponent) +Textures and Animations can be added via this component. + +> [!important] +> A [Transform Component](@ref TransformComponent) is first needed before adding a Texture as the coordinates from the transform component are needed to tell the game where to render the texture --- ### [Data Component](@ref DataComponent) Custom Data such as Stats can be added to an Entity and accessed using this Component. > [!important] -> If an Entity is supposed to have movement the stat "speed" has to be added and set to a positive int! +> If an Entity is supposed to be able to move the stat "speed" has to be added and set to a positive int! + +--- +### [Collider Component](@ref ColliderComponent) +see also [Collision Handler](@ref CollisionHandler) + +Adds collision functionality to an Entity. It is used to stop entities with a PLAYER group label from running through tiles that were given the "collision" tag in the Tiled editor (see [Tiled](@ref md_docs_2md-pages_2tilemaps) section) or the COLLIDERS group label in the code. + +Also enables "picking up" other entities via [Pickup Component](@ref PickupComponent). --- ### [Interaction Component](@ref InteractionComponent) @@ -36,17 +49,6 @@ see also [Pickup Manager](@ref PickupManager) Entities with pickup components will disappear once another collision having entity with the [Group Label](@ref Entity#GroupLabel) "Player" intersects with it and executes the custom functionality given to it via constructor. ---- -### [Transform Component](@ref TransformComponent) -The Transform Component manages the position and movement of an Entity. Multiple overloaded constructors exist depending on whether or not the entity is stationary - ---- -### [Sprite Component](@ref SpriteComponent) -Textures and Animations can be added via this component. - -> [!important] -> A [Transform Component](@ref TransformComponent) is first needed before adding a Texture as the coordinates from the transform component are needed to tell the game where to render the texture - --- ### [Stat Effects Component](@ref StatEffectsComponent) Temporary stateffects can be added using this component. Using the time and function passed it will execute whatever is in the function after the given time. It is used to e.g. reset stats after raising them in order to allow for temporary stat raises \ No newline at end of file diff --git a/docs/md-pages/main.md b/docs/md-pages/main.md index 3b35985..c4b7c57 100644 --- a/docs/md-pages/main.md +++ b/docs/md-pages/main.md @@ -2,18 +2,21 @@ Here you will (hopefully) find any information necessary to use the different classes and components of this engine to develop your own simple 2D games. -If you are using this library for the first time it is recommended you follow the following sections step by step. - Alternatively you could also just look at the code in the templates include and src folders and look at the example implementations there. The best place to start is `GameImplementation.h` and `GameImplementation.cpp`. All .cpp files have an associated .h file, please always start in the .h file with the same name as the .cpp file, otherwise you might get confused at some of the inline explanations provided in the files. +> [!note] +> When navigating this documentation click on hyperlinks if you ever feel like information is missing (there is usually more information available in the detailed view only visible if you click it or scroll far enough) + The base functionality can be split into a few major sections: +### Setup and Config 1. [Quickstart guide for setting up the library](@ref md_docs_2md-pages_2quickstart) 2. [Configuring game settings](@ref md_docs_2md-pages_2config) 3. [Building a map using Tiled and tmx and loading it](@ref md_docs_2md-pages_2tilemaps) +### Implementation of Features 4. [Entities and Components](@ref md_docs_2md-pages_2entitiesAndComponents) 5. [Input Management](@ref md_docs_2md-pages_2inputhandling) 6. [Eventhandling](@ref md_docs_2md-pages_2eventhandling) You can also of course just browse the classes on your own this just act as a more structured separation and docuementation of relevant features -**DISCLAIMER: EVERYTHING IN THE GIVEN TEMPLATE CODE IS OPTIONAL EVERYTHING FOUND IN THERE IS JUST A GUIDE AND CAN BE CHANGED AND/OR DELETED WITHOUT A PROBLEM** \ No newline at end of file +DISCLAIMER: EVERYTHING IN THE GIVEN TEMPLATE CODE IS OPTIONAL EVERYTHING FOUND IN THERE IS JUST A GUIDE AND CAN BE CHANGED AND/OR DELETED WITHOUT A PROBLEM \ No newline at end of file diff --git a/include/DataComponent.h b/include/DataComponent.h index a5e6959..5e813f1 100644 --- a/include/DataComponent.h +++ b/include/DataComponent.h @@ -10,6 +10,7 @@ class DataComponent : public Component { public: + //! \brief The data component only has a default constructor DataComponent() {}; ~DataComponent() {}; /** @@ -23,7 +24,8 @@ public: /** * @brief Get a value of type T from the data map - * @details e.g. \code{.cpp}getEntry("speed");\endcode in this case the key is "speed" and the value is returned as an integer + * @details e.g. \code{.cpp}getEntry("speed").value();\endcode in this case the key is "speed" and the value is returned as an integer + * @details the value() or value_or() is NEEDED to handle the optional return type * @param key The name to retrieve the value from * @return An optional of type T containing the value if it exists and matches in typeid, otherwise std::nullopt */ diff --git a/include/SpriteComponent.h b/include/SpriteComponent.h index 61611bf..2042fdc 100644 --- a/include/SpriteComponent.h +++ b/include/SpriteComponent.h @@ -44,24 +44,17 @@ public: //debug Textures getTexture() { return this->textureEnum; } - - - //! \brief Constructor for SpriteComponent - //! \param texture The texture to be used for the sprite, must be a Texture enum - //! \param zIndex The z-index of the sprite, used for rendering order, in order to show up on the map, the zIndex must be higher than the layer you want it to show up on - SpriteComponent(Textures texture, int zIndex); - //! \param texture The texture to be used for the sprite, must be a Texture enum //! \param xOffset The x offset of the sprite relative to the transform component position, used for rendering position //! \param yOffset The y offset of the sprite relative to the transform component position, used for rendering position //! \param zIndex The z-index of the sprite, used for rendering order, in order to show up on the map, the zIndex must be higher than the layer you want it to show up on - SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex); + SpriteComponent(Textures texture, int zIndex, int xOffset = 0, int yOffset = 0); //! \param path The path to the texture to be used for the entity (for performance reasons, prefer enums instead) //! \param xOffset The x offset of the sprite relative to the transform component position, used for rendering position //! \param yOffset The y offset of the sprite relative to the transform component position, used for rendering position //! \param zIndex The z-index of the sprite, used for rendering order, in order to show up on the map, the zIndex must be higher than the layer you want it to show up on - SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex); + SpriteComponent(const char* path, int zIndex, int xOffset = 0, int yOffset = 0); /** * \brief Constructor used for **animated** sprites diff --git a/include/TransformComponent.h b/include/TransformComponent.h index 4afbe3d..5c48c8d 100644 --- a/include/TransformComponent.h +++ b/include/TransformComponent.h @@ -10,6 +10,11 @@ class TransformComponent : public Component { public: Vector2D position; // TODO: change to int to save CPU time -> possibly subpixel coordinates + + //! \brief The direction in which the entity is moving. (0, 0) is the default and signifies no movement. + //! \brief access direction with direction.x and direction.y for each direction + //! \brief x = 1 for right, -1 for left + //! \brief y = 1 for down, -1 for up Vector2D direction; int height = 32; diff --git a/src/Map.cpp b/src/Map.cpp index 08a4f0f..06bbcb3 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -167,7 +167,7 @@ void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int auto& tile(VEGO_Game().manager.addEntity()); tile.addComponent(x, y, mapTileSize.x, mapTileSize.y, 1); - tile.addComponent(texturePath.c_str(), v, u, zIndex); // why does uv need to be reversed? + tile.addComponent(texturePath.c_str(), zIndex, v, u); // why does uv need to be reversed? //TODO: also implement updated map stuff for this if (collision) { diff --git a/src/SpriteComponent.cpp b/src/SpriteComponent.cpp index 0c628e4..4d78892 100644 --- a/src/SpriteComponent.cpp +++ b/src/SpriteComponent.cpp @@ -15,19 +15,13 @@ #include "Manager.h" #include "VEGO.h" -SpriteComponent::SpriteComponent(Textures texture, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(0), textureYOffset(0) -{ - this->textureEnum = texture; - this->path = ""; -} - -SpriteComponent::SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) +SpriteComponent::SpriteComponent(Textures texture, int zIndex, int xOffset, int yOffset) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) { this->textureEnum = texture; this->path = ""; } -SpriteComponent::SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) { +SpriteComponent::SpriteComponent(const char* path, int zIndex, int xOffset, int yOffset) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) { this->path = path; }