treewars/gamecore.cpp

72 lines
1.1 KiB
C++
Raw Normal View History

#include "gamecore.h"
#include "mathutils.h"
2011-06-24 13:48:59 +00:00
#include "debug.h"
#include <SDL.h>
int GameCore::NODE_RADIUS = 12;
GameCore::GameCore()
{
is_running = true;
}
int GameCore::execute()
{
if (!init()) return 1;
SDL_Event event;
while (is_running)
{
while(SDL_PollEvent(&event))
handle_event(&event);
// iterate();
renderer.render(data);
}
cleanup();
return 0;
}
bool GameCore::init()
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;
SDL_WM_SetCaption("TreeWars","TreeWars");
return renderer.init();
}
void GameCore::cleanup()
{
renderer.cleanup();
SDL_Quit();
}
void GameCore::on_exit()
{
is_running = false;
}
void GameCore::on_lbutton_down(int x, int y)
{
data.do_vertex(x, y, NODE_RADIUS);
}
void GameCore::on_rbutton_down(int mX, int mY)
{
data.clear_current_vertex();
}
2011-06-24 13:48:59 +00:00
void GameCore::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode)
{
if (sym == SDLK_q && mod & KMOD_CTRL) is_running = false;
if (sym == SDLK_a) data.set_mode(MODE_ATTACK);
if (sym == SDLK_m) data.set_mode(MODE_MOVE);
2011-06-24 13:48:59 +00:00
}