2011-06-28 02:07:52 +00:00
|
|
|
/* Abstract instance of a game state.
|
|
|
|
This contains the basic functions for game looping code,
|
|
|
|
and has a fully-functional event handler we can overload later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GAME_STATE_H_
|
|
|
|
#define _GAME_STATE_H_
|
|
|
|
|
|
|
|
#include "mainevent.h"
|
2011-06-28 02:35:52 +00:00
|
|
|
#include <SDL.h>
|
2011-06-28 02:07:52 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
using std::exception;
|
|
|
|
using std::stack;
|
|
|
|
|
|
|
|
class StateExit : public exception {};
|
|
|
|
|
|
|
|
class GameState : public MainEvent
|
|
|
|
{
|
|
|
|
public:
|
2011-06-30 21:21:46 +00:00
|
|
|
GameState(stack<GameState*>* state_stack, SDL_Surface* display)
|
|
|
|
{ this->state_stack = state_stack, this->display = display; }
|
2011-06-29 01:38:18 +00:00
|
|
|
virtual ~GameState() {}
|
2011-06-28 02:07:52 +00:00
|
|
|
|
|
|
|
virtual bool init() = 0;
|
2011-06-30 21:21:46 +00:00
|
|
|
void execute() throw(StateExit);
|
2011-06-28 02:35:52 +00:00
|
|
|
|
|
|
|
protected:
|
2011-06-29 01:38:18 +00:00
|
|
|
virtual void iterate() = 0;
|
|
|
|
virtual void render() = 0;
|
|
|
|
|
2011-06-30 21:21:46 +00:00
|
|
|
void on_exit();
|
|
|
|
|
|
|
|
stack<GameState*>* state_stack;
|
2011-06-28 02:35:52 +00:00
|
|
|
SDL_Surface* display;
|
2011-06-28 02:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|