Support different colours for different vertices

This commit is contained in:
2011-06-23 15:10:40 -04:00
parent 9d36120f6d
commit b967542157
4 changed files with 43 additions and 16 deletions

View File

@ -5,12 +5,17 @@
int GameCore::MAX_MOVE_DISTANCE = 100;
int GameCore::NODE_RADIUS = 12;
int GameCore::PLAYER1_COLOUR = 0x4a483f;
int GameCore::PLAYER2_COLOUR = 0x090c7a;
GameCore::GameCore()
{
display = NULL;
background = NULL;
is_running = true;
who = PLAYER1;
}
int GameCore::execute()
@ -83,7 +88,7 @@ void GameCore::render()
{
Vertex v = *(*cursor);
DrawUtils::draw_circle_filled(display, v.x, v.y, v.r,
0x000000);
v.colour);
}
for (list<Edge>::iterator cursor = edges.begin();
@ -91,7 +96,7 @@ void GameCore::render()
{
Edge e = *cursor;
DrawUtils::draw_line(display, e.a->x, e.a->y, e.b->x, e.b->y, 2,
0x000000);
e.a->colour);
}
SDL_Flip(display);
@ -125,9 +130,21 @@ void GameCore::on_lbutton_down(int x, int y)
(MathUtils::distance(cv->x, cv->y, x, y)
> MAX_MOVE_DISTANCE))
{
graph.select_vertex(x, y);
Vertex* v = graph.vertex_at(x, y);
if (v->colour == PLAYER1_COLOUR && turn == PLAYER1 ||
v->colour == PLAYER2_COLOUR && turn == PLAYER2)
graph.select_vertex(x, y);
return;
}
graph.do_vertex(x, y, NODE_RADIUS);
graph.do_vertex(x, y, NODE_RADIUS, PLAYER1_COLOUR);
if (turn == PLAYER1) turn = PLAYER2;
else turn = PLAYER_1;
}
void GameCore::on_rbutton_down(int mX, int mY)
{
graph.clear_current_vertex();
}