Implemented node movement

This commit is contained in:
Anna Rose 2011-07-03 10:38:56 -04:00
parent 6085267cc4
commit 7744bad7c7

View File

@ -82,20 +82,33 @@ void GameData::handle_click(int x, int y)
int colour; int colour;
colour = turn->get_colour(); colour = turn->get_colour();
if (mode == MODE_SELECT) Vertex* v = vertex_at(x, y, 0);
// fixme - energy expenditure should happen in each of these cases except
// MODE_SELECT
switch (mode)
{ {
case MODE_SELECT:
// select_vertex handles making sure a point exists at (x,y) // select_vertex handles making sure a point exists at (x,y)
select_vertex(x, y); select_vertex(x, y);
} break;
else if (mode == MODE_BUILD) case MODE_BUILD:
{
add_vertex(x, y, 0, r, colour); add_vertex(x, y, 0, r, colour);
} break;
else if (mode == MODE_ATTACK) case MODE_ATTACK:
{
Vertex* v = vertex_at(x, y, 0);
if (v == NULL || dynamic_cast<GameVertex*>(v)->player == turn) return; if (v == NULL || dynamic_cast<GameVertex*>(v)->player == turn) return;
if (v->colour != colour) attack_vertex(v); if (v->colour != colour) attack_vertex(v);
break;
case MODE_MOVE:
if (current == NULL) return;
if (MathUtils::distance(current->x, current->y, current->z, x, y, 0)
<= get_range())
{
current->x = x;
current->y = y;
toggle_turn();
}
break;
} }
} }