Implemented font framework, print info about each vertex
This commit is contained in:
19
game.cpp
19
game.cpp
@ -2,6 +2,7 @@
|
||||
#include "mathutils.h"
|
||||
#include "drawutils.h"
|
||||
#include "debug.h"
|
||||
#include "itos.h"
|
||||
#include <SDL.h>
|
||||
|
||||
int Game::NODE_RADIUS = 10;
|
||||
@ -11,6 +12,7 @@ Game::Game(stack<GameState*>* state_stack, SDL_Surface* display)
|
||||
: GameState(state_stack, display)
|
||||
{
|
||||
background = NULL;
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +20,8 @@ Game::~Game()
|
||||
{
|
||||
if (background != NULL)
|
||||
SDL_FreeSurface(background);
|
||||
if (font != NULL)
|
||||
TTF_CloseFont(font);
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +35,14 @@ bool Game::init()
|
||||
return false;
|
||||
}
|
||||
|
||||
font = TTF_OpenFont("LiberationSans-Regular.ttf", 12);
|
||||
|
||||
if (font == NULL)
|
||||
{
|
||||
debug("Game::init(): error: Couldn't load font");
|
||||
return false;
|
||||
}
|
||||
|
||||
return GameState::init();
|
||||
}
|
||||
|
||||
@ -70,6 +82,13 @@ void Game::render()
|
||||
Vertex* v = *cursor;
|
||||
DrawUtils::draw_circle_filled(display, v->x, v->y, v->r,
|
||||
v->colour);
|
||||
DrawUtils::draw_text(display,
|
||||
"str " + itos(data.calculate_strength(v)),
|
||||
v->x, v->y, font, 0, 0);
|
||||
DrawUtils::draw_text(display, "hp " + itos(v->score),
|
||||
v->x, v->y + 13, font, 0, 0);
|
||||
|
||||
|
||||
for (list<Vertex*>::iterator subcursor = v->neighbors.begin();
|
||||
subcursor != v->neighbors.end(); subcursor++)
|
||||
{
|
||||
|
Reference in New Issue
Block a user