Added some basic differences between vertex types

This commit is contained in:
Anna Rose 2011-07-03 15:48:06 -04:00
parent fc0c0f26fd
commit 8ad4ec0672
3 changed files with 88 additions and 15 deletions

View File

@ -148,7 +148,9 @@ void Game::render()
DrawUtils::draw_line(display, 150, display->h - 100, 150, display->h, 2, DrawUtils::draw_line(display, 150, display->h - 100, 150, display->h, 2,
0x000000); 0x000000);
if (data.get_current_vertex() != NULL) if (data.get_current_vertex() != NULL &&
dynamic_cast<GameVertex*>(data.get_current_vertex())->player ==
data.get_turn())
{ {
for (list<MenuButton*>::iterator cursor = buttons.begin(); for (list<MenuButton*>::iterator cursor = buttons.begin();
cursor != buttons.end(); cursor++) cursor != buttons.end(); cursor++)
@ -242,24 +244,61 @@ void Game::handle_button_press(ButtonAction action)
void Game::draw_stats(Vertex* v) void Game::draw_stats(Vertex* v)
{ {
int num_lines = 4; int line_num = 0;
int x = 20; int line_height = 14;
int y = display->h - 76; int x = 10;
int y = display->h - 95;
int adj_y = y;
DrawUtils::draw_text(display, "player:", x, y, font); DrawUtils::draw_text(display, "player:", x, adj_y, font);
DrawUtils::draw_text(display, dynamic_cast<GameVertex*>(v)->player->get_name(), x + 50, y, font); DrawUtils::draw_text(display,
dynamic_cast<GameVertex*>(v)->player->get_name(),
x + 50, adj_y, font);
DrawUtils::draw_text(display, "atk:", x, y + 14, font); line_num++;
DrawUtils::draw_text(display, itos(data.calculate_strength(v)), adj_y = y + line_num * line_height;
x + 50, y + 14, font); DrawUtils::draw_text(display, "type:", x, adj_y, font);
VertexType vtype = dynamic_cast<GameVertex*>(v)->type;
string type;
switch(vtype)
{
case VERTEX_ATTACKER:
type = "attacker";
break;
case VERTEX_DEFENDER:
type = "defender";
break;
case VERTEX_PRODUCER:
type = "producer";
break;
}
DrawUtils::draw_text(display, type, x + 50, adj_y, font);
DrawUtils::draw_text(display, "armor:", x, y + 28, font); line_num++;
adj_y = y + line_num * line_height;
DrawUtils::draw_text(display, "atk:", x, adj_y, font);
DrawUtils::draw_text(display, itos(data.calculate_attack(v)),
x + 50, adj_y, font);
line_num++;
adj_y = y + line_num * line_height;
DrawUtils::draw_text(display, "armor:", x, adj_y, font);
DrawUtils::draw_text(display, itos(data.calculate_armor(v)), DrawUtils::draw_text(display, itos(data.calculate_armor(v)),
x + 50, y + 28, font); x + 50, adj_y, font);
DrawUtils::draw_text(display, "hp:", x, y + 42, font); line_num++;
DrawUtils::draw_text(display, itos(v->score), x + 50, y + 42, font); adj_y = y + line_num * line_height;
DrawUtils::draw_text(display, "hp:", x, adj_y, font);
DrawUtils::draw_text(display, itos(v->score), x + 50, adj_y, font);
if (vtype == VERTEX_PRODUCER)
{
line_num++;
adj_y = y + line_num * line_height;
DrawUtils::draw_text(display, "energy:", x, adj_y, font);
DrawUtils::draw_text(display, "25", x + 50, adj_y, font);
}
} }

View File

@ -191,12 +191,45 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
float GameData::calculate_armor(Vertex* node) float GameData::calculate_armor(Vertex* node)
{ {
float str = calculate_strength(node); float str = calculate_strength(node);
float armor = str / 10; float armor;
switch(dynamic_cast<GameVertex*>(node)->type)
{
case VERTEX_ATTACKER:
armor = str / 10;
break;
case VERTEX_DEFENDER:
armor = str / 5;
break;
case VERTEX_PRODUCER:
armor = str / 40;
break;
}
if (armor < 1) armor = 1; if (armor < 1) armor = 1;
return armor; return armor;
} }
float GameData::calculate_attack(Vertex* node)
{
float attack = calculate_strength(node);
switch (dynamic_cast<GameVertex*>(node)->type)
{
case VERTEX_ATTACKER:
attack *= 1.5;
break;
case VERTEX_DEFENDER:
attack /= 0.75;
break;
case VERTEX_PRODUCER:
attack = 0;
break;
}
}
float GameData::calculate_strength(Vertex* node) float GameData::calculate_strength(Vertex* node)
{ {
list<Vertex*> visited; list<Vertex*> visited;
@ -297,7 +330,7 @@ int GameData::get_range(Vertex* node)
void GameData::attack_vertex(Vertex* target) void GameData::attack_vertex(Vertex* target)
{ {
float atk = calculate_strength(current); float atk = calculate_attack(current);
float armor = calculate_armor(target); float armor = calculate_armor(target);
int damage = (int)(atk / armor); int damage = (int)(atk / armor);
target->score -= damage; target->score -= damage;

View File

@ -54,6 +54,7 @@ class GameData : public Graph
// check for (and set, if needed) winner // check for (and set, if needed) winner
bool endgame(); bool endgame();
Player* get_turn() const { return turn; } Player* get_turn() const { return turn; }
float calculate_attack(Vertex* node);
float calculate_strength(Vertex* node); float calculate_strength(Vertex* node);
float calculate_armor(Vertex* node); float calculate_armor(Vertex* node);