Pacman Torben Petré
Loading...
Searching...
No Matches
logic::MovingEntityModel Class Referenceabstract

#include <EntityModel.h>

Inheritance diagram for logic::MovingEntityModel:
Collaboration diagram for logic::MovingEntityModel:

Public Member Functions

 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
virtual void move (const World &world, float dt)=0
 Called within the World update loop and should update the position of the entity or handle moving the entity appropriately.
virtual void respawn ()=0
 Called when an entity should respawn, this means it died and should be 'reset' to some extent.
Public Member Functions inherited from logic::EntityModel
 EntityModel (float normalizedX, float normalizedY)
 Base class for entities.
 ~EntityModel () override=default
float getX () const
float getY () const
Public Member Functions inherited from logic::Subject
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.

Protected Member Functions

virtual bool gridTargetReached (const World &world)=0
 This function should be called when the MovingEntity has reached its targetX and targetY values (within a certain Epsilon).
void normalizeTarget ()
 Normalizes the grid coordinates and stores these values in as target coordinates. Moving entities strive towards normalized grid coordinates.

Protected Attributes

float mapWidth
float mapHeight
float spawnX
float spawnY
int gridY
int gridX
float targetX
float targetY
Moves direction = Moves::RIGHT
float speed
Protected Attributes inherited from logic::EntityModel
float x
float y
Protected Attributes inherited from logic::Subject
std::list< std::weak_ptr< Observer > > observers

Constructor & Destructor Documentation

◆ MovingEntityModel()

MovingEntityModel::MovingEntityModel ( float normalizedX,
float normalizedY,
float mapWidth,
float mapHeight,
float speed )

Subclass of EntityModel to be used for any moving entity.

Parameters
normalizedXNormalized initial X coordinate
normalizedYNormalized initial Y coordinate
mapWidthMap width (in tiles)
mapHeightMap height (in tiles)
speedDefault speed of entity

Member Function Documentation

◆ getDirection()

Moves MovingEntityModel::getDirection ( ) const
nodiscard

Get the direction the entity is currently moving in.

Returns
Current direction

◆ getGridX()

int MovingEntityModel::getGridX ( ) const
nodiscard
Returns
Current grid aligned X coordinate

◆ getGridY()

int MovingEntityModel::getGridY ( ) const
nodiscard
Returns
Current grid aligned Y coordinate

◆ gridTargetReached()

virtual bool logic::MovingEntityModel::gridTargetReached ( const World & world)
protectedpure virtual

This function should be called when the MovingEntity has reached its targetX and targetY values (within a certain Epsilon).

Parameters
worldWorld
Returns
Whether the entity continues down its current direction.

◆ move()

virtual void logic::MovingEntityModel::move ( const World & world,
float dt )
pure virtual

Called within the World update loop and should update the position of the entity or handle moving the entity appropriately.

Parameters
worldWorld
dtDeltatime since last call

Implemented in logic::GhostModel, and logic::PacmanModel.

◆ normalizeTarget()

void MovingEntityModel::normalizeTarget ( )
protected

Normalizes the grid coordinates and stores these values in as target coordinates. Moving entities strive towards normalized grid coordinates.

◆ respawn()

virtual void logic::MovingEntityModel::respawn ( )
pure virtual

Called when an entity should respawn, this means it died and should be 'reset' to some extent.

Implemented in logic::GhostModel, and logic::PacmanModel.

Member Data Documentation

◆ direction

Moves logic::MovingEntityModel::direction = Moves::RIGHT
protected

◆ gridX

int logic::MovingEntityModel::gridX
protected

◆ gridY

int logic::MovingEntityModel::gridY
protected

◆ mapHeight

float logic::MovingEntityModel::mapHeight
protected

◆ mapWidth

float logic::MovingEntityModel::mapWidth
protected

◆ spawnX

float logic::MovingEntityModel::spawnX
protected

◆ spawnY

float logic::MovingEntityModel::spawnY
protected

◆ speed

float logic::MovingEntityModel::speed
protected

◆ targetX

float logic::MovingEntityModel::targetX
protected

◆ targetY

float logic::MovingEntityModel::targetY
protected

The documentation for this class was generated from the following files: