Added ability to actually build different unit types, as well as icons to distinguish them

This commit is contained in:
2011-07-03 15:16:00 -04:00
parent 7744bad7c7
commit fc0c0f26fd
10 changed files with 75 additions and 36 deletions

View File

@ -11,6 +11,10 @@ Game::Game(stack<GameState*>* state_stack, SDL_Surface* display)
{
background = NULL;
font = NULL;
attacker_icon = NULL;
defender_icon = NULL;
producer_icon = NULL;
}
@ -32,21 +36,22 @@ Game::~Game()
bool Game::init()
{
background = DrawUtils::load("background.bmp");
if (background == NULL)
{
debug("Game::init(): error: Couldn't load background image");
return false;
}
font = TTF_OpenFont("LiberationSans-Regular.ttf", 12);
attacker_icon = DrawUtils::load("attacker_icon.bmp");
defender_icon = DrawUtils::load("defender_icon.bmp");
producer_icon = DrawUtils::load("producer_icon.bmp");
if (font == NULL)
if (background == NULL || font == NULL || attacker_icon == NULL ||
defender_icon == NULL || producer_icon == NULL)
{
debug("Game::init(): error: Couldn't load font");
debug("Game::init(): error: Couldn't load some resource(s)");
return false;
}
DrawUtils::transpare(attacker_icon);
DrawUtils::transpare(defender_icon);
DrawUtils::transpare(producer_icon);
int row1 = display->h - 95;
int row2 = display->h - 50;
int col1 = 155;
@ -102,13 +107,11 @@ void Game::render()
range_colour);
}
// Now paint each vertex, and any edges that it needs
// First draw the edges, so that they don't obscure any data
for (list<Vertex*>::iterator cursor = vertices.begin();
cursor != vertices.end(); cursor++)
{
Vertex* v = *cursor;
DrawUtils::draw_circle_filled(display, v->x, v->y, v->r,
v->colour);
for (list<Vertex*>::iterator subcursor = v->neighbors.begin();
subcursor != v->neighbors.end(); subcursor++)
@ -119,16 +122,6 @@ void Game::render()
}
}
// Add hit points on top of the nodes
for (list<Vertex*>::iterator cursor = vertices.begin();
cursor != vertices.end(); cursor++)
{
Vertex* v = *cursor;
DrawUtils::draw_text(display, itos(v->score), v->x, v->y, font,
0x00ff00, true, true);
}
// ring the selected vertex and write info about it
if (data.get_current_vertex() != NULL)
{
@ -137,6 +130,14 @@ void Game::render()
draw_stats(v);
}
// Draw each node
for (list<Vertex*>::iterator cursor = vertices.begin();
cursor != vertices.end(); cursor++)
{
Vertex* v = *cursor;
draw_node(v);
}
// draw the rest of the bottom menu
// horizontal line across the whole thing
@ -190,6 +191,29 @@ void Game::draw_button(MenuButton* button)
}
void Game::draw_node(Vertex* v)
{
DrawUtils::draw_circle_filled(display, v->x, v->y, v->r,
v->colour);
DrawUtils::draw_text(display, itos(v->score), v->x, v->y, font,
0x00ff00, true, true);
switch (dynamic_cast<GameVertex*>(v)->type)
{
case VERTEX_ATTACKER:
DrawUtils::draw(display, attacker_icon, v->x + 5, v-> y + 5);
break;
case VERTEX_DEFENDER:
DrawUtils::draw(display, defender_icon, v->x + 5, v-> y + 5);
break;
case VERTEX_PRODUCER:
DrawUtils::draw(display, producer_icon, v->x + 5, v-> y + 5);
break;
}
}
void Game::handle_button_press(ButtonAction action)
{
switch (action)
@ -225,7 +249,7 @@ void Game::draw_stats(Vertex* v)
DrawUtils::draw_text(display, "player:", x, y, font);
DrawUtils::draw_text(display, dynamic_cast<GameVertex*>(v)->player->get_name(), x + 50, y, font);
DrawUtils::draw_text(display, "str:", x, y + 14, font);
DrawUtils::draw_text(display, "atk:", x, y + 14, font);
DrawUtils::draw_text(display, itos(data.calculate_strength(v)),
x + 50, y + 14, font);