2011-06-22 20:12:22 +00:00
|
|
|
#include "gamecore.h"
|
2011-06-23 16:36:40 +00:00
|
|
|
#include "mathutils.h"
|
2011-06-24 13:48:59 +00:00
|
|
|
#include "debug.h"
|
2011-06-24 13:53:44 +00:00
|
|
|
#include <SDL.h>
|
2011-06-22 20:12:22 +00:00
|
|
|
|
2011-06-23 16:36:40 +00:00
|
|
|
int GameCore::NODE_RADIUS = 12;
|
2011-06-23 02:32:33 +00:00
|
|
|
|
2011-06-22 20:12:22 +00:00
|
|
|
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);
|
2011-06-24 13:40:13 +00:00
|
|
|
// iterate();
|
2011-06-24 16:02:53 +00:00
|
|
|
renderer.render(data);
|
2011-06-22 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GameCore::init()
|
|
|
|
{
|
|
|
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;
|
2011-06-24 13:53:44 +00:00
|
|
|
SDL_WM_SetCaption("TreeWars","TreeWars");
|
2011-06-24 13:40:13 +00:00
|
|
|
return renderer.init();
|
2011-06-22 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GameCore::cleanup()
|
|
|
|
{
|
2011-06-24 13:40:13 +00:00
|
|
|
renderer.cleanup();
|
2011-06-22 20:12:22 +00:00
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GameCore::on_exit()
|
|
|
|
{
|
|
|
|
is_running = false;
|
|
|
|
}
|
2011-06-22 21:57:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
void GameCore::on_lbutton_down(int x, int y)
|
|
|
|
{
|
2011-06-23 21:28:49 +00:00
|
|
|
data.do_vertex(x, y, NODE_RADIUS);
|
2011-06-23 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GameCore::on_rbutton_down(int mX, int mY)
|
|
|
|
{
|
2011-06-23 21:28:49 +00:00
|
|
|
data.clear_current_vertex();
|
2011-06-22 21:57:44 +00:00
|
|
|
}
|
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;
|
2011-06-24 16:02:53 +00:00
|
|
|
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
|
|
|
}
|