Refactored code heavily to be able to use a state stack - main function now does the basic init, looping, and shutdown, and each state is a pointer to an object that has its own event handling, rendering, etc
This commit is contained in:
52
game.cpp
Normal file
52
game.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "game.h"
|
||||
#include "mathutils.h"
|
||||
#include "debug.h"
|
||||
#include <SDL.h>
|
||||
|
||||
int Game::NODE_RADIUS = 12;
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
renderer.cleanup();
|
||||
}
|
||||
|
||||
|
||||
void Game::execute(stack<GameState*> &state_stack) throw(StateExit)
|
||||
{
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
handle_event(&event);
|
||||
renderer.render(data);
|
||||
}
|
||||
|
||||
|
||||
bool Game::init()
|
||||
{
|
||||
return renderer.init();
|
||||
}
|
||||
|
||||
|
||||
void Game::on_exit()
|
||||
{
|
||||
throw StateExit();
|
||||
}
|
||||
|
||||
|
||||
void Game::on_lbutton_down(int x, int y)
|
||||
{
|
||||
data.do_vertex(x, y, NODE_RADIUS);
|
||||
}
|
||||
|
||||
|
||||
void Game::on_rbutton_down(int mX, int mY)
|
||||
{
|
||||
data.clear_current_vertex();
|
||||
}
|
||||
|
||||
|
||||
void Game::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode)
|
||||
{
|
||||
if (sym == SDLK_q && mod & KMOD_CTRL) throw StateExit();
|
||||
if (sym == SDLK_a) data.set_mode(MODE_ATTACK);
|
||||
if (sym == SDLK_m) data.set_mode(MODE_MOVE);
|
||||
}
|
Reference in New Issue
Block a user