Simple 2D RPG made in C++ and SFML
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#ifndef GAMESTATE
|
|
|
|
#define GAMESTATE
|
|
|
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
|
|
|
class GameState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Initialize(sf::RenderWindow* window) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Update(sf::RenderWindow* window) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Render(sf::RenderWindow* window) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Destroy(sf::RenderWindow* window) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GameStateManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GameStateManager() {
|
|
|
|
this->state = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetWindow(sf::RenderWindow* window) {
|
|
|
|
this->window = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetState(GameState* state) {
|
|
|
|
if(this->state != NULL) {
|
|
|
|
this->state->Destroy(this->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->state = state;
|
|
|
|
if(this->state != NULL) {
|
|
|
|
this->state->Initialize(this->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
if(this->state != NULL) {
|
|
|
|
this->state->Update(this->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Render() {
|
|
|
|
if(this->state != NULL) {
|
|
|
|
this->state->Render(this->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~GameStateManager() {
|
|
|
|
if(this->state != NULL) {
|
|
|
|
this->state->Destroy(this->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sf::RenderWindow* window;
|
|
|
|
GameState* state;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern GameStateManager gameState;
|
|
|
|
|
|
|
|
#endif // GAMESTATE
|
|
|
|
|