GameKit  0.0.1a
C++ gamedev tools
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
gk::ApplicationState Class Referenceabstract

Abstract base class for game states. More...

#include <ApplicationState.hpp>

Inheritance diagram for gk::ApplicationState:
gk::IDrawable gk::Transformable gk::NonCopyable

Public Member Functions

 ApplicationState (ApplicationState *parent=nullptr)
 Default constructor. More...
 
 ApplicationState (ApplicationState &&)=default
 Defaulted move constructor. More...
 
virtual ~ApplicationState ()=default
 Virtual destructor. More...
 
ApplicationStateoperator= (ApplicationState &&)=default
 Defaulted move assignment operator. More...
 
virtual void onEvent (const SDL_Event &)
 Do an action in response to an SDL event. More...
 
virtual void update ()=0
 Execute actions every game tick. More...
 
ApplicationStateparent ()
 Get the parent of this state. More...
 
void setStateStack (ApplicationStateStack *stateStack)
 Change the stack this state belongs to. More...
 
- Public Member Functions inherited from gk::IDrawable
virtual ~IDrawable ()=default
 Virtual destructor. More...
 
- Public Member Functions inherited from gk::Transformable
virtual ~Transformable ()=default
 
void setPosition (float x, float y, float z=0)
 
void setPosition (const Vector3f &position)
 
void setOrigin (float x, float y, float z=0)
 
void setOrigin (const Vector3f &origin)
 
void setScale (float factorX, float factorY, float factorZ=1)
 
void setScale (const Vector3f &factors)
 
void setRotation (float angle)
 
void setRotation (float angle, const Vector3f &axis)
 
const Vector3fgetPosition () const
 
const Vector3fgetOrigin () const
 
const Vector3fgetScale () const
 
float getRotation () const
 
void move (float offsetX, float offsetY, float offsetZ=0)
 
void move (const Vector3f &offset)
 
void scale (float factorX, float factorY, float factorZ=1)
 
void scale (const Vector3f &factor)
 
void rotate (float angle)
 
void rotate (float angle, const Vector3f &axis)
 
const TransformgetTransform () const
 

Protected Member Functions

void draw (gk::RenderTarget &, gk::RenderStates) const override
 Draw the sprite to a render target. More...
 
- Protected Member Functions inherited from gk::NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
const NonCopyableoperator= (const NonCopyable &)=delete
 

Protected Attributes

ApplicationStatem_parent = nullptr
 Parent to this state. More...
 
ApplicationStateStackm_stateStack = nullptr
 Stack where this state belongs to. More...
 

Detailed Description

Abstract base class for game states.

gk::ApplicationState is a very simple base class for designing your own game states.

Example:

class MyState : public gk::ApplicationState {
public:
...
}
void update() override {
...
}
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override {
...
}
...
};
See also
gk::ApplicationStateStack

Definition at line 30 of file ApplicationState.hpp.

Constructor & Destructor Documentation

§ ApplicationState() [1/2]

gk::ApplicationState::ApplicationState ( ApplicationState parent = nullptr)
inline

Default constructor.

Parameters
parentThe parent of this state

Definition at line 38 of file ApplicationState.hpp.

§ ApplicationState() [2/2]

gk::ApplicationState::ApplicationState ( ApplicationState &&  )
default

Defaulted move constructor.

§ ~ApplicationState()

virtual gk::ApplicationState::~ApplicationState ( )
virtualdefault

Virtual destructor.

Member Function Documentation

§ draw()

void gk::ApplicationState::draw ( gk::RenderTarget ,
gk::RenderStates   
) const
inlineoverrideprotectedvirtual

Draw the sprite to a render target.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gk::IDrawable.

Definition at line 99 of file ApplicationState.hpp.

§ onEvent()

virtual void gk::ApplicationState::onEvent ( const SDL_Event &  )
inlinevirtual

Do an action in response to an SDL event.

Parameters
eventThe event sent from SDL

Definition at line 64 of file ApplicationState.hpp.

§ operator=()

ApplicationState& gk::ApplicationState::operator= ( ApplicationState &&  )
default

Defaulted move assignment operator.

§ parent()

ApplicationState* gk::ApplicationState::parent ( )
inline

Get the parent of this state.

Returns
The parent of this state

Definition at line 81 of file ApplicationState.hpp.

§ setStateStack()

void gk::ApplicationState::setStateStack ( ApplicationStateStack stateStack)
inline

Change the stack this state belongs to.

Parameters
stateStackThe new state stack

Definition at line 89 of file ApplicationState.hpp.

§ update()

virtual void gk::ApplicationState::update ( )
pure virtual

Execute actions every game tick.

This is a pure virtual function that has to be implemented by the derived class to define what the state should do.

Member Data Documentation

§ m_parent

ApplicationState* gk::ApplicationState::m_parent = nullptr
protected

Parent to this state.

Definition at line 104 of file ApplicationState.hpp.

§ m_stateStack

ApplicationStateStack* gk::ApplicationState::m_stateStack = nullptr
protected

Stack where this state belongs to.

Definition at line 106 of file ApplicationState.hpp.


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