This repository was archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.cpp
More file actions
106 lines (88 loc) · 2.07 KB
/
Copy pathGUI.cpp
File metadata and controls
106 lines (88 loc) · 2.07 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* GUI.cpp
*
* Created on: Dec 16, 2015
* Author: andres
*/
#include "GUI.h"
GUI::GUI(RenderWindow* window, GameWorld* world) {
this->window = window;
this->world = world;
this->player = player;
this->font.loadFromFile("assets/slkscr.ttf");
this->commando.loadFromFile("assets/commando.ttf");
this->screenW = window->getView().getSize().x;
this->screenH = window->getView().getSize().y;
playerPoints.setFont(font);
playerPoints.setCharacterSize(24);
playerPoints.setColor(Color::White);
playerPoints.setPosition(40, 80);
hp.setFont(font);
hp.setCharacterSize(24);
hp.setColor(Color::White);
hp.setPosition(40, 110);
highscore.setFont(commando);
highscore.setCharacterSize(24);
highscore.setColor(Color::White);
highscore.setString("New Highscore");
highscore.setPosition(screenW/2.0f - 180, screenH/2.0f - 60);
gameover.setFont(commando);
gameover.setCharacterSize(82);
gameover.setColor(Color::White);
gameover.setString("Game Over");
gameover.setPosition(screenW/2.0f - 180, screenH/2.0f - 60);
}
GUI::~GUI() {
}
void GUI::draw()
{
for(list<Entity*>::iterator i = world->entities->begin(); i != world->entities->end(); i++)
{
Entity* entity = *i;
if(entity->getType() == "Player")
{
player = (Player*)entity;
break;
}
}
if(!world->gameover)
{
int points = player->points;
ostringstream pointsString;
pointsString << "Points: " << points;
int hp_value = player->hp;
ostringstream hpString;
ostringstream hpBars;
for(int i = 0; i < hp_value; i++)
hpBars << "|";
hpString << "HP: " << hpBars.str();
playerPoints.setString(pointsString.str());
hp.setString(hpString.str());
window->draw(playerPoints);
window->draw(hp);
}
else
{
window->draw(gameover);
readScores();
}
}
void GUI::readScores()
{
/*
ifstream in("scores.orb");
in.seekg(0, ios::end);
int size = in.tellg()/4;
in.seekg(0);
for(int i = 0; i < size; i++)
{
in.seekg(i*4);
int* points;
in.read((char*)points, 4);
scores.push_back(*points);
}
in.close();
for(int i = 0; i < scores.size(); i++)
cout << scores[i] << endl;
*/
}