First implementation of game logic and control

This commit is contained in:
2011-06-22 17:57:44 -04:00
parent 2aadb9ad7e
commit fc08adcade
5 changed files with 64 additions and 9 deletions

View File

@ -8,6 +8,8 @@
GameCore::GameCore()
{
display = NULL;
background = NULL;
node = NULL;
is_running = true;
}
@ -44,13 +46,41 @@ bool GameCore::init()
return false;
}
background = DrawUtils::load("background.bmp");
node = DrawUtils::load("node.bmp");
if (background == NULL || node == NULL)
{
#ifdef DEBUG
std::cerr << "GameCore::init(): error: Couldn't load an image file\n";
#endif
return false;
}
return true;
}
void GameCore::render()
{
list<Vertex> vertices = graph.get_vertices();
list<Edge> edges = graph.get_edges();
for (list<Vertex>::iterator cursor = vertices.begin();
cursor != vertices.end(); cursor++)
{
Vertex v = *cursor;
DrawUtils::draw(display, node, v.x_min, v.y_min);
}
for (list<Edge>::iterator cursor = edges.begin();
cursor != edges.end(); cursor++)
{
Edge e = *cursor;
DrawUtils::draw_line(e.a.x, e.a.y, e.b.x, e.b.y, 2, 0xffffff, display);
}
SDL_Flip(display);
}
@ -62,6 +92,8 @@ void GameCore::iterate()
void GameCore::cleanup()
{
SDL_FreeSurface(background);
SDL_FreeSurface(node);
SDL_FreeSurface(display);
SDL_Quit();
}
@ -71,3 +103,9 @@ void GameCore::on_exit()
{
is_running = false;
}
void GameCore::on_lbutton_down(int x, int y)
{
graph.add_vertex(x, y, 25);
}