#include <GhostModel.h>
|
| | GhostModel (float normalizedX, float normalizedY, float mapWidth, float mapHeight, double cooldown) |
| | Base class for Ghosts. Handles Ghost state and how that influences ghost behaviour.
|
| | ~GhostModel () override=default |
| GhostState | getState () const |
| | Returns the current state of the Ghost.
|
| bool | isFrightened () const |
| | Returns whether the Ghost is currently frightened.
|
| int | getGridSpawnX () const |
| | Returns the Grid mapped X coordinate of where the Ghost spawned.
|
| int | getGridSpawnY () const |
| | Returns the Grid mapped Y coordinate of where the Ghost spawned.
|
| void | setFrightened (bool frightened, const World &world) |
| | Allows the World to set toggle whether the Ghost is Frigthened or not.
|
| void | pacmanCollides (World &world) |
| | Tells the Ghost it collided with Pacman and should handle this situation.
|
| 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 State and possibly move.
|
| void | respawn () override |
| | Tell the Ghost to respawn. It will go back to its spawnpoint and start in a GhostState::WAITING state again.
|
| | MovingEntityModel (float normalizedX, float normalizedY, float mapWidth, float mapHeight, float speed) |
| | Subclass of EntityModel to be used for any moving entity.
|
| Moves | getDirection () const |
| | Get the direction the entity is currently moving in.
|
| int | getGridX () const |
| int | getGridY () const |
| | EntityModel (float normalizedX, float normalizedY) |
| | Base class for entities.
|
| | ~EntityModel () override=default |
| float | getX () const |
| float | getY () const |
| virtual | ~Subject ()=default |
| void | attach (const std::shared_ptr< Observer > &observer) |
| | Attaches an observer to this Subject.
|
| void | notify (Events event) |
| | Call the Observer update function with the provided event.
|
|
| virtual Moves | decideNextMove (const World &world)=0 |
| | This function must be overriden by any inheriting Ghost classes. It must return the best Move according to its attacking personality.
|
| void | normalizeTarget () |
| | Normalizes the grid coordinates and stores these values in as target coordinates. Moving entities strive towards normalized grid coordinates.
|
◆ GhostModel()
| GhostModel::GhostModel |
( |
float | normalizedX, |
|
|
float | normalizedY, |
|
|
float | mapWidth, |
|
|
float | mapHeight, |
|
|
double | cooldown ) |
|
explicit |
Base class for Ghosts. Handles Ghost state and how that influences ghost behaviour.
Uses GhostNavigator helper functions for Pathfinding and Path related decision-making.
- Parameters
-
| normalizedX | Normalized x spawn coordinate |
| normalizedY | Normalized y spawn coordinate |
| mapWidth | Map width (in tiles) |
| mapHeight | Map height (in tiles) |
| cooldown | Spawn cooldown before leaving enclosure |
◆ ~GhostModel()
| logic::GhostModel::~GhostModel |
( |
| ) |
|
|
overridedefault |
◆ decideNextMove()
| virtual Moves logic::GhostModel::decideNextMove |
( |
const World & | world | ) |
|
|
protectedpure virtual |
This function must be overriden by any inheriting Ghost classes. It must return the best Move according to its attacking personality.
- Parameters
-
- Returns
- The best Move for this Ghost
◆ getGridSpawnX()
| int GhostModel::getGridSpawnX |
( |
| ) |
const |
|
nodiscard |
Returns the Grid mapped X coordinate of where the Ghost spawned.
- Returns
- Grid X coordinate of Ghost spawn
◆ getGridSpawnY()
| int GhostModel::getGridSpawnY |
( |
| ) |
const |
|
nodiscard |
Returns the Grid mapped Y coordinate of where the Ghost spawned.
- Returns
- Grid Y coordinate of Ghost spawn
◆ getState()
Returns the current state of the Ghost.
- Returns
- GhostState
◆ isFrightened()
| bool GhostModel::isFrightened |
( |
| ) |
const |
|
nodiscard |
Returns whether the Ghost is currently frightened.
- Returns
- Frightened
◆ move()
| void GhostModel::move |
( |
const World & | world, |
|
|
float | dt ) |
|
overridevirtual |
This function is to be called in the World update loop. The Ghost will act based on it's current State and possibly move.
Whether the Ghost actually moves or not depends on its state. A GhostState::WAITING will not move until its cooldown runs out. Otherwise, it will move based on it's behaviour and whether it is frightened.
- Parameters
-
| world | World |
| dt | Deltatime since last call |
Implements logic::MovingEntityModel.
◆ pacmanCollides()
| void GhostModel::pacmanCollides |
( |
World & | world | ) |
|
Tells the Ghost it collided with Pacman and should handle this situation.
Depending on whether the Ghost is frightened or not it will kill Pacman, or get killed.
- Parameters
-
◆ respawn()
| void GhostModel::respawn |
( |
| ) |
|
|
overridevirtual |
Tell the Ghost to respawn. It will go back to its spawnpoint and start in a GhostState::WAITING state again.
If the Ghost must respawn because of getting eaten while being frightened, it may instantly switch to a GhostState::EXITING without waiting for its cooldown to pass. If Pacman dies and the World resets, the Ghost will have to watch its cooldown again.
Implements logic::MovingEntityModel.
◆ setFrightened()
| void GhostModel::setFrightened |
( |
bool | frightened, |
|
|
const World & | world ) |
Allows the World to set toggle whether the Ghost is Frigthened or not.
- Warning
- Any change to the frightened state is ignored while a Ghost is dead.
Changes the Ghost's internal state and notifies Observers. Updates the Ghost speed to match its frightenedness. Updates the Ghost's internal pathing to either run away or re-target Pacman.
- Parameters
-
| frightened | True or False toggle |
| world | World |
The documentation for this class was generated from the following files: