Building Game Engines
CollisionComponent Class Reference

Provides functions to detect collision. More...

#include <CollisionComponent.hpp>

Inheritance diagram for CollisionComponent:
Inheritance graph
Collaboration diagram for CollisionComponent:
Collaboration graph

Public Member Functions

 CollisionComponent (int w, int h)
 
 ~CollisionComponent ()
 
void SetCurrPos (int x, int y)
 
std::pair< int, int > GetProcessedPos ()
 
bool CheckCollisionWithWall (bool &onGround)
 
COLLISION_DIRECTION CheckCollisionWithTile (TileMap *currMap, bool &onGround, int collider_type)
 
Position getStartPos ()
 returns the generated start pos More...
 
- Public Member Functions inherited from Component
 Component ()
 
 ~Component ()
 

Detailed Description

Provides functions to detect collision.

Constructor & Destructor Documentation

◆ CollisionComponent()

CollisionComponent::CollisionComponent ( int  w,
int  h 
)

Initialize object's collider with a box size

◆ ~CollisionComponent()

CollisionComponent::~CollisionComponent ( )

Deconstructor of a box collider

Member Function Documentation

◆ CheckCollisionWithTile()

COLLISION_DIRECTION CollisionComponent::CheckCollisionWithTile ( TileMap currMap,
bool &  onGround,
int  collider_type 
)

Process tile collision Type: 1 is player; 2 is monster

◆ CheckCollisionWithWall()

bool CollisionComponent::CheckCollisionWithWall ( bool &  onGround)

Process wall collision

◆ GetProcessedPos()

std::pair< int, int > CollisionComponent::GetProcessedPos ( )

Get the position after collision processed

◆ getStartPos()

Position CollisionComponent::getStartPos ( )

returns the generated start pos

◆ SetCurrPos()

void CollisionComponent::SetCurrPos ( int  x,
int  y 
)

Update the collider pos with the object pos. COuld be improved if we can share a transform component