SDL Breakout Engine  0.1.0
An implementation of a Breakout game using sdl, implemented with efficient resource management.
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
GameObject Class Reference

#include <GameObject.hpp>

Inheritance diagram for GameObject:
GUIElement Brick MovingGUIElement Ball

Public Member Functions

 GameObject (const std::string &tag)
 
 GameObject (const Vector3D &position)
 
 GameObject (const Vector3D &position, const std::string &tag)
 
 GameObject (const Vector3D &position, const Vector3D &size)
 
 GameObject (const Vector3D &position, const Vector3D &size, const std::string &tag)
 
void Update (const Vector3D &position)
 
Vector3D GetSize ()
 
Vector3D GetSize () const
 
const Vector3D_GetPosition () const
 
void DebugRender (SDL_Renderer *renderer)
 
virtual void Hit (const std::string &tag)
 
 GameObject ()
 default constructor for a gameobject More...
 

Public Attributes

std::string mTag = ""
 the name of this object, should be unique to other objects unless grouping is desired. More...
 
bool alive = true
 whether this object is alive or not. More...
 

Protected Attributes

int mWidth = 0
 internal width More...
 
int mHeight = 0
 internal height More...
 
Vector3D mPosition = Vector3D(0, 0, 0)
 internal position More...
 
Vector3D startPosition
 start position More...
 

Friends

std::ostream & operator<< (std::ostream &os, const GameObject &obj)
 overload for << operator More...
 

Detailed Description

Describes a general GameObject which can either be subclassed to override functionality, or instantiated in its own right.

A GameObject is solely aware of its position and size. If needed it can be rendered to the screen in the form of a rectangle (the objects bounding box), however this is solely for debugging and is not recommended as an actual drawing method.

A GameObject is allowed to start with no position or size for convenience. Attempting to draw said object is undefined behavior.

GameObject supports 3D space.

Todo:
GameObject supports a weak notion of alive-ness but could use a more OOP approach, and also shouldn't necessarily enforce all objects to follow it's suit.

Constructor & Destructor Documentation

GameObject::GameObject ( const std::string &  tag)

the simplest constructor, just tag the object.

Parameters
tagwhat to name it.
GameObject::GameObject ( const Vector3D position)

Give the object a position, unnamed.

Parameters
positionthe objects position
GameObject::GameObject ( const Vector3D position,
const std::string &  tag 
)

Give the named object a position.

Parameters
positionposition
tagtag
GameObject::GameObject ( const Vector3D position,
const Vector3D size 
)

Give the unnamed object a position and size.

Parameters
positionposition
sizethe width, height, and depth that the object occupies.
GameObject::GameObject ( const Vector3D position,
const Vector3D size,
const std::string &  tag 
)

Give the named object a position and size.

Parameters
positionposition
sizesize
tagtag
GameObject::GameObject ( )
default

default constructor for a gameobject

Member Function Documentation

const Vector3D & GameObject::_GetPosition ( ) const

Return the position of this object.

It is uncommon to need this method, in general, try to implement logic within subclasses of GameObject, rather than in an outer graphics program class.

void GameObject::DebugRender ( SDL_Renderer *  renderer)

Render the object to the screen

Parameters
rendererthe renderer to use
Todo:
remove dependency on SDL
Vector3D GameObject::GetSize ( )

Return the size of this object.

Vector3D GameObject::GetSize ( ) const

Return the size of this object.

void GameObject::Hit ( const std::string &  tag)
virtual

Notify this object that it has collided with an object of the given tag.

Parameters
tagthe object that collided with this.
Todo:
expand on the concept of callbacks/provide more information to the callback

Reimplemented in Brick.

void GameObject::Update ( const Vector3D position)

Update the GameObject with a given position. Does a direct jump, no interpolation.

Parameters
positionwhere to move to.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const GameObject &  obj 
)
friend

overload for << operator

Member Data Documentation

bool GameObject::alive = true

whether this object is alive or not.

int GameObject::mHeight = 0
protected

internal height

Vector3D GameObject::mPosition = Vector3D(0, 0, 0)
protected

internal position

std::string GameObject::mTag = ""

the name of this object, should be unique to other objects unless grouping is desired.

int GameObject::mWidth = 0
protected

internal width

Vector3D GameObject::startPosition
protected

start position


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