KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
collider.hpp
1/*
2 KTech, Kaup's C++ 2D terminal game engine library.
3 Copyright (C) 2023-2025 Ethan Kaufman (AKA Kaup)
4
5 This file is part of KTech.
6
7 KTech is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 any later version.
11
12 KTech is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with KTech. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#pragma once
22
23#define KTECH_DEFINITION
24#include "../ktech.hpp"
25#undef KTECH_DEFINITION
26#include "../basic/point.hpp"
27#include "../basic/upoint.hpp"
28
29#include <string>
30#include <vector>
31
46{
47 bool m_active = true;
48
49 bool m_simple;
50 uint8_t m_type;
53 std::vector<bool> m_c;
54
55 void Simple(UPoint size, uint8_t type, Point relativePosition = Point(0, 0));
56 void Write(const std::vector<std::string>& stringVector, uint8_t type, Point relativePosition = Point(0, 0));
57 void ByTextureCharacter(const Texture& texture, uint8_t type, char excludedCharacter = ' ');
58 void ByTextureBackground(const Texture& texture, uint8_t type, uint8_t alphaThreshold = 0);
59 void ByTextureForeground(const Texture& texture, uint8_t type, uint8_t alphaThreshold = 0);
60
61 [[nodiscard]] auto operator()(size_t x, size_t y) const -> bool;
62};
2D physical space for Objects.
Definition collider.hpp:46
UPoint m_size
Rectangle size (used in both simple and complex forms).
Definition collider.hpp:52
void Write(const std::vector< std::string > &stringVector, uint8_t type, Point relativePosition=Point(0, 0))
Construct a complex Collider (2D bitmap).
Definition collider.cpp:75
void ByTextureForeground(const Texture &texture, uint8_t type, uint8_t alphaThreshold=0)
Construct a Collider based on a Texture's foreground values.
Definition collider.cpp:157
Point m_rPos
Relative position to the parent Object.
Definition collider.hpp:51
void Simple(UPoint size, uint8_t type, Point relativePosition=Point(0, 0))
Construct a simple Collider (filled rectangle).
Definition collider.cpp:34
std::vector< bool > m_c
1D vector of the 2D bitmap (used only in complex form).
Definition collider.hpp:53
auto operator()(size_t x, size_t y) const -> bool
Get a value from the 2D bitmap by-value (complex Colliders only).
Definition collider.cpp:185
void ByTextureBackground(const Texture &texture, uint8_t type, uint8_t alphaThreshold=0)
Construct a Collider based on a Texture's background values.
Definition collider.cpp:133
void ByTextureCharacter(const Texture &texture, uint8_t type, char excludedCharacter=' ')
Construct a Collider based on a Texture's character values.
Definition collider.cpp:109
bool m_active
Activation status: true means enabled. false means disabled, and will be ignored in Object movement p...
Definition collider.hpp:47
bool m_simple
true means simple, false means complex.
Definition collider.hpp:49
uint8_t m_type
Collider type, which determines collision results based on Collision::colliderTypes.
Definition collider.hpp:50
2D vector, mostly used to store positions and directions.
Definition point.hpp:30
A CellA-based sprite.
Definition texture.hpp:48
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29