Added display showing information about selected vertex
This commit is contained in:
parent
d15e6590ec
commit
c49fdb8169
|
@ -152,7 +152,7 @@ bool DrawUtils::transpare(SDL_Surface* surface, int r, int g, int b)
|
||||||
// Modified from
|
// Modified from
|
||||||
// http://www.parallelrealities.co.uk/tutorials/basic/tutorial7.php
|
// http://www.parallelrealities.co.uk/tutorials/basic/tutorial7.php
|
||||||
void DrawUtils::draw_text(SDL_Surface* display, string text, int x, int y,
|
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_Rect dest;
|
||||||
SDL_Surface *surface;
|
SDL_Surface *surface;
|
||||||
|
@ -174,8 +174,8 @@ void DrawUtils::draw_text(SDL_Surface* display, string text, int x, int y,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Blit the surface */
|
/* Blit the surface */
|
||||||
dest.x = (center_x ? (display->w - surface->w) / 2 : x);
|
dest.x = x;
|
||||||
dest.y = (center_y ? (display->h - surface->h) / 2 : y);
|
dest.y = y;
|
||||||
dest.w = surface->w;
|
dest.w = surface->w;
|
||||||
dest.h = surface->h;
|
dest.h = surface->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_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,
|
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
|
// transpare (v) - to make transparent
|
||||||
// this function makes a particular color key on a surface transparent
|
// this function makes a particular color key on a surface transparent
|
||||||
|
|
30
game.cpp
30
game.cpp
|
@ -85,9 +85,9 @@ void Game::render()
|
||||||
v->colour);
|
v->colour);
|
||||||
DrawUtils::draw_text(display,
|
DrawUtils::draw_text(display,
|
||||||
"str " + itos(data.calculate_strength(v)),
|
"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),
|
DrawUtils::draw_text(display, "hp " + itos(v->score),
|
||||||
v->x, v->y + 13, font, 0, 0);
|
v->x, v->y + 13, font);
|
||||||
|
|
||||||
|
|
||||||
for (list<Vertex*>::iterator subcursor = v->neighbors.begin();
|
for (list<Vertex*>::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)
|
if (data.get_current_vertex() != NULL)
|
||||||
{
|
{
|
||||||
Vertex* v = data.get_current_vertex();
|
Vertex* v = data.get_current_vertex();
|
||||||
DrawUtils::draw_circle(display, v->x, v->y, v->r + 5, 0x000000);
|
DrawUtils::draw_circle(display, v->x, v->y, v->r + 5, 0x000000);
|
||||||
|
draw_stats(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Flip(display);
|
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)
|
void Game::on_lbutton_down(int x, int y)
|
||||||
{
|
{
|
||||||
if (!data.endgame()) data.handle_click(x, 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_a) data.set_mode(MODE_ATTACK);
|
||||||
if (sym == SDLK_m) data.set_mode(MODE_MOVE);
|
if (sym == SDLK_m) data.set_mode(MODE_MOVE);
|
||||||
if (sym == SDLK_b) data.set_mode(MODE_BUILD);
|
if (sym == SDLK_b) data.set_mode(MODE_BUILD);
|
||||||
|
if (sym == SDLK_s) data.set_mode(MODE_SELECT);
|
||||||
}
|
}
|
||||||
|
|
1
game.h
1
game.h
|
@ -33,6 +33,7 @@ class Game : public GameState
|
||||||
void on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode);
|
void on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void draw_stats(Vertex* v);
|
||||||
|
|
||||||
// data
|
// data
|
||||||
GameData data;
|
GameData data;
|
||||||
|
|
|
@ -107,14 +107,15 @@ 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
|
// this is the special case for adding the first vertex for each player
|
||||||
if (!turn->has_played())
|
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
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n",
|
fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", calculate_strength(*(vertices.rbegin())));
|
||||||
calculate_strength(*(vertices.rbegin())));
|
|
||||||
#endif
|
#endif
|
||||||
toggle_turn();
|
toggle_turn();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user