2021-09-13 12:47:09 +00:00
|
|
|
#include "Fruits.hpp"
|
|
|
|
#include "GameState.hpp"
|
|
|
|
|
|
|
|
namespace pacman {
|
|
|
|
|
2021-09-23 12:57:53 +00:00
|
|
|
void Fruits::update(std::chrono::milliseconds time_delta, int eatenPellets) {
|
2021-09-15 12:40:07 +00:00
|
|
|
if (visible) {
|
|
|
|
time_visible += time_delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time_visible > std::chrono::seconds(9)) {
|
|
|
|
hide();
|
2021-09-23 12:57:53 +00:00
|
|
|
} else if ((index == 0 && eatenPellets >= 70) || (index == 1 && eatenPellets >= 170)) {
|
2021-09-15 12:40:07 +00:00
|
|
|
// We show the fruit twice, once at 70 pellets and once at 170
|
|
|
|
visible = true;
|
|
|
|
}
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GridPosition Fruits::currentSprite() const {
|
2021-09-15 12:40:07 +00:00
|
|
|
// That's the cherry
|
|
|
|
return { 3, 8 };
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Position Fruits::position() const {
|
2021-09-15 12:40:07 +00:00
|
|
|
// under the pen
|
|
|
|
return { 13.5, 17 };
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Fruits::isVisible() const {
|
2021-09-15 12:40:07 +00:00
|
|
|
return visible;
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Fruits::value() const {
|
2021-09-15 12:40:07 +00:00
|
|
|
// The cherry is worth 100
|
|
|
|
return 100;
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Fruits::eat() {
|
2021-09-15 12:40:07 +00:00
|
|
|
if (!isVisible()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hide();
|
|
|
|
return value();
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fruits::hide() {
|
2021-09-15 12:40:07 +00:00
|
|
|
index++;
|
|
|
|
time_visible = std::chrono::seconds{ 0 };
|
|
|
|
visible = false;
|
2021-09-13 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 12:40:07 +00:00
|
|
|
} // namespace pacman
|