2021-06-24 11:32:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#include "Atlas.hpp"
|
|
|
|
#include "Board.hpp"
|
|
|
|
#include "Position.hpp"
|
|
|
|
|
2021-07-05 12:10:01 +00:00
|
|
|
namespace pacman {
|
|
|
|
|
2021-07-28 13:28:36 +00:00
|
|
|
class GameState;
|
|
|
|
|
2021-06-24 11:32:52 +00:00
|
|
|
class Ghost {
|
|
|
|
public:
|
|
|
|
enum class State {
|
|
|
|
Chase,
|
|
|
|
Scatter,
|
2021-06-28 10:42:21 +00:00
|
|
|
Frightened,
|
2021-06-24 11:32:52 +00:00
|
|
|
Eyes,
|
|
|
|
};
|
|
|
|
|
2021-07-28 17:06:35 +00:00
|
|
|
explicit Ghost(Atlas::Ghost spriteSet);
|
2021-07-28 14:20:19 +00:00
|
|
|
virtual ~Ghost() = default;
|
2021-06-24 11:32:52 +00:00
|
|
|
|
2021-07-05 09:46:49 +00:00
|
|
|
[[nodiscard]] GridPosition currentSprite() const;
|
2021-06-24 11:32:52 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Position position() const;
|
|
|
|
|
2021-07-05 11:54:54 +00:00
|
|
|
[[nodiscard]] GridPosition positionInGrid() const;
|
2021-06-24 11:32:52 +00:00
|
|
|
|
2021-07-28 13:28:36 +00:00
|
|
|
void update(std::chrono::milliseconds time_delta, const GameState & gameState);
|
2021-06-28 10:42:21 +00:00
|
|
|
void frighten();
|
2021-07-13 12:26:57 +00:00
|
|
|
void die();
|
2021-07-07 09:24:12 +00:00
|
|
|
[[nodiscard]] bool isFrightened() const;
|
|
|
|
[[nodiscard]] bool isEyes() const;
|
2021-06-28 10:42:21 +00:00
|
|
|
void reset();
|
2021-06-24 11:32:52 +00:00
|
|
|
|
2021-06-25 09:06:50 +00:00
|
|
|
private:
|
|
|
|
void updateAnimation(std::chrono::milliseconds time_delta);
|
2021-07-28 13:28:36 +00:00
|
|
|
void updatePosition(std::chrono::milliseconds time_delta, const GameState & gameState);
|
|
|
|
void updateDirection(const GameState & gameState);
|
2021-06-25 09:06:50 +00:00
|
|
|
|
2021-06-24 11:32:52 +00:00
|
|
|
protected:
|
2021-07-28 13:28:36 +00:00
|
|
|
|
2021-07-28 14:20:19 +00:00
|
|
|
virtual double speed(const GameState & gameState) const = 0;
|
|
|
|
virtual Position target(const GameState & gameState) const = 0;
|
|
|
|
virtual Position initialPosition() const = 0;
|
|
|
|
|
2021-07-28 17:06:35 +00:00
|
|
|
Atlas::Ghost spriteSet;
|
2021-06-24 11:32:52 +00:00
|
|
|
Direction direction = Direction::NONE;
|
2021-06-28 10:42:21 +00:00
|
|
|
double timeForAnimation = 0;
|
|
|
|
int animationIndex = 0;
|
2021-06-24 11:32:52 +00:00
|
|
|
State state = State::Chase;
|
2021-06-28 10:42:21 +00:00
|
|
|
int timeFrighten = 0;
|
|
|
|
int timeChase = 0;
|
2021-06-24 11:32:52 +00:00
|
|
|
Position pos;
|
2021-07-06 10:35:23 +00:00
|
|
|
GridPosition last_grid_position = { 0, 0 };
|
2021-07-07 09:39:09 +00:00
|
|
|
[[nodiscard]] bool isInPen() const;
|
2021-06-24 11:32:52 +00:00
|
|
|
};
|
|
|
|
|
2021-07-05 12:10:01 +00:00
|
|
|
} // namespace pacman
|