KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
KTech::Object Class Reference

World structure that comprises Textures and Colliders, and exists within Layer. More...

#include <object.hpp>

Public Member Functions

 Object (Engine &engine, Point position=Point(0, 0), std::string name="")
 Construct an Object.
 
 Object (Engine &engine, const ID< Layer > &parentLayer, Point position=Point(0, 0), std::string name="")
 Construct an Object and immediately enter a Layer.
 
virtual ~Object ()
 Leave parent Layer (if in one) and remove itself from Memory.
 
auto EnterLayer (const ID< Layer > &layer) -> bool
 Enter a Layer.
 
auto LeaveLayer () -> bool
 Leave the parent Layer.
 
auto Move (Point direction) -> bool
 Move in relation to other Objects in the Layer and their Colliders.
 

Public Attributes

Engineengine
 Parent Engine.
 
const ID< Objectm_id {ID<Object>::Unique()}
 Personal ID.
 
std::string m_name
 String name.
 
ID< Layerm_parentLayer
 Parent Layer.
 
Point m_pos
 World position.
 
std::vector< Texturem_textures = {}
 Textures.
 
std::vector< Colliderm_colliders = {}
 Colliders.
 

Protected Member Functions

virtual auto OnTick () -> bool
 Virtual function called once each tick.
 
virtual void OnMove (Point direction)
 Called by Collision::MoveObject() as a result of this Object moving (voluntarily or passively).
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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 Object.
 
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.
 

Friends

class KTech::Collision
 
class KTech::Memory
 

Detailed Description

World structure that comprises Textures and Colliders, and exists within Layer.

This and Widget are the most commonly inherited-from world structures. It differs from Widget because it can contain Colliders, while Widget is limited to Textures. Widget also has some additional features which are useful for user-interfaces. You can conveniently make player-controlled classes based on Object, such as walking characters (see "simpleplatform" game example).

Constructor & Destructor Documentation

◆ Object() [1/2]

KTech::Object::Object ( Engine & engine,
Point position = Point(0, 0),
std::string name = "" )

Construct an Object.

Parameters
engineParent Engine.
positionWorld position.
nameString name.

◆ Object() [2/2]

KTech::Object::Object ( Engine & engine,
const ID< Layer > & parentLayer,
Point position = Point(0, 0),
std::string name = "" )

Construct an Object and immediately enter a Layer.

Parameters
engineParent Engine.
parentLayerLayer to enter.
positionWorld position.
nameString name.

Member Function Documentation

◆ EnterLayer()

auto KTech::Object::EnterLayer ( const ID< Layer > & layer) -> bool

Enter a Layer.

Parameters
layerThe Layer to enter.
Returns
true if entered Layer. false if the given Layer is already the parent Layer, doesn't exist in Memory, or failed to add this Object.

◆ LeaveLayer()

auto KTech::Object::LeaveLayer ( ) -> bool

Leave the parent Layer.

Returns
true if left the parent Layer. false if the parent Layer failed to remove this Object.

◆ Move()

auto KTech::Object::Move ( Point direction) -> bool

Move in relation to other Objects in the Layer and their Colliders.

This function calls Collision::MoveObject() on itself (on the calling Object; this).

Returns
true if moved. false if blocked.
See also
Collision::MoveObject()

◆ OnBlock()

void KTech::Object::OnBlock ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object blocking another Object.

Parameters
directionThe attempted movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnBlocked()

void KTech::Object::OnBlocked ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object getting blocked by another Object.

Parameters
directionThe attempted movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnMove()

void KTech::Object::OnMove ( Point direction)
protectedvirtual

Called by Collision::MoveObject() as a result of this Object moving (voluntarily or passively).

Parameters
directionThe movement's direction.

◆ OnOverlap()

void KTech::Object::OnOverlap ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object overlapping into another Object.

Parameters
directionThe movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnOverlapExit()

void KTech::Object::OnOverlapExit ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object leaving an overlap with another Object.

Parameters
directionThe movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnOverlapped()

void KTech::Object::OnOverlapped ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object getting overlapped into by another Object.

Parameters
directionThe movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnOverlappedExit()

void KTech::Object::OnOverlappedExit ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of another Object leaving an overlap with this Object.

Parameters
directionThe movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnPush()

void KTech::Object::OnPush ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object pushing another Object.

Parameters
directionThe movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnPushed()

void KTech::Object::OnPushed ( Point direction,
size_t collider,
ID< Object > otherObject,
size_t otherCollider )
protectedvirtual

Called by Collision::MoveObject() as a result of this Object getting pushed.

Parameters
directionThe movement's direction.
colliderThe index of this Object's collider that collided (this->Object::m_colliders[collider]).
otherObjectThe Object that collided with this Object.
otherColliderThe index of otherObject's collider that collided (engine.memory.objects[otherObject]->Object::m_colliders[otherCollider]).

◆ OnTick()

auto KTech::Object::OnTick ( ) -> bool
protectedvirtual

Virtual function called once each tick.

Called by Memory::CallOnTicks().

Returns
bool value, which is explained in Output::ShouldRenderThisTick().
See also
Memory::CallOnTicks()
Output::ShouldRenderThisTick()

The documentation for this class was generated from the following files: