2016-10-17 00:56:51 +02:00
|
|
|
#ifndef RWGAME_STATE_HPP
|
|
|
|
#define RWGAME_STATE_HPP
|
2014-08-12 22:15:26 +02:00
|
|
|
#include <render/ViewCamera.hpp>
|
2016-09-09 22:13:20 +02:00
|
|
|
#include "GameWindow.hpp"
|
2013-12-27 00:18:55 +01:00
|
|
|
#include "MenuSystem.hpp"
|
2018-02-27 23:25:05 +01:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_events.h>
|
2013-12-27 00:18:55 +01:00
|
|
|
|
2014-09-16 20:22:43 +02:00
|
|
|
class RWGame;
|
|
|
|
class GameWorld;
|
2016-10-17 00:56:51 +02:00
|
|
|
class StateManager;
|
2014-09-16 20:22:43 +02:00
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
class State {
|
|
|
|
public:
|
2016-10-18 23:00:53 +02:00
|
|
|
std::shared_ptr<Menu> menu;
|
|
|
|
std::shared_ptr<Menu> nextMenu;
|
2016-09-09 22:13:20 +02:00
|
|
|
|
|
|
|
RWGame* game;
|
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
State(RWGame* game) : game(game) {
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void enter() = 0;
|
|
|
|
virtual void exit() = 0;
|
|
|
|
|
|
|
|
virtual void tick(float dt) = 0;
|
|
|
|
|
|
|
|
virtual void draw(GameRenderer* r) {
|
|
|
|
if (getCurrentMenu()) {
|
|
|
|
getCurrentMenu()->draw(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 01:06:39 +01:00
|
|
|
virtual ~State() = default;
|
2016-09-09 22:13:20 +02:00
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
void enterMenu(const std::shared_ptr<Menu>& menu) {
|
2016-09-09 22:13:20 +02:00
|
|
|
nextMenu = menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu* getCurrentMenu() {
|
|
|
|
if (nextMenu) {
|
2016-10-18 23:00:53 +02:00
|
|
|
menu = nextMenu;
|
2016-09-09 22:13:20 +02:00
|
|
|
nextMenu = nullptr;
|
|
|
|
}
|
2016-10-18 23:00:53 +02:00
|
|
|
return menu.get();
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void handleEvent(const SDL_Event& e);
|
|
|
|
|
2016-11-30 00:28:53 +01:00
|
|
|
virtual const ViewCamera& getCamera(float alpha);
|
2016-09-09 22:13:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns false if the game world should not should
|
|
|
|
* not update while this state is active
|
|
|
|
*/
|
|
|
|
virtual bool shouldWorldUpdate();
|
|
|
|
|
2016-11-30 00:28:53 +01:00
|
|
|
GameWorld* getWorld() const;
|
2016-09-09 22:13:20 +02:00
|
|
|
GameWindow& getWindow();
|
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
bool hasExited() const {
|
|
|
|
return hasexited_;
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
private:
|
|
|
|
bool hasexited_ = false;
|
2016-10-18 23:00:53 +02:00
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
protected:
|
2016-10-18 23:00:53 +02:00
|
|
|
void done() {
|
|
|
|
hasexited_ = true;
|
|
|
|
}
|
2013-12-27 00:18:55 +01:00
|
|
|
};
|
|
|
|
|
2014-05-25 23:30:50 +02:00
|
|
|
#endif
|