Platformer
Platformer
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GameObject Class Reference

A GameObject class. More...

#include <GameObject.hpp>

Inheritance diagram for GameObject:
Inheritance graph
Collaboration diagram for GameObject:
Collaboration graph

Public Member Functions

void Update ()
 Updates this GameObject.
 
void Disable ()
 Disables this GameObject.
 
void Enable ()
 Enables this GameObject.
 
bool IsActive () const
 Gets whether this GameObject is active. More...
 
bool IsColliding (const GameObject &other) const
 Gets whether this GameObject is colliding with another. More...
 
SDL_Rect ScreenRegion ()
 Determines the screen region this object takes up. More...
 
template<class C >
std::shared_ptr< C > GetComponent ()
 Gets the first component of type C in the component map or null if none are found. More...
 
template<class C >
std::shared_ptr< GameObjectAddComponent (std::shared_ptr< C > comp)
 Adds a component of type C to the component map. More...
 

Static Public Member Functions

static std::shared_ptr< GameObjectCreate (int posX, int posY, int width, int height, bool isUI=false, bool isPermanent=false)
 Creates a GameObject. More...
 
static std::shared_ptr< GameObjectCreateStandard (int posX, int posY, int width, int height)
 Creates a non-UI, non-permanent GameObject. More...
 

Public Attributes

Vector2 position
 The position of this GameObject.
 
Vector2 scale
 The scale of this GameObject.
 

Private Member Functions

 GameObject (int posX, int posY, int width, int height, bool isUI)
 Constructs a GameObject. More...
 

Static Private Member Functions

template<class Key >
static int GetTypeID ()
 Gets a new unused component id. More...
 

Private Attributes

std::unordered_map< int, std::shared_ptr< Component > > componentMap
 The map of component ids and components for this GameObject.
 
bool active
 Whether or not this GameObject is active.
 
bool isUI
 Whether this GameObject should use direct screen coordinates.
 

Static Private Attributes

static int lastTypeID = 0
 The last component id used.
 

Detailed Description

A GameObject class.

This represents a simple object within our game, having a position, dimensions, and an active state.

Constructor & Destructor Documentation

◆ GameObject()

GameObject::GameObject ( int  posX,
int  posY,
int  width,
int  height,
bool  isUI 
)
private

Constructs a GameObject.

Parameters
posXThe x coordinate of this GameObject
posYThe y coordinate of this GameObject
widthThe width of this GameObject
heightThe height of this GameObject
isUIWhether this GameObject should use direct screen coordinates
Here is the caller graph for this function:

Member Function Documentation

◆ AddComponent()

template<class C >
std::shared_ptr<GameObject> GameObject::AddComponent ( std::shared_ptr< C >  comp)
inline

Adds a component of type C to the component map.

Returns
A shared pointer reference to this GameObject

◆ Create()

std::shared_ptr< GameObject > GameObject::Create ( int  posX,
int  posY,
int  width,
int  height,
bool  isUI = false,
bool  isPermanent = false 
)
static

Creates a GameObject.

Returns
the created GameObject
Parameters
posXThe x coordinate of this GameObject
posYThe y coordinate of this GameObject
widthThe width of this GameObject
heightThe height of this GameObject
isUIWhether this GameObject should use direct screen coordinates
isPermanentWhether this GameObject should persist througt level load
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateStandard()

std::shared_ptr< GameObject > GameObject::CreateStandard ( int  posX,
int  posY,
int  width,
int  height 
)
static

Creates a non-UI, non-permanent GameObject.

Returns
the created GameObject
Parameters
posXThe x coordinate of this GameObject
posYThe y coordinate of this GameObject
widthThe width of this GameObject
heightThe height of this GameObject
Here is the call graph for this function:

◆ GetComponent()

template<class C >
std::shared_ptr<C> GameObject::GetComponent ( )
inline

Gets the first component of type C in the component map or null if none are found.

Returns
The first component found of type C

◆ GetTypeID()

template<class Key >
static int GameObject::GetTypeID ( )
inlinestaticprivate

Gets a new unused component id.

Returns
The new id

◆ IsActive()

bool GameObject::IsActive ( ) const

Gets whether this GameObject is active.

Returns
The GameObject's active state

◆ IsColliding()

bool GameObject::IsColliding ( const GameObject other) const

Gets whether this GameObject is colliding with another.

Returns
The GameObject's collision state
Parameters
otherThe GameObject to check for collisions

◆ ScreenRegion()

SDL_Rect GameObject::ScreenRegion ( )

Determines the screen region this object takes up.

Uses the active camera.

Returns
An SDL_Rect representing the region of the screen.
Here is the call graph for this function:

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