Added ability to actually build different unit types, as well as icons to distinguish them
This commit is contained in:
30
gamedata.cpp
30
gamedata.cpp
@ -31,7 +31,7 @@ GameData::GameData()
|
||||
player1 = Player("player 1", PLAYER1_COLOUR);
|
||||
player2 = Player("player 2", PLAYER2_COLOUR);
|
||||
turn = &player1;
|
||||
build_type = VERTEX_NONE;
|
||||
build_type = VERTEX_PRODUCER; // first vertex is always a producer
|
||||
}
|
||||
|
||||
GameData::~GameData() { }
|
||||
@ -67,8 +67,16 @@ void GameData::toggle_turn()
|
||||
if (turn == &player1) turn = &player2;
|
||||
else if (turn == &player2) turn = &player1;
|
||||
|
||||
if (!turn->has_played()) mode = MODE_BUILD;
|
||||
else mode = MODE_SELECT;
|
||||
if (!turn->has_played())
|
||||
{
|
||||
mode = MODE_BUILD;
|
||||
build_type = VERTEX_PRODUCER;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = MODE_SELECT;
|
||||
build_type = VERTEX_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
current = NULL;
|
||||
@ -125,8 +133,9 @@ bool GameData::select_vertex(int x, int y)
|
||||
|
||||
bool GameData::add_vertex(int x, int y, int z, int r, int colour)
|
||||
{
|
||||
GameVertex* v = new GameVertex(x, y, z, r, colour, 10, VERTEX_ATTACKER,
|
||||
turn);
|
||||
if (build_type == VERTEX_NONE) return false;
|
||||
|
||||
GameVertex* v = new GameVertex(x, y, z, r, colour, 10, build_type, turn);
|
||||
|
||||
if (current == NULL)
|
||||
{
|
||||
@ -182,7 +191,9 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
|
||||
float GameData::calculate_armor(Vertex* node)
|
||||
{
|
||||
float str = calculate_strength(node);
|
||||
return str / 10;
|
||||
float armor = str / 10;
|
||||
if (armor < 1) armor = 1;
|
||||
return armor;
|
||||
}
|
||||
|
||||
|
||||
@ -287,16 +298,13 @@ int GameData::get_range(Vertex* node)
|
||||
void GameData::attack_vertex(Vertex* target)
|
||||
{
|
||||
float atk = calculate_strength(current);
|
||||
float armor = calculate_armor(current);
|
||||
|
||||
float armor = calculate_armor(target);
|
||||
int damage = (int)(atk / armor);
|
||||
|
||||
target->score -= damage;
|
||||
|
||||
if (target->score <= 0) remove_vertex(target);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "debug: GameData::attack_vertex(): atk=%.2f, armor=%.2f, armor=%.2f, damage=%d\n", atk, armor, damage);
|
||||
fprintf(stderr, "debug: GameData::attack_vertex(): atk=%.2f, armor=%.2f, damage=%d\n", atk, armor, damage);
|
||||
#endif
|
||||
|
||||
toggle_turn();
|
||||
|
Reference in New Issue
Block a user