![]() |
KTech 1.1.0
C++ 2D terminal game engine library
|
2D physical space for Objects.
More...
#include <collider.hpp>
Public Member Functions | |
| void | Simple (UPoint size, uint8_t type, Point relativePosition=Point(0, 0)) |
Construct a simple Collider (filled rectangle). | |
| void | Write (const std::vector< std::string > &stringVector, uint8_t type, Point relativePosition=Point(0, 0)) |
Construct a complex Collider (2D bitmap). | |
| void | ByTextureCharacter (const Texture &texture, uint8_t type, char excludedCharacter=' ') |
Construct a Collider based on a Texture's character values. | |
| void | ByTextureBackground (const Texture &texture, uint8_t type, uint8_t alphaThreshold=0) |
Construct a Collider based on a Texture's background values. | |
| void | ByTextureForeground (const Texture &texture, uint8_t type, uint8_t alphaThreshold=0) |
Construct a Collider based on a Texture's foreground values. | |
| auto | operator() (size_t x, size_t y) const -> bool |
Get a value from the 2D bitmap by-value (complex Colliders only). | |
Public Attributes | |
| bool | m_active = true |
Activation status: true means enabled. false means disabled, and will be ignored in Object movement processing. | |
| bool | m_simple |
true means simple, false means complex. | |
| uint8_t | m_type |
Collider type, which determines collision results based on Collision::colliderTypes. | |
| Point | m_rPos |
Relative position to the parent Object. | |
| UPoint | m_size |
| Rectangle size (used in both simple and complex forms). | |
| std::vector< bool > | m_c |
| 1D vector of the 2D bitmap (used only in complex form). | |
2D physical space for Objects.
Objects have a vector of these Colliders (Object::m_colliders), which represents their physical space. Colliders are used to process Object movement in Collision::MoveObject().
Similarly to Texture, there are 2 forms of Colliders: "simple" and "complex".
Colliders.bools which allow them to hold a detailed shape (in contrary to a filled rectangle). This makes them the least efficient in terms of processing and memory. So, minimize your use of complex Colliders to when you need such detailed shapes.Colliders also have a "type", which you can define yourself (or first learn about) in Collision::colliderTypes.
Collision::colliderTypes | void KTech::Collider::ByTextureBackground | ( | const Texture & | texture, |
| uint8_t | type, | ||
| uint8_t | alphaThreshold = 0 ) |
Construct a Collider based on a Texture's background values.
| texture | The base Texture. |
| type | Collider type, as defiend in Collision::colliderTypes. |
| alphaThreshold | Cells with background alpha => this value will be turned on. |
| void KTech::Collider::ByTextureCharacter | ( | const Texture & | texture, |
| uint8_t | type, | ||
| char | excludedCharacter = ' ' ) |
Construct a Collider based on a Texture's character values.
| texture | The base Texture. |
| type | Collider type, as defiend in Collision::colliderTypes. |
| excludedCharacter | Cells with this character will not be turned on. |
| void KTech::Collider::ByTextureForeground | ( | const Texture & | texture, |
| uint8_t | type, | ||
| uint8_t | alphaThreshold = 0 ) |
Construct a Collider based on a Texture's foreground values.
| texture | The base Texture. |
| type | Collider type, as defiend in Collision::colliderTypes. |
| alphaThreshold | Cells with foreground alpha => this value will be turned on. |
|
nodiscard |
Get a value from the 2D bitmap by-value (complex Colliders only).
Useful if you don't want to convert the 2D position to the corresponding index in the bitmap vector (Collider::m_c).
| x | X axis. |
| y | Y axis. |
Construct a simple Collider (filled rectangle).
| size | Rectangle size. |
| type | Collider type, as defiend in Collision::colliderTypes. |
| relativePosition | Relative position to the parent Object. |
| void KTech::Collider::Write | ( | const std::vector< std::string > & | stringVector, |
| uint8_t | type, | ||
| Point | relativePosition = Point(0, 0) ) |
Construct a complex Collider (2D bitmap).
| stringVector | The 2D bitmap representation in a vector of std::strings. If a character is a space (' '), the collider will not exist in the corresponding part of the resulting bitmap. Otherwise, the collider will exist there. |
| type | Collider type, as defiend in Collision::colliderTypes. |
| relativePosition | Relative position to the parent Object. |
Example:
Will construct a Collider that corresponds to the Texture: