pacman/lib/include/Ghost.hpp

61 lines
1.4 KiB
C++

#pragma once
#include <chrono>
#include "Atlas.hpp"
#include "Board.hpp"
#include "Position.hpp"
namespace pacman {
struct GameState;
class Ghost {
public:
enum class State {
Chase,
Scatter,
Frightened,
Eyes,
};
explicit Ghost(Atlas::Ghost spriteSet);
virtual ~Ghost() = default;
GridPosition currentSprite() const;
Position position() const;
GridPosition positionInGrid() const;
void update(std::chrono::milliseconds time_delta, const GameState & gameState);
void frighten();
void die();
bool isFrightened() const;
bool isEyes() const;
void reset();
private:
void updateAnimation(std::chrono::milliseconds time_delta);
void updatePosition(std::chrono::milliseconds time_delta, const GameState & gameState);
void updateDirection(const GameState & gameState);
protected:
Atlas::Ghost spriteSet;
Direction direction = Direction::NONE;
double timeForAnimation = 0;
int animationIndex = 0;
State state = State::Chase;
std::chrono::milliseconds timeFrighten = {};
std::chrono::milliseconds timeChase = {};
Position pos;
GridPosition last_grid_position = { 0, 0 };
State defaultStateAtDuration(std::chrono::seconds seconds);
virtual double speed(const GameState & gameState) const = 0;
virtual Position target(const GameState & gameState) const = 0;
virtual Position initialPosition() const = 0;
bool isInPen() const;
};
} // namespace pacman