-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhud.cpp
38 lines (32 loc) · 1.16 KB
/
hud.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <allegro5/allegro_primitives.h>
#include "hud.h"
#include "resources.h"
#include "coords.h"
#include "game.h"
#define COLOR_HUNGERBORDER al_map_rgb(200, 220, 10)
#define COLOR_HUNGERBAR al_map_rgb(240, 30, 100)
const PixelCoords HUNGERBAR_POSITION = { 15, 15 };
const int HUNGERBAR_LENGTH = 100;
const int HUNGERBAR_HEIGHT = 14;
void Hud::draw()
{
al_draw_filled_rectangle(HUNGERBAR_POSITION.x, HUNGERBAR_POSITION.y,
HUNGERBAR_POSITION.x+HUNGERBAR_LENGTH, HUNGERBAR_POSITION.x+HUNGERBAR_HEIGHT,
COLOR_HUNGERBORDER);
float hunger_part = (HUNGERBAR_LENGTH-4) * (1.0 - (float)hunger / maxHunger);
if (hunger_part > 0) {
al_draw_filled_rectangle(HUNGERBAR_POSITION.x+2, HUNGERBAR_POSITION.y+2,
HUNGERBAR_POSITION.x+hunger_part, HUNGERBAR_POSITION.x+HUNGERBAR_HEIGHT-2,
COLOR_HUNGERBAR);
}
al_draw_textf(Resources::instance()->fontNormal, al_map_rgb(255, 255, 255),
Game::WIDTH - 10, 10, ALLEGRO_ALIGN_RIGHT, "Score: %d", Game::globalGame->score);
}
void Hud::setMaxHunger(int value)
{
maxHunger = value;
}
void Hud::setHunger(int value)
{
hunger = value;
}