From c49fdb81696b38a827cb277b353809463cfb62aa Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 1 Jul 2011 18:04:15 -0400 Subject: [PATCH] Added display showing information about selected vertex --- drawutils.cpp | 6 +++--- drawutils.h | 2 +- game.cpp | 30 +++++++++++++++++++++++++++--- game.h | 1 + gamedata.cpp | 11 ++++++----- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/drawutils.cpp b/drawutils.cpp index 8c267a8..59fe2f5 100644 --- a/drawutils.cpp +++ b/drawutils.cpp @@ -152,7 +152,7 @@ bool DrawUtils::transpare(SDL_Surface* surface, int r, int g, int b) // Modified from // http://www.parallelrealities.co.uk/tutorials/basic/tutorial7.php void DrawUtils::draw_text(SDL_Surface* display, string text, int x, int y, - TTF_Font *font, bool center_x, bool center_y) + TTF_Font *font) { SDL_Rect dest; SDL_Surface *surface; @@ -174,8 +174,8 @@ void DrawUtils::draw_text(SDL_Surface* display, string text, int x, int y, } /* Blit the surface */ - dest.x = (center_x ? (display->w - surface->w) / 2 : x); - dest.y = (center_y ? (display->h - surface->h) / 2 : y); + dest.x = x; + dest.y = y; dest.w = surface->w; dest.h = surface->h; diff --git a/drawutils.h b/drawutils.h index b13da38..5f4ce6d 100644 --- a/drawutils.h +++ b/drawutils.h @@ -25,7 +25,7 @@ class DrawUtils static void draw_circle_filled(SDL_Surface* dest, Sint16 x, Sint16 y, Uint16 r, Uint32 colour); static void draw_text(SDL_Surface* display, string text, int x, int y, - TTF_Font *font, bool center_x, bool center_y); + TTF_Font *font); // transpare (v) - to make transparent // this function makes a particular color key on a surface transparent diff --git a/game.cpp b/game.cpp index 485247b..3afcf5a 100644 --- a/game.cpp +++ b/game.cpp @@ -85,9 +85,9 @@ void Game::render() v->colour); DrawUtils::draw_text(display, "str " + itos(data.calculate_strength(v)), - v->x, v->y, font, 0, 0); + v->x, v->y, font); DrawUtils::draw_text(display, "hp " + itos(v->score), - v->x, v->y + 13, font, 0, 0); + v->x, v->y + 13, font); for (list::iterator subcursor = v->neighbors.begin(); @@ -99,17 +99,40 @@ void Game::render() } } - // Finally, ring the selected vertex + // Finally, ring the selected vertex and write info about it if (data.get_current_vertex() != NULL) { Vertex* v = data.get_current_vertex(); DrawUtils::draw_circle(display, v->x, v->y, v->r + 5, 0x000000); + draw_stats(v); } SDL_Flip(display); } +void Game::draw_stats(Vertex* v) +{ + int num_lines = 4; + int x = 20; + int y = display->h - (num_lines * 14) - 20; + + DrawUtils::draw_text(display, "player:", x, y, font); + + DrawUtils::draw_text(display, "str:", x, y + 14, font); + DrawUtils::draw_text(display, itos(data.calculate_strength(v)), + x + 50, y + 14, font); + + DrawUtils::draw_text(display, "def:", x, y + 28, font); + DrawUtils::draw_text(display, itos(data.calculate_strength(v)), + x + 50, y + 28, font); + + DrawUtils::draw_text(display, "hp:", x, y + 42, font); + DrawUtils::draw_text(display, itos(v->score), x + 50, y + 42, font); + +} + + void Game::on_lbutton_down(int x, int y) { if (!data.endgame()) data.handle_click(x, y); @@ -128,4 +151,5 @@ void Game::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode) if (sym == SDLK_a) data.set_mode(MODE_ATTACK); if (sym == SDLK_m) data.set_mode(MODE_MOVE); if (sym == SDLK_b) data.set_mode(MODE_BUILD); + if (sym == SDLK_s) data.set_mode(MODE_SELECT); } diff --git a/game.h b/game.h index 8b749d1..fd5e3eb 100644 --- a/game.h +++ b/game.h @@ -33,6 +33,7 @@ class Game : public GameState void on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode); private: + void draw_stats(Vertex* v); // data GameData data; diff --git a/gamedata.cpp b/gamedata.cpp index 7ed9109..0da795c 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -107,13 +107,14 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour) // this is the special case for adding the first vertex for each player if (!turn->has_played()) { - Graph::add_vertex(x, y, z, r, colour, 10); + if (Graph::add_vertex(x, y, z, r, colour, 10)) + { #ifdef DEBUG - fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", - calculate_strength(*(vertices.rbegin()))); + fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", calculate_strength(*(vertices.rbegin()))); #endif - toggle_turn(); - return true; + toggle_turn(); + return true; + } } return false; }