2021-09-13 12:47:09 +00:00
|
|
|
#include "Fruits.hpp"
|
|
|
|
#include "GameState.hpp"
|
|
|
|
|
|
|
|
namespace pacman {
|
|
|
|
|
|
|
|
void Fruits::update(std::chrono::milliseconds time_delta, const GameState & gameState) {
|
2021-09-15 12:40:07 +00:00
|
|
|
if (visible) {
|
|
|
|
time_visible += time_delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time_visible > std::chrono::seconds(9)) {
|
|
|
|
hide();
|
|
|
|
} else if ((index == 0 && gameState.score.eatenPellets >= 70) || (index == 1 && gameState.score.eatenPellets >= 170)) {
|
|
|
|
// 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
|