KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
object.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 "../utility/id.hpp"
27#include "../basic/point.hpp"
28#include "collider.hpp"
29#include "texture.hpp"
30
37{
38public:
41 std::string m_name;
43
45 std::vector<Texture> m_textures = {};
46 std::vector<Collider> m_colliders = {};
47
48 Object(Engine& engine, Point position = Point(0, 0), std::string name = "");
49 Object(Engine& engine, const ID<Layer>& parentLayer, Point position = Point(0, 0), std::string name = "");
50 virtual ~Object();
51
52 auto EnterLayer(const ID<Layer>& layer) -> bool;
53 auto LeaveLayer() -> bool;
54
55 auto Move(Point direction) -> bool;
56
57protected:
58 virtual auto OnTick() -> bool;
59 virtual void OnMove(Point direction);
60 virtual void OnPushed(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
61 virtual void OnPush(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
62 virtual void OnBlocked(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
63 virtual void OnBlock(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
64 virtual void OnOverlap(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
65 virtual void OnOverlapExit(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
66 virtual void OnOverlapped(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
67 virtual void OnOverlappedExit(Point direction, size_t collider, ID<Object> otherObject, size_t otherCollider);
68
69 friend class KTech::Collision;
70 friend class KTech::Memory;
71};
Engine component responsible for processing Object movement and collision.
Definition collision.hpp:34
Complete engine containing all engine components.
Definition engine.hpp:41
Engine component responsible for registering all world structures.
Definition memory.hpp:36
World structure that comprises Textures and Colliders, and exists within Layer.
Definition object.hpp:37
const ID< Object > m_id
Personal ID.
Definition object.hpp:40
virtual void OnPushed(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object getting pushed.
Definition object.cpp:135
std::vector< Collider > m_colliders
Colliders.
Definition object.hpp:46
auto Move(Point direction) -> bool
Move in relation to other Objects in the Layer and their Colliders.
Definition object.cpp:99
virtual void OnBlock(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object blocking another Object.
Definition object.cpp:165
Point m_pos
World position.
Definition object.hpp:44
virtual void OnPush(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object pushing another Object.
Definition object.cpp:145
Engine & engine
Parent Engine.
Definition object.hpp:39
virtual void OnBlocked(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object getting blocked by another Object.
Definition object.cpp:155
std::vector< Texture > m_textures
Textures.
Definition object.hpp:45
std::string m_name
String name.
Definition object.hpp:41
virtual auto OnTick() -> bool
Virtual function called once each tick.
Definition object.cpp:115
virtual void OnOverlappedExit(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of another Object leaving an overlap with this Object.
Definition object.cpp:205
virtual void OnOverlapped(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object getting overlapped into by another Objec...
Definition object.cpp:195
virtual void OnOverlapExit(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object leaving an overlap with another Object.
Definition object.cpp:185
virtual void OnMove(Point direction)
Called by Collision::MoveObject() as a result of this Object moving (voluntarily or passively).
Definition object.cpp:125
virtual ~Object()
Leave parent Layer (if in one) and remove itself from Memory.
Definition object.cpp:54
Object(Engine &engine, Point position=Point(0, 0), std::string name="")
Construct an Object.
Definition object.cpp:33
auto LeaveLayer() -> bool
Leave the parent Layer.
Definition object.cpp:79
auto EnterLayer(const ID< Layer > &layer) -> bool
Enter a Layer.
Definition object.cpp:66
virtual void OnOverlap(Point direction, size_t collider, ID< Object > otherObject, size_t otherCollider)
Called by Collision::MoveObject() as a result of this Object overlapping into another Object.
Definition object.cpp:175
ID< Layer > m_parentLayer
Parent Layer.
Definition object.hpp:42
Serializable world structure identifier.
Definition id.hpp:38
2D vector, mostly used to store positions and directions.
Definition point.hpp:30