pacman/lib/include/Ghost.hpp

78 lines
1.6 KiB
C++
Raw Normal View History

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-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,
};
explicit Ghost(Atlas::Ghost spritesSet, Position startingPosition, Position scatterTarget);
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
void update(std::chrono::milliseconds time_delta, const Board & board);
2021-06-28 10:42:21 +00:00
void frighten();
void eat();
bool isFrightened() const;
bool isEyes() const;
void reset();
2021-06-24 11:32:52 +00:00
private:
2021-06-28 10:42:21 +00:00
double speed() const;
void updateAnimation(std::chrono::milliseconds time_delta);
void updatePosition(std::chrono::milliseconds time_delta, const Board & board);
void updateDirection(const Board & board);
Position target(const Board & board) const;
2021-06-24 11:32:52 +00:00
protected:
Atlas::Ghost spritesSet;
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;
Position startingPosition;
Position scatterTarget;
2021-07-06 10:35:23 +00:00
GridPosition last_grid_position = { 0, 0 };
2021-07-01 12:53:52 +00:00
bool isInPen(const Board & board) const;
2021-06-24 11:32:52 +00:00
};
class Blinky : public Ghost {
public:
explicit Blinky(const Board & board);
};
class Speedy : public Ghost {
public:
explicit Speedy(const Board & board);
};
class Inky : public Ghost {
public:
explicit Inky(const Board & board);
};
class Clyde : public Ghost {
public:
explicit Clyde(const Board & board);
};
2021-07-05 12:10:01 +00:00
} // namespace pacman