mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
This commit is contained in:
parent
2ff579dd39
commit
4c2ddb7ff4
@ -588,7 +588,7 @@ RESOLVE_UNNAMED_PARAMS = YES
|
||||
# section is generated. This option has no effect if EXTRACT_ALL is enabled.
|
||||
# The default value is: NO.
|
||||
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_MEMBERS = YES
|
||||
|
||||
# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
|
||||
# undocumented classes that are normally visible in the class hierarchy. If set
|
||||
@ -597,7 +597,7 @@ HIDE_UNDOC_MEMBERS = NO
|
||||
# if EXTRACT_ALL is enabled.
|
||||
# The default value is: NO.
|
||||
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_UNDOC_CLASSES = YES
|
||||
|
||||
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
|
||||
# declarations. If set to NO, these declarations will be included in the
|
||||
@ -649,7 +649,7 @@ HIDE_SCOPE_NAMES = NO
|
||||
# YES the compound reference will be hidden.
|
||||
# The default value is: NO.
|
||||
|
||||
HIDE_COMPOUND_REFERENCE= NO
|
||||
HIDE_COMPOUND_REFERENCE = NO
|
||||
|
||||
# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class
|
||||
# will show which file needs to be included to use the class.
|
||||
@ -949,7 +949,7 @@ WARN_LOGFILE =
|
||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = ./include ./src
|
||||
INPUT = ./include ./src ./docs/md-pages
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
@ -991,7 +991,8 @@ INPUT_FILE_ENCODING =
|
||||
|
||||
FILE_PATTERNS = *.cpp \
|
||||
*.h \
|
||||
*.hpp
|
||||
*.hpp \
|
||||
*.md
|
||||
|
||||
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
||||
# be searched for input files as well.
|
||||
@ -1120,7 +1121,7 @@ FILTER_SOURCE_PATTERNS =
|
||||
# (index.html). This can be useful if you have a project on for instance GitHub
|
||||
# and want to reuse the introduction page also for the doxygen output.
|
||||
|
||||
USE_MDFILE_AS_MAINPAGE =
|
||||
USE_MDFILE_AS_MAINPAGE = ./docs/md-pages/main.md
|
||||
|
||||
# The Fortran standard specifies that for fixed formatted Fortran code all
|
||||
# characters from position 72 are to be considered as comment. A common
|
||||
@ -2379,7 +2380,7 @@ INCLUDE_FILE_PATTERNS =
|
||||
# recursively expanded use the := operator instead of the = operator.
|
||||
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
|
||||
|
||||
PREDEFINED =
|
||||
PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS
|
||||
|
||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
|
||||
# tag can be used to specify a list of macro names that should be expanded. The
|
||||
|
||||
31
docs/md-pages/entitiesAndComponents.md
Normal file
31
docs/md-pages/entitiesAndComponents.md
Normal file
@ -0,0 +1,31 @@
|
||||
# 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
|
||||
- Entity
|
||||
|
||||
## Components
|
||||
The following components are currently available to you to use in your entities:
|
||||
- Collider Component
|
||||
|
||||
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. 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.
|
||||
- Data Component
|
||||
|
||||
Custom Data such as Stats can be added to an Entity and accessed using this Component. If an Entity is supposed to have movement the stat "speed" **has to be added**!
|
||||
- Interaction Component
|
||||
|
||||
Adding this component to an entity tells it to react to triggered Interactions e.g. by button press. For this a custom lambda or function pointer is passed to determine what exactly should happen once an entities ineraction was triggered.
|
||||
- Pickup Component
|
||||
|
||||
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.
|
||||
- Sprite Component
|
||||
|
||||
Textures and Animations can be added via this component
|
||||
- Stateffects Component
|
||||
|
||||
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
|
||||
- Transform Component
|
||||
|
||||
The Transform Component manages the position and movement of an Entity. Multiple overloaded constructors exist depending on whether or not the entity is stationary
|
||||
4
docs/md-pages/eventhandling.md
Normal file
4
docs/md-pages/eventhandling.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Interactions
|
||||
|
||||
In order to make an entity react to interactions it needs to include an implementation of InteractionListener such as the InteractionComponent. Using [its constructor](@ref InteractionComponent#InteractionComponent) you can add a lambda/function pointer containing what you want to happen once an interaction with this entity happens.
|
||||
|
||||
3
docs/md-pages/inputhandling.md
Normal file
3
docs/md-pages/inputhandling.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Input Management
|
||||
|
||||
Using the function [registerAction()](@ref InputManager#registerAction) Keys (both key press and key release) can be mapped to do certain actions such as moving an entity. Example code can be found within the template
|
||||
14
docs/md-pages/main.md
Normal file
14
docs/md-pages/main.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Welcome to the VEGO library documentation
|
||||
|
||||
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.
|
||||
|
||||
The base functionality can be split into a few major sections:
|
||||
- [Quickstart guide for setting up the library](@ref md_docs_2md-pages_2quickstart)
|
||||
- [Building an environment using Tiled and tmx](@ref md_docs_2md-pages_2tilemaps)
|
||||
- [Entities and Components](@ref md_docs_2md-pages_2entitiesAndComponents)
|
||||
- [Input Management](@ref md_docs_2md-pages_2inputhandling)
|
||||
- [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
|
||||
|
||||
Example code and quick start docu for each relevant function can be found within the template files themselves, use GameImplementation.cpp as a starting point.
|
||||
20
docs/md-pages/quickstart.md
Normal file
20
docs/md-pages/quickstart.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Quickstart guide for setting up the library
|
||||
|
||||
This guide's purpose is to get developers from 0 to being able to create their game in the quickest and most uncomplicated way possible. Therefore it will only go over the bare minimum to get everything up and running for implementation guides check out the other sections on the welcome page.
|
||||
|
||||
## Installations and tools
|
||||
|
||||
Go to the github repository and download the setup file for your OS (windows and linux supported). This file needs to be executed in the folder you want to start your project in which will start the initial setup. While you can also manually download all of the necessary tools, this setup file acts as a central automated executable to streamline and expedite the non-game development aspect of this process which is why it is highly recommended.
|
||||
The tools downloaded are:
|
||||
- mingw(win)/gcc(linux)
|
||||
- CMake
|
||||
- Tiled (Installer)
|
||||
- Git
|
||||
|
||||
It will also automatically download the library and templates to start a project with.
|
||||
The only manual step required of the user is to finalize the installation of Tiled in order to use it for the creation of maps. For this simply double click the downloaded setup file and go through the installation wizard. After it is installed the .msi file can be deleted.
|
||||
|
||||
After this is completed there should be a folder named vego, with everything necessary in it.
|
||||
The optional templates will be under `vego/my_game/include` and `vego/my_game/src`. Even if you choose not to use them still place your .h files in include and your .cpp files in src. Once setup, open the project folder in the IDE of your choosing, building and compiling should work using the associated compilation script as it is “IDE Agnostic”. For actual development it is recommended to look into the preexisting files in the template. Within them inline short explanations and code snippets can be found that act as a guide for your own implementation of features.
|
||||
|
||||
|
||||
41
docs/md-pages/tilemaps.md
Normal file
41
docs/md-pages/tilemaps.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Building an environment using Tiled and tmx
|
||||
|
||||
see also: [the official Tiled documentation](https://doc.mapeditor.org/en/stable/manual/introduction/#getting-started)
|
||||
|
||||
After opening Tiled, select "New Map", a custom size measured in tiles and as tile size select 32x32 as this is the size the library currently supports.
|
||||
|
||||
### Create a New Tileset
|
||||
|
||||
In the editor, go to the lower-right corner and select "New Tileset".
|
||||
|
||||
Give your tileset a name.
|
||||
|
||||
Make sure to select "Embed in map".
|
||||
|
||||
Choose your tilesheet as the source.
|
||||
|
||||
### Draw Your Environment
|
||||
|
||||
Once imported, you can select tiles from the tileset and use them to build your environment.
|
||||
|
||||
### Understand Layers in Tiled
|
||||
|
||||
Tiled allows you to use multiple layers for organizing your map.
|
||||
|
||||
You need to give your Layers seperate z-Indices to decide their rendering order, the lower the number the earlier it gets rendered.
|
||||
|
||||
In order to do this select a layer.
|
||||
|
||||
Add a new int property named "zIndex" and give it a number starting with 0 to decide when to render it (0 gets rendered first etc.).
|
||||
|
||||
Important: Tiles that should have collision must be placed on a separate layer.
|
||||
|
||||
### Set Up Collision
|
||||
|
||||
Select the layer you want to have collision.
|
||||
|
||||
Right-click and go to "Custom Properties".
|
||||
|
||||
Add a new boolean property named "collision" and tick the checkbox.
|
||||
|
||||
Any tile placed on this layer will now automatically have collision—meaning moving entities cannot pass through them.
|
||||
@ -7,23 +7,31 @@
|
||||
|
||||
class TransformComponent;
|
||||
|
||||
//! \brief Adds a collision box to an entity when added via entity.addComponent()
|
||||
class ColliderComponent : public Component
|
||||
{
|
||||
public:
|
||||
SDL_Rect collider;
|
||||
const char* tag;
|
||||
TransformComponent* transform;
|
||||
bool hasCollision; //added for removing collision of destroyed projectiles
|
||||
float hitboxScale; //adds a seperate variable for the scale of the hitbox (not the sprite) so each sprite can have a different hitbox size if needed
|
||||
|
||||
bool isProjectile = false;
|
||||
SDL_Rect& getCollider() { return collider; } //!< \returns the collider of the entity
|
||||
const char* getTag() const { return tag; } //!< \returns the tag of the entity
|
||||
bool hasCollision() const { return collision; } //!< \returns the collision state of the entity
|
||||
|
||||
//! \brief Constructor for ColliderComponent
|
||||
//! \param tag The tag of the collider, can be any char*
|
||||
ColliderComponent(const char* tag);
|
||||
|
||||
//! \brief Constructor for ColliderComponent
|
||||
//! \param tag The tag of the collider, can be any char*
|
||||
//! \param hitboxScale The scale of the collider, used to scale the collider size, default is 1.0f and takes up the 32x32 pixels
|
||||
ColliderComponent(const char* tag, float hitboxScale);
|
||||
|
||||
void init() override;
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
//! \brief Removes the collision of an entity
|
||||
void removeCollision();
|
||||
|
||||
void handleCollision(Vector2D& characterPos, SDL_Rect& characterCollider, SDL_Rect& componentCollider);
|
||||
private:
|
||||
SDL_Rect collider;
|
||||
const char* tag;
|
||||
TransformComponent* transform;
|
||||
bool collision; //added for removing collision of destroyed projectiles
|
||||
float hitboxScale; //adds a seperate variable for the scale of the hitbox (not the sprite) so each sprite can have a different hitbox size if needed
|
||||
};
|
||||
@ -27,6 +27,7 @@ constexpr uint8_t DIRECTION_C = 4;
|
||||
using IntersectionBitSet = std::bitset<DIRECTION_C>;
|
||||
// [IntersectionBitSet]
|
||||
|
||||
//! \brief Class responsible for collision detection and handling
|
||||
class CollisionHandler
|
||||
{
|
||||
private:
|
||||
@ -38,7 +39,11 @@ public:
|
||||
manager(mManager) { };
|
||||
~CollisionHandler();
|
||||
|
||||
static IntersectionBitSet getIntersection( // intersections relative to entityA
|
||||
//! \brief Checks for intersections relative to entityA
|
||||
//! \param entityA The first entity to check against
|
||||
//! \param entityB The second entity to check against
|
||||
//! \param posModA Modifier to apply to entityA's position before checking collisions
|
||||
static IntersectionBitSet getIntersection(
|
||||
Entity* entityA,
|
||||
Entity* entityB,
|
||||
Vector2D posModA = Vector2D(0,0),
|
||||
|
||||
@ -34,23 +34,15 @@ using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Used for rendering order (last is highest) or retrieving entities of group
|
||||
* \todo Label used in singular entity shouldn't use plural
|
||||
* \todo HEARTS are rendered above POWERUPS, missleading order
|
||||
* \todo PROJECTILE are rendered above POWERUPS, missleading order
|
||||
* \todo Generalize HEARTS as UI or similar
|
||||
*/
|
||||
//! \brief Some premade Entity groups used to avoid checking all entities for everything all of the time
|
||||
enum class GroupLabel
|
||||
{
|
||||
MAPTILES, //!< Entity using TileComponent
|
||||
PLAYERS, //!< Primary entity in player controll
|
||||
ENEMIES, //!< \deprecated All players now grouped as Entity::PLAYERS
|
||||
MAPTILES, //!< Entity using TileComponent, internal use
|
||||
PLAYERS, //!< Primary entity in player control, used to be able to interact with pickupables
|
||||
COLLIDERS, //!< Fixed collider entity, e.g. a wall
|
||||
PROJECTILE, //!< \todo Document
|
||||
HEARTS, //!< \todo Document
|
||||
POWERUPS //!< \todo Document
|
||||
POWERUPS //!< \todo Document
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -70,13 +62,12 @@ public:
|
||||
this->getComponent<ColliderComponent>().removeCollision();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
bool hasGroup(Group mGroup); //!< \sa GroupLabel
|
||||
void addGroup(Group mGroup); //!< \sa GroupLabel
|
||||
void delGroup(Group mGroup); //!< \sa GroupLabel
|
||||
//! \returns bitset with true on position GroupLabel if the entity belongs to group
|
||||
//! \sa GroupLabel
|
||||
std::bitset<MAX_GROUPS> getGroupBitSet();
|
||||
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
|
||||
|
||||
//! \sa Manager
|
||||
Manager& getManager() { return manager; };
|
||||
@ -102,12 +93,17 @@ public:
|
||||
return *c;
|
||||
};
|
||||
|
||||
//! \brief Access a specific component of an entity
|
||||
//! \tparam T Type of component to access
|
||||
//! \return Reference to component of type T
|
||||
template <typename T> T& getComponent() const //!< \todo: rewrite to use optionals
|
||||
{
|
||||
auto ptr(componentArray[getComponentTypeID<T>()]);
|
||||
return *static_cast<T*>(ptr);
|
||||
}
|
||||
|
||||
//! \brief Access a specific component of an entity as a pointer
|
||||
//! \tparam T Type of component to access
|
||||
//! \return Pointer to component of type T
|
||||
template <typename T> std::shared_ptr<T> getComponentAsPointer() const
|
||||
{
|
||||
return std::static_pointer_cast<T>(components.at(getComponentTypeID<T>()));
|
||||
|
||||
@ -9,13 +9,11 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
//! \brief InputManager class to handle input events and actions
|
||||
//! \details This class manages input events, allowing for the registration of actions and their corresponding key bindings.
|
||||
class InputManager {
|
||||
public:
|
||||
enum class EventType {
|
||||
KeyDown,
|
||||
KeyUp
|
||||
};
|
||||
|
||||
//! \brief A list of every key that can be bound to an action
|
||||
enum class Key
|
||||
{
|
||||
UP,
|
||||
@ -99,6 +97,10 @@ public:
|
||||
GRAVE
|
||||
};
|
||||
|
||||
//! \brief InputAction struct to represent an action and its bindings
|
||||
//! \param name The name of the action
|
||||
//! \param bindings The keys that are bound to this action
|
||||
//! \param callback The function to call when the action is triggered
|
||||
struct InputAction {
|
||||
std::string name;
|
||||
std::vector<Key> bindings;
|
||||
@ -110,9 +112,18 @@ public:
|
||||
|
||||
void init(); // see if necessary
|
||||
void processEvents();
|
||||
void registerAction(const std::string& actionName, const std::vector<Key>& keys, std::function<void(bool)> callback, const std::string& context);
|
||||
//! \brief Register an action with a name, key bindings, and a callback function
|
||||
//! \param actionName The name of the action
|
||||
//! \param keys The keys that are bound to this action
|
||||
//! \param callback The function to call when the action is triggered
|
||||
//! \param context The context in which the action is valid can be used to switch between e.g. gameplay and menu so the same keys can be used for different actions
|
||||
void registerAction(const std::string& actionName, const std::vector<Key>& keys, std::function<void(bool)> callback, const std::string& context = "Default");
|
||||
|
||||
//! \brief set the active context, is "Default" by default
|
||||
//! \param context The name of the context to set as active
|
||||
void setActiveContext(const std::string& context);
|
||||
|
||||
//! \brief Get the active context
|
||||
std::string getActiveContext() const;
|
||||
|
||||
//void rebindAction(const std::string& actionName, const std::vector<Key>& newBindings, const std::string& context);
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
//! \brief InteractionComponent class to handle interaction events
|
||||
//! \details This class manages interaction events, allowing for the registration of a callback function to be called when an interaction event is triggered.
|
||||
class InteractionComponent : public Component, public InteractionListener
|
||||
{
|
||||
public:
|
||||
@ -14,6 +16,7 @@ public:
|
||||
*/
|
||||
InteractionComponent(std::function<void(void*,void*)> callback);
|
||||
|
||||
void init() override;
|
||||
/**
|
||||
* @brief Internal function to be called when an interaction event is triggered.
|
||||
*/
|
||||
|
||||
@ -29,13 +29,18 @@ public:
|
||||
//! \sa Entity::destroy()
|
||||
void refresh();
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
void addToGroup(Entity* mEntity, Group mGroup); //!< \todo `friend` to Entity
|
||||
std::vector<Entity*>& getGroup(Group mGroup); //!< \returns std::vector containing all entities in group Entity::GroupLabel
|
||||
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
|
||||
|
||||
//! \brief Returns all entities currently loaded in the game
|
||||
std::vector<Entity*> getAll(); //!< \returns std::vector containing all entities
|
||||
|
||||
//! \brief Add a new entity to the game
|
||||
Entity& addEntity(); //!< Creates and returns a new, empty entity
|
||||
|
||||
/// \deprecated Use \ref VEGO_Game() instead
|
||||
GameInternal* getGame() { return this->game; };
|
||||
|
||||
private:
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <tmxlite/Types.hpp>
|
||||
|
||||
class GameInternal;
|
||||
//! \brief Class responsible for the creation and management of the map or background
|
||||
class Map
|
||||
{
|
||||
public:
|
||||
@ -21,6 +22,7 @@ public:
|
||||
* \sa Map::generateTiles()
|
||||
*/
|
||||
Map(const char* path);
|
||||
//! \brief Used to generate the tiles of a previously loaded map
|
||||
void generateTiles(); //!< Generates the map based on the loaded definition
|
||||
private:
|
||||
// struct required for initialisation
|
||||
@ -45,7 +47,7 @@ private:
|
||||
std::vector<std::function<void()>> tileConstructors;
|
||||
|
||||
void loadTileLayer(const tmx::TileLayer& layer);
|
||||
static void addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, std::string texturePath, bool hasCollision);
|
||||
static void addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, std::string texturePath, bool collision);
|
||||
|
||||
template<typename T>
|
||||
static std::optional<T> getLayerProperty(const std::vector<tmx::Property>& properties, std::string propertyName) { return std::nullopt; };
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include <functional>
|
||||
#include "Component.h"
|
||||
|
||||
//! \brief PickupComponent class to handle pickup events
|
||||
//! \details This class manages pickup events, allowing for the registration of a callback function to be called when an entity with this component collides with another entity that has the "players" group label.
|
||||
class PickupComponent : public Component
|
||||
{
|
||||
public:
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "RenderObject.h"
|
||||
|
||||
class TransformComponent;
|
||||
//! \brief SpriteComponent class to handle sprite rendering and animation
|
||||
|
||||
class SpriteComponent : public Component, public RenderObject
|
||||
{
|
||||
@ -45,9 +46,27 @@ public:
|
||||
|
||||
|
||||
|
||||
//! \brief Constructor for SpriteComponent
|
||||
//! \param texture The texture to be used for the sprite, must be a Texture enum
|
||||
//! \brief 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, used for rendering position
|
||||
//! \param yOffset The y offset of the sprite, used for rendering position
|
||||
//! \brief 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);
|
||||
//! \param texture The texture to be used for the sprite, must be a char* path
|
||||
//! \param xOffset The x offset of the sprite, used for rendering position
|
||||
//! \param yOffset The y offset of the sprite, used for rendering position
|
||||
//! \brief 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);
|
||||
//! \brief used for animated sprites
|
||||
//! \param texture The texture to be used for the sprite, must be a Texture enum
|
||||
//! \param isAnimated Whether the sprite is animated or not
|
||||
//! \param animationList The list of animations to be used for the sprite
|
||||
//! \param defaultAnimation The default animation to be used for the sprite when it first gets loaded
|
||||
//! \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,
|
||||
bool isAnimated,
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
#include "Constants.h"
|
||||
#include "DataComponent.h"
|
||||
|
||||
//! \brief Adds a transform to an entity when added via entity.addComponent()
|
||||
//! \details The transform component is responsible for the position, direction and size of an entity. It is used to move the entity in the game world and to determine its size and position on the screen.
|
||||
class TransformComponent : public Component
|
||||
{
|
||||
public:
|
||||
@ -15,12 +17,12 @@ public:
|
||||
int width = 32;
|
||||
int scale = 1;
|
||||
|
||||
//! \attention in order to allow an entity to move the stat "speed" must be set in the DataComponent (written exactly like that and set to any positive int value, 0 will lead to no movement, negative numbers to backwards movement)
|
||||
explicit TransformComponent(int scale = 1);
|
||||
TransformComponent(float x, float y, int scale = 1);
|
||||
TransformComponent(float x, float y, int w, int h, int scale = 1);
|
||||
|
||||
void init() override;
|
||||
/*! TODO: document usage of collision handler */
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void setPositionAfterCollision(Vector2D& positionChange);
|
||||
int getSpeed();
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
ColliderComponent::ColliderComponent(const char* tag)
|
||||
{
|
||||
this->tag = tag;
|
||||
this->hasCollision = true;
|
||||
this->collision = true;
|
||||
this->hitboxScale = 1;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ ColliderComponent::ColliderComponent(const char* tag, float hitboxScale) //addin
|
||||
{
|
||||
this->tag = tag;
|
||||
this->hitboxScale = hitboxScale;
|
||||
this->hasCollision = true;
|
||||
this->collision = true;
|
||||
}
|
||||
|
||||
void ColliderComponent::init()
|
||||
@ -26,10 +26,6 @@ void ColliderComponent::init()
|
||||
entity->addComponent<TransformComponent>();
|
||||
}
|
||||
|
||||
if (strcmp(this->tag, "projectile") == 0) {
|
||||
this->isProjectile = true;
|
||||
}
|
||||
|
||||
transform = &entity->getComponent<TransformComponent>();
|
||||
this->update(0);
|
||||
}
|
||||
@ -46,18 +42,5 @@ void ColliderComponent::update(uint_fast16_t diffTime)
|
||||
|
||||
void ColliderComponent::removeCollision()
|
||||
{
|
||||
this->hasCollision = false;
|
||||
}
|
||||
|
||||
void ColliderComponent::handleCollision(Vector2D& entityPos, SDL_Rect& entityCollider, SDL_Rect& componentCollider)
|
||||
{
|
||||
// collision to right of character
|
||||
if (entityPos.x < componentCollider.x)
|
||||
{
|
||||
entityPos.x = componentCollider.x - entityCollider.w;
|
||||
}
|
||||
else // collision to left of character
|
||||
{
|
||||
entityPos.x = componentCollider.x + componentCollider.w;
|
||||
}
|
||||
this->collision = false;
|
||||
}
|
||||
@ -18,8 +18,8 @@ IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* en
|
||||
!entityB->hasComponent<ColliderComponent>())
|
||||
return std::bitset<DIRECTION_C>();
|
||||
|
||||
SDL_Rect colliderA = entityA->getComponent<ColliderComponent>().collider;
|
||||
SDL_Rect colliderB = entityB->getComponent<ColliderComponent>().collider;
|
||||
SDL_Rect colliderA = entityA->getComponent<ColliderComponent>().getCollider();
|
||||
SDL_Rect colliderB = entityB->getComponent<ColliderComponent>().getCollider();
|
||||
|
||||
colliderA.x += posModA.x;
|
||||
colliderA.y += posModA.y;
|
||||
@ -61,7 +61,7 @@ IntersectionBitSet CollisionHandler::getIntersectionWithBounds(Entity* entity, V
|
||||
if (!entity->hasComponent<ColliderComponent>())
|
||||
return std::bitset<DIRECTION_C>();
|
||||
|
||||
SDL_Rect* collider = &entity->getComponent<ColliderComponent>().collider;
|
||||
SDL_Rect* collider = &entity->getComponent<ColliderComponent>().getCollider();
|
||||
|
||||
std::bitset<DIRECTION_C> intersections;
|
||||
|
||||
@ -152,8 +152,8 @@ Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
||||
{
|
||||
if (!entity->hasComponent<ColliderComponent>()) return nullptr;
|
||||
for (auto& collider : getColliders(groupLabels, excludedEntities)) {
|
||||
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
|
||||
if (SDL_HasRectIntersection(&rect, &collider->collider)) {
|
||||
SDL_Rect rect = entity->getComponent<ColliderComponent>().getCollider() + posMod;
|
||||
if (SDL_HasRectIntersection(&rect, &collider->getCollider())) {
|
||||
return collider->entity;
|
||||
}
|
||||
}
|
||||
@ -175,8 +175,8 @@ bool CollisionHandler::getAnyIntersection<bool>(
|
||||
{
|
||||
if (!entity->hasComponent<ColliderComponent>()) return false;
|
||||
for (auto& collider : getColliders(groupLabels, excludedEntities)) {
|
||||
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
|
||||
if (SDL_HasRectIntersection(&rect, &collider->collider)) {
|
||||
SDL_Rect rect = entity->getComponent<ColliderComponent>().getCollider() + posMod;
|
||||
if (SDL_HasRectIntersection(&rect, &collider->getCollider())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,7 +253,6 @@ void InputManager::registerAction(const std::string& actionName, const std::vect
|
||||
for (const auto& key : keys) {
|
||||
actionsByContextAndKey[context][key].emplace_back(storedAction);
|
||||
}
|
||||
std::cout << "Registered action: " << storedAction << " in context: " << context << std::endl;
|
||||
}
|
||||
|
||||
std::vector<InputManager::InputAction*> InputManager::getActionsByKey(const Key key) const {
|
||||
@ -271,7 +270,6 @@ std::vector<InputManager::InputAction*> InputManager::getActionsByKey(const Key
|
||||
|
||||
void InputManager::setActiveContext(const std::string& context) {
|
||||
activeContext = context;
|
||||
std::cout << "Active context set to: " << activeContext << std::endl;
|
||||
}
|
||||
|
||||
std::string InputManager::getActiveContext() const {
|
||||
@ -286,14 +284,12 @@ SDL_AppResult InputManager::handleEvent(SDL_EventType type, SDL_Event* const eve
|
||||
{ return pair.second == event->key.scancode; });
|
||||
|
||||
if (keyIt != keyMap.end()) {
|
||||
std::cout << "in != keymap.end" << std::endl;
|
||||
|
||||
Key pressedKey = keyIt->first;
|
||||
auto keyActions = actionsByContextAndKey[activeContext];
|
||||
auto it = keyActions.find(pressedKey);
|
||||
if (it != keyActions.end()) {
|
||||
for (auto& action : it->second) {
|
||||
std::cout << "Action triggered: " << action->name << " in context: " << activeContext << std::endl;
|
||||
action->callback(type == SDL_EVENT_KEY_UP);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,11 @@
|
||||
#include "VEGO.h"
|
||||
|
||||
InteractionComponent::InteractionComponent(std::function<void(void*,void*)> callback) : interactionCallback(callback)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InteractionComponent::init()
|
||||
{
|
||||
VEGO_Game().interactionManager->registerListener(this->entity->getComponentAsPointer<InteractionComponent>());
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ void Map::loadTileLayer(const tmx::TileLayer& layer)
|
||||
this->tileConstructors.insert(this->tileConstructors.end(), tileConstructorRange.begin(), tileConstructorRange.end());
|
||||
}
|
||||
|
||||
void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, std::string texturePath, bool hasCollision)
|
||||
void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, std::string texturePath, bool collision)
|
||||
{
|
||||
auto& tile(VEGO_Game().manager.addEntity());
|
||||
|
||||
@ -170,7 +170,7 @@ void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int
|
||||
tile.addComponent<SpriteComponent>(texturePath.c_str(), v, u, zIndex); // why does uv need to be reversed?
|
||||
//TODO: also implement updated map stuff for this
|
||||
|
||||
if (hasCollision) {
|
||||
if (collision) {
|
||||
// tag currently does not have a clear purposes, TODO: figure out appropriate tag name
|
||||
tile.addComponent<ColliderComponent>("hello I am a collider of a tile!");
|
||||
tile.addGroup((size_t)Entity::GroupLabel::MAPTILES);
|
||||
|
||||
@ -39,6 +39,8 @@ void PickupManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pi
|
||||
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
||||
}
|
||||
|
||||
// \internal
|
||||
// \brief Calculates a random spawn position for the powerup
|
||||
Vector2D PickupManager::calculateSpawnPosition()
|
||||
{
|
||||
Vector2D spawnPos = Vector2D(-1, -1);
|
||||
@ -52,7 +54,7 @@ Vector2D PickupManager::calculateSpawnPosition()
|
||||
conflict = false;
|
||||
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
||||
{
|
||||
if (SDL_HasRectIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
|
||||
if (SDL_HasRectIntersection(&spawnRect, &cc->getCollider()) && strcmp(cc->getTag(), "projectile"))
|
||||
{
|
||||
conflict = true;
|
||||
break;
|
||||
|
||||
@ -98,6 +98,10 @@ void SpriteComponent::draw()
|
||||
|
||||
void SpriteComponent::playAnimation(std::string type)
|
||||
{
|
||||
if (animations == nullptr) {
|
||||
SDL_SetError("playAnimation() was called on a sprite without any animations");
|
||||
return;
|
||||
}
|
||||
this->animationIndex = animations->at(type)->index;
|
||||
this->frames = animations->at(type)->frames;
|
||||
this->speed = animations->at(type)->speed;
|
||||
|
||||
@ -51,7 +51,8 @@ void TransformComponent::update(uint_fast16_t diffTime)
|
||||
direction.y * this->getSpeed() * multiplier * diffTime * (1.f/1000)
|
||||
);
|
||||
|
||||
if (this->entity->hasGroup((size_t)Entity::GroupLabel::PLAYERS)){
|
||||
if (this->entity->hasComponent<ColliderComponent>()
|
||||
&& this->entity->getComponent<ColliderComponent>().hasCollision()){
|
||||
this->setPositionAfterCollision(positionChange);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user