Pacman Torben Petré
Loading...
Searching...
No Matches
GhostModel.h
Go to the documentation of this file.
1#ifndef PACMAN_GHOSTMODEL_H
2#define PACMAN_GHOSTMODEL_H
3
4#include "../PacmanModel.h"
5
6
7namespace logic {
8
34
35
37 public:
51 explicit GhostModel(float normalizedX, float normalizedY, float mapWidth, float mapHeight, double cooldown);
52 ~GhostModel() override = default;
53
54
59 [[nodiscard]] GhostState getState() const;
60
65 [[nodiscard]] bool isFrightened() const;
66
72 [[nodiscard]] int getGridSpawnX() const;
73
79 [[nodiscard]] int getGridSpawnY() const;
80
81
95 void setFrightened(bool frightened, const World& world);
96
97
107 void pacmanCollides(World& world);
108
121 void move(const World& world, float dt) override;
122
132 void respawn() override;
133
134 protected:
142 virtual Moves decideNextMove(const World& world) = 0;
143
144 private:
155 bool gridTargetReached(const World& world) override;
156
163 void updateWaiting(const World& world, double dt);
164
170 void updateExiting(const World& world);
171
177 void updateChasing(const World& world);
178
183 void updateDead(const World& world);
184
185 GhostState state;
186 float defaultSpeed;
187
188 int gridSpawnX;
189 int gridSpawnY;
190
191 bool frightened = false;
192
193 double startCooldown;
194 double waitingTime;
195
196 std::list<Moves> cachedPath;
197 };
198
199}
200
201
202#endif //PACMAN_GHOSTMODEL_H
~GhostModel() override=default
bool isFrightened() const
Returns whether the Ghost is currently frightened.
Definition GhostModel.cpp:27
GhostModel(float normalizedX, float normalizedY, float mapWidth, float mapHeight, double cooldown)
Base class for Ghosts. Handles Ghost state and how that influences ghost behaviour.
Definition GhostModel.cpp:11
int getGridSpawnX() const
Returns the Grid mapped X coordinate of where the Ghost spawned.
Definition GhostModel.cpp:31
virtual Moves decideNextMove(const World &world)=0
This function must be overriden by any inheriting Ghost classes. It must return the best Move accordi...
int getGridSpawnY() const
Returns the Grid mapped Y coordinate of where the Ghost spawned.
Definition GhostModel.cpp:35
void setFrightened(bool frightened, const World &world)
Allows the World to set toggle whether the Ghost is Frigthened or not.
Definition GhostModel.cpp:40
void pacmanCollides(World &world)
Tells the Ghost it collided with Pacman and should handle this situation.
Definition GhostModel.cpp:64
void respawn() override
Tell the Ghost to respawn. It will go back to its spawnpoint and start in a GhostState::WAITING state...
Definition GhostModel.cpp:118
void move(const World &world, float dt) override
This function is to be called in the World update loop. The Ghost will act based on it's current Stat...
Definition GhostModel.cpp:82
GhostState getState() const
Returns the current state of the Ghost.
Definition GhostModel.cpp:23
float mapWidth
Definition EntityModel.h:120
MovingEntityModel(float normalizedX, float normalizedY, float mapWidth, float mapHeight, float speed)
Subclass of EntityModel to be used for any moving entity.
Definition EntityModel.cpp:22
float mapHeight
Definition EntityModel.h:121
Definition World.h:16
Definition Difficulty.h:6
GhostState
Definition GhostModel.h:33
@ WAITING
Definition GhostModel.h:33
@ EXITING
Definition GhostModel.h:33
@ CHASING
Definition GhostModel.h:33
@ DEAD
Definition GhostModel.h:33
Moves
Definition EntityModel.h:8