-
Notifications
You must be signed in to change notification settings - Fork 2
/
GameInterface.cpp
112 lines (86 loc) · 3.07 KB
/
GameInterface.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
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
107
108
109
110
111
112
//
// Created by Sondre on 19.10.2017.
//
#include "GameInterface.h"
#include <iostream>
#include "gameConfig.h"
#include "equipment.h"
// Declare and load a font
sf::Font font;
sf::Text* moneyLabel_ptr;
sf::Text* scoreLabel_ptr;
Object* healthBar_ptr;
Object* energyBar_ptr;
GameInterface::GameInterface(){
ammo1.loadFromFile("Assets/player.png");
moneyLabel_ptr = &moneyLabel;
scoreLabel_ptr = &scoreLabel;
moneyLabel = sf::Text();
scoreLabel = sf::Text();
sf::Texture* hud_main_ptr = &hud_main;
sf::Texture* hp_bar_ptr = &hp_bar;
sf::Texture* energy_bar_ptr = &energy_bar;
sf::Texture* frames_ptr = &frames;
priWeapon_tx_ptr = PlayerEquipment[0]->ObjectTexture();
secWeapon_1_tx_ptr = PlayerEquipment[1]->ObjectTexture();
secWeapon_2_tx_ptr = PlayerEquipment[2]->ObjectTexture();
hud_main.loadFromFile("Assets/HUD-Main.png");
hp_bar.loadFromFile("Assets/health-bar.png");
energy_bar.loadFromFile("Assets/energy-bar.png");
frames.loadFromFile("Assets/bar-frames.png");
//781
moneyLabel.setPosition(20,8);
scoreLabel.setPosition(940, 8);
primary_weapon_ptr = new Object(1108,713, 1, 1, priWeapon_tx_ptr, 68, 68); //68x68
secondary_weapon_1_ptr = new Object(1048,738, 1, 1, secWeapon_1_tx_ptr, 42, 42);
secondary_weapon_2_ptr = new Object(987,738, 1, 1, secWeapon_2_tx_ptr, 42, 42);
Object* e1 = new Object(0,0, 1, 1, hud_main_ptr, 1200, 800);
healthBar_ptr = new Object(10,731, 1, 1, hp_bar_ptr, 191, 16);
energyBar_ptr = new Object(10,777, 1, 1, energy_bar_ptr, 191, 16);
Object* e4 = new Object(8,729, 1, 1, frames_ptr, 195, 66);
font.loadFromFile("Fonts/neuropol.ttf");
moneyLabel.setFont(font);
scoreLabel.setFont(font);
UI_Objects.push_back(e1);
UI_Objects.push_back(healthBar_ptr);
UI_Objects.push_back(energyBar_ptr);
UI_Objects.push_back(e4);
UI_Objects.push_back(primary_weapon_ptr);
UI_Objects.push_back(secondary_weapon_1_ptr);
UI_Objects.push_back(secondary_weapon_2_ptr);
texts.push_back(moneyLabel_ptr);
texts.push_back(scoreLabel_ptr);
}
std::list<Object*> GameInterface::GetObjects(){
return UI_Objects;
}
std::list<sf::Text*> GameInterface::GetLabels(){
return texts;
}
void GameInterface::update(){
priWeapon_tx_ptr = PlayerEquipment[0]->ObjectTexture();
secWeapon_1_tx_ptr = PlayerEquipment[1]->ObjectTexture();
secWeapon_2_tx_ptr = PlayerEquipment[2]->ObjectTexture();
}
void GameInterface::setHealthPercentage(float percentage){
healthBar_ptr->rect.setScale(percentage/100, 1.0);
}
void GameInterface::setMoney(int money){
moneyLabel_ptr->setString(std::to_string(money) + "$");
}
void GameInterface::setScore(int score){
scoreLabel_ptr->setString("Score: " + std::to_string(score));
}
void GameInterface::setEnergyPercentage(float percentage) {
energyBar_ptr->rect.setScale(percentage/100, 1.0);
}
void setWeapon(int index, Object* newWeapon){
if(index == 0)
{
//primary_weapon_ptr = newWeapon;
}
else if(index > 0)
{
//secondary_weapons_ptr[index-1] = newWeapon;
}
}