-
Notifications
You must be signed in to change notification settings - Fork 0
/
pet_stats.cpp
205 lines (174 loc) · 6.31 KB
/
pet_stats.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "pet_stats.h"
#include <algorithm> // for std::max and std::min
#include <iostream>
PetStats::PetStats()
: health_level(25), // Set initial health level to 25
sleep_level(25), // Set initial sleep level to 25
hunger_level(25), // Set initial hunger level to 25
iq_level(50), // Set initial IQ level to 50
total_money(1000) {
stat_timer.restart();
}
void PetStats::updateStats(sf::RenderWindow& window, sf::Font font) {
// Update stats every 30 seconds
if (stat_timer.getElapsedTime().asSeconds() >= 30) {
// Update health level, but not if it's already 0
if (health_level > 0) {
health_level = std::max(0, health_level - 10);
}
// Update sleep level, but not if it's already 0
if (sleep_level > 0) {
sleep_level = std::max(0, sleep_level - 10);
}
// Update hunger level, but not if it's already 0
if (hunger_level > 0) {
hunger_level = std::max(0, hunger_level - 10);
}
// Update IQ level, but not if it's already 0
if (iq_level > 0) {
iq_level = std::max(0, iq_level - 5);
}
stat_timer.restart();
}
}
void PetStats::renderStats(sf::RenderWindow& window, sf::Font& font) {
// Health bar
sf::RectangleShape health_bar(sf::Vector2f(250 * health_level / 100, 30));
health_bar.setFillColor(sf::Color::Black);
health_bar.setPosition(20, 50);
window.draw(health_bar);
sf::Text health_text;
health_text.setFont(font);
health_text.setCharacterSize(44);
health_text.setFillColor(sf::Color::Black);
health_text.setPosition(50, 2);
health_text.setString("Health Bar: ");
window.draw(health_text);
// Sleep bar
sf::RectangleShape sleep_bar(sf::Vector2f(250 * sleep_level / 100, 30));
sleep_bar.setFillColor(sf::Color::Black);
sleep_bar.setPosition(350, 50);
window.draw(sleep_bar);
sf::Text sleep_bar_text;
sleep_bar_text.setFont(font);
sleep_bar_text.setCharacterSize(44);
sleep_bar_text.setFillColor(sf::Color::Black);
sleep_bar_text.setPosition(350, 2);
sleep_bar_text.setString("Sleep Bar: ");
window.draw(sleep_bar_text);
// Hunger bar
sf::RectangleShape hunger_bar(sf::Vector2f(250 * hunger_level / 100, 30));
hunger_bar.setFillColor(sf::Color::Black);
hunger_bar.setPosition(970, 50);
window.draw(hunger_bar);
sf::Text hunger_text;
hunger_text.setFont(font);
hunger_text.setCharacterSize(44);
hunger_text.setFillColor(sf::Color::Black);
hunger_text.setPosition(970, 2);
hunger_text.setString("Hunger Bar: ");
window.draw(hunger_text);
// IQ bar
sf::RectangleShape iq_bar(sf::Vector2f(250 * iq_level / 100.0f, 30));
iq_bar.setFillColor(sf::Color::Black);
iq_bar.setPosition(650, 50);
window.draw(iq_bar);
sf::Text iq_bar_text;
iq_bar_text.setFont(font);
iq_bar_text.setCharacterSize(44);
iq_bar_text.setFillColor(sf::Color::Black);
iq_bar_text.setPosition(650, 2);
iq_bar_text.setString("IQ Bar: ");
window.draw(iq_bar_text);
// Money text
sf::Text money_text;
money_text.setFont(font);
money_text.setCharacterSize(44);
money_text.setFillColor(sf::Color::Black);
money_text.setPosition(1320, 20);
money_text.setString(std::to_string(total_money));
window.draw(money_text);
// Coin sign
sf::Texture coin_sign_texture;
if (!coin_sign_texture.loadFromFile("coin.png")) {
std::cout << "Image Not Found" << std::endl;
}
sf::Sprite coin_sign;
coin_sign.setTexture(coin_sign_texture);
coin_sign.setPosition(1240, 20);
coin_sign.setScale(0.1f, 0.1f);
window.draw(coin_sign); // Draw the coin sign
}
// Function to determine color based on the stat level (if needed)
sf::Color PetStats::getBarColor(int level) {
return sf::Color::Black; // Return black color for now
}
void PetStats::increaseHunger(int amount) {
hunger_level = std::min(100, hunger_level + amount);
}
void PetStats::increaseSleep(int amount) {
sleep_level = std::min(100, sleep_level + amount);
}
void PetStats::increaseIQ(int score) {
if (score >= 0 && score <= 5) {
iq_level = std::min(100, iq_level + (score * 5));
std::cout << iq_level << std::endl;
}
}
void PetStats::increaseMoney(int amount) { total_money += amount; }
int PetStats::getMoney() const { return total_money; }
void PetStats::useHungerPotion() { hunger_level = 100; }
void PetStats::useSleepPotion() { sleep_level = 100; }
void PetStats::maxHealth() { health_level = 100; }
void PetStats::maxSleep() { sleep_level = 100; }
void PetStats::maxHunger() { hunger_level = 100; }
void PetStats::changeMoney(int someMoney) {
total_money = total_money + someMoney;
}
void PetStats::checkStats(sf::RenderWindow& window, sf::Font& font) {
// Variable to keep track of where to position the next warning
float warning_position_y = 400; // Start at Y position 400
float warning_position_x = 20; // Fixed X position at 20
// Display warnings if any stat is at 0
if (health_level <= 0) {
sf::Text warning_text;
warning_text.setFont(font);
warning_text.setCharacterSize(44);
warning_text.setFillColor(sf::Color::Red);
warning_text.setPosition(warning_position_x,
warning_position_y); // X = 20, Y starts at 400
warning_text.setString("WARNING!! HEALTH IS 0");
window.draw(warning_text);
warning_position_y += 60; // Move down for the next warning
}
if (sleep_level <= 0) {
sf::Text warning_text;
warning_text.setFont(font);
warning_text.setCharacterSize(44);
warning_text.setFillColor(sf::Color::Red);
warning_text.setPosition(warning_position_x, warning_position_y); // X = 20
warning_text.setString("WARNING!! SLEEP IS 0");
window.draw(warning_text);
warning_position_y += 60;
}
if (hunger_level <= 0) {
sf::Text warning_text;
warning_text.setFont(font);
warning_text.setCharacterSize(44);
warning_text.setFillColor(sf::Color::Red);
warning_text.setPosition(warning_position_x, warning_position_y); // X = 20
warning_text.setString("WARNING!! HUNGER IS 0");
window.draw(warning_text);
warning_position_y += 60;
}
if (iq_level <= 0) {
sf::Text warning_text;
warning_text.setFont(font);
warning_text.setCharacterSize(44);
warning_text.setFillColor(sf::Color::Red);
warning_text.setPosition(warning_position_x, warning_position_y); // X = 20
warning_text.setString("WARNING!! IQ IS 0");
window.draw(warning_text);
warning_position_y += 60;
}
}