Polygon Dash
Loading...
Searching...
No Matches
ComponentCollision Class Reference

Check for collisions with other GameObject entities. More...

Inheritance diagram for ComponentCollision:
ComponentScript IComponent

Public Member Functions

 this (size_t owner, ComponentTransform transform, ComponentPlayerInputJump jump, bool *isActive)
 Set up the script.
 
override void Update ()
 Update internal state of the script.
 
void CheckForFloorCollision (GameObject other, const SDL_Rect *camera)
 Check whether a floor collision will happen on the next frame update.
 
void HandleCollision (GameObject collidee, const SDL_Rect *camera)
 Check for collisions with other GameObject entities.
 
SDL_Rect rotateRect (SDL_Rect rect, float angle, SDL_Rect box)
 Rotate a hitbox rectangle based on the rotation angle of the GameObject.
 
- Public Member Functions inherited from ComponentScript
 this (size_t id)
 Store the owner id.
 
override void Render (SDL_Renderer *renderer, SDL_Rect *camera)
 Render the given script.
 
- Public Member Functions inherited from IComponent

Public Attributes

ComponentTransform mTransform
 The ComponentTransform of the linked GameObject.
 
ComponentPlayerInputJump mJump
 The ComponentPlayerInputJump of the linked GameObject.
 
bool * mIsActive
 A pointer to whether the linked GameObject is active.
 

Detailed Description

Check for collisions with other GameObject entities.

Constructor & Destructor Documentation

◆ this()

ComponentCollision::this ( size_t owner,
ComponentTransform transform,
ComponentPlayerInputJump jump,
bool * isActive )
inline

Set up the script.

Parameters
ownerthe id of the linked GameObject.
transformthe ComponentTransform of the linked GameObject.
jumpthe ComponentPlayerInputJump of the linked GameObject.
isActivea pointer to whether the linked GameObject is active.

Member Function Documentation

◆ CheckForFloorCollision()

void ComponentCollision::CheckForFloorCollision ( GameObject other,
const SDL_Rect * camera )
inline

Check whether a floor collision will happen on the next frame update.

Check whether the current gravity, velocity, and position will result in a floor collision. If so, adjust the gravity/velocity value to land perfectly on top of the floor object.

See also
GameApplication::Update
GameApplication::CheckForLanding
ComponentPlayerInputJump::PreviewNextHeight

◆ HandleCollision()

void ComponentCollision::HandleCollision ( GameObject collidee,
const SDL_Rect * camera )
inline

Check for collisions with other GameObject entities.

If a collision is found, mark the player as inactive since they are now "dead."

Note: this intentionally does not differentiate between floor and enemy collisions. It is expected that CheckForFloorCollision has already been run.

See also
GameApplication::Update
GameApplication::UpdateCollisions

◆ rotateRect()

SDL_Rect ComponentCollision::rotateRect ( SDL_Rect rect,
float angle,
SDL_Rect box )
inline

Rotate a hitbox rectangle based on the rotation angle of the GameObject.

Parameters
rectthe original position.
anglethe angle to rotate by (either 90, 180, 270, or 0).
boxthe rotation point.

◆ Update()

override void ComponentCollision::Update ( )
inlinevirtual

Update internal state of the script.

Implements ComponentScript.


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