Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
GameObject Class Referenceabstract

Represents a game object in the game. This is the base class for all objects that can be updated, rendered, and checked for collisions. More...

#include <GameObject.h>

Inheritance diagram for GameObject:

Public Member Functions

 GameObject ()
 Instantiate a game object.
 
virtual ~GameObject ()
 
virtual void Update (const GameTime &gameTime)
 Update the object.
 
virtual void Draw (SpriteBatch &spriteBatch)=0
 Render the object.
 
virtual bool IsActive () const
 Flag to determine if the object is active.
 
virtual void Activate ()
 Activate the object.
 
virtual void Deactivate ()
 Deactivate the object.
 
virtual Vector2 & GetPosition ()
 Get the position of the object.
 
virtual Vector2 & GetPreviousPosition ()
 Get the position of the object during the previous frame.
 
virtual std::string ToString () const =0
 Get the string representation of the object.
 
virtual Vector2 GetHalfDimensions () const
 Get the half dimensions of the object.
 
virtual uint32_t GetIndex () const
 Get the index of the object. Each object is assigned a unique ID when created, starting at 0.
 
virtual CollisionType GetCollisionType () const =0
 Get the collision type of the object.
 
virtual float GetCollisionRadius () const
 Get the collision radius of the object.
 
virtual void Hit (const float damage)
 Hits the object with a specified amount of damage.
 
virtual bool HasMask (CollisionType mask) const
 Check if the object has a specific collision bit-mask.
 
virtual bool IsMask (CollisionType mask) const
 
virtual bool IsDrawnByLevel () const
 

Static Public Member Functions

static void SetCurrentLevel (Level *pLevel)
 Set the current level.
 
static Level * GetCurrentLevel ()
 Get the current level.
 

Protected Member Functions

virtual void SetCollisionRadius (const int radius)
 
virtual void SetPosition (const float x, const float y)
 
virtual void SetPosition (const Vector2 &position)
 
virtual void TranslatePosition (const float x, const float y)
 
virtual void TranslatePosition (const Vector2 &offset)
 
virtual bool IsOnScreen () const
 

Detailed Description

Represents a game object in the game. This is the base class for all objects that can be updated, rendered, and checked for collisions.

Definition at line 14 of file GameObject.h.

Constructor & Destructor Documentation

◆ GameObject()

GameObject::GameObject ( )

Instantiate a game object.

Definition at line 9 of file GameObject.cpp.

◆ ~GameObject()

virtual GameObject::~GameObject ( )
inlinevirtual

Definition at line 21 of file GameObject.h.

Member Function Documentation

◆ Activate()

virtual void GameObject::Activate ( )
inlinevirtual

Activate the object.

Definition at line 45 of file GameObject.h.

◆ Deactivate()

virtual void GameObject::Deactivate ( )
inlinevirtual

Deactivate the object.

Definition at line 48 of file GameObject.h.

◆ Draw()

virtual void GameObject::Draw ( SpriteBatch & spriteBatch)
pure virtual

Render the object.

Parameters
spriteBatchA reference to the game's sprite batch, used for rendering.

Implemented in BioEnemyShip, EnemyShip, PlayerShip, Projectile, and Ship.

◆ GetCollisionRadius()

virtual float GameObject::GetCollisionRadius ( ) const
inlinevirtual

Get the collision radius of the object.

Returns
The collision radius of the object.

Definition at line 80 of file GameObject.h.

◆ GetCollisionType()

virtual CollisionType GameObject::GetCollisionType ( ) const
pure virtual

Get the collision type of the object.

Returns
The collision type of the object.

Implemented in EnemyShip, PlayerShip, Projectile, and Ship.

◆ GetCurrentLevel()

static Level * GameObject::GetCurrentLevel ( )
inlinestatic

Get the current level.

Returns
A pointer to the current level.

Definition at line 30 of file GameObject.h.

◆ GetHalfDimensions()

Vector2 GameObject::GetHalfDimensions ( ) const
virtual

Get the half dimensions of the object.

Returns
The half dimensions of the object.
Remarks
Unless overridden, this will return a Vector2 with both coordinates set to the value of the CollisionRadius.
See also
GetCollisionRadius

Reimplemented in PlayerShip.

Definition at line 23 of file GameObject.cpp.

◆ GetIndex()

virtual uint32_t GameObject::GetIndex ( ) const
inlinevirtual

Get the index of the object. Each object is assigned a unique ID when created, starting at 0.

Returns
The index of the object.

Definition at line 72 of file GameObject.h.

◆ GetPosition()

virtual Vector2 & GameObject::GetPosition ( )
inlinevirtual

Get the position of the object.

Returns
The position of the object.

Definition at line 52 of file GameObject.h.

◆ GetPreviousPosition()

virtual Vector2 & GameObject::GetPreviousPosition ( )
inlinevirtual

Get the position of the object during the previous frame.

Returns
The previous position of the object.

Definition at line 56 of file GameObject.h.

◆ HasMask()

virtual bool GameObject::HasMask ( CollisionType mask) const
inlinevirtual

Check if the object has a specific collision bit-mask.

Parameters
maskThe bit-mask to check.
Returns
True if the object has the specified bit-mask.

Definition at line 89 of file GameObject.h.

◆ Hit()

virtual void GameObject::Hit ( const float damage)
inlinevirtual

Hits the object with a specified amount of damage.

Parameters
damageThe amount of damage to apply.

Reimplemented in EnemyShip, and Ship.

Definition at line 84 of file GameObject.h.

◆ IsActive()

virtual bool GameObject::IsActive ( ) const
inlinevirtual

Flag to determine if the object is active.

Returns
True if the object is active.

Definition at line 42 of file GameObject.h.

◆ IsDrawnByLevel()

virtual bool GameObject::IsDrawnByLevel ( ) const
inlinevirtual

Definition at line 93 of file GameObject.h.

◆ IsMask()

virtual bool GameObject::IsMask ( CollisionType mask) const
inlinevirtual

Definition at line 91 of file GameObject.h.

◆ IsOnScreen()

bool GameObject::IsOnScreen ( ) const
protectedvirtual

Definition at line 49 of file GameObject.cpp.

◆ SetCollisionRadius()

virtual void GameObject::SetCollisionRadius ( const int radius)
inlineprotectedvirtual

Definition at line 98 of file GameObject.h.

◆ SetCurrentLevel()

static void GameObject::SetCurrentLevel ( Level * pLevel)
inlinestatic

Set the current level.

Parameters
pLevelA pointer to the current level.
Remarks
This is called automatically by the level class when a game object is added to it.

Definition at line 26 of file GameObject.h.

◆ SetPosition() [1/2]

void GameObject::SetPosition ( const float x,
const float y )
protectedvirtual

Definition at line 28 of file GameObject.cpp.

◆ SetPosition() [2/2]

void GameObject::SetPosition ( const Vector2 & position)
protectedvirtual

Definition at line 34 of file GameObject.cpp.

◆ ToString()

virtual std::string GameObject::ToString ( ) const
pure virtual

Get the string representation of the object.

Returns
The string representation of the object.

Implemented in EnemyShip, PlayerShip, Projectile, and Ship.

◆ TranslatePosition() [1/2]

void GameObject::TranslatePosition ( const float x,
const float y )
protectedvirtual

Definition at line 39 of file GameObject.cpp.

◆ TranslatePosition() [2/2]

void GameObject::TranslatePosition ( const Vector2 & offset)
protectedvirtual

Definition at line 44 of file GameObject.cpp.

◆ Update()

void GameObject::Update ( const GameTime & gameTime)
virtual

Update the object.

Parameters
gameTimeA reference to the game time object.

Reimplemented in BioEnemyShip, EnemyShip, PlayerShip, Projectile, and Ship.

Definition at line 15 of file GameObject.cpp.


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