Pacman Torben Petré
Loading...
Searching...
No Matches
logic::World Class Referencefinal

#include <World.h>

Inheritance diagram for logic::World:
Collaboration diagram for logic::World:

Public Member Functions

 World (const std::shared_ptr< AbstractFactory > &factory, int lives)
 Creates a World instance. Creating an instance does nothing on its own.
float getWidth () const
 Returns the width of the currently loaded map (width is in tiles).
float getHeight () const
 Returns the height of the currently loaded map (width is in tiles).
int getGhostExitX () const
 Exit coordinates are the coordinates specified on the map which Ghosts must go to in their exiting state.
int getGhostExitY () const
 Exit coordinates are the coordinates specified on the map which Ghosts must go to in their exiting state.
std::shared_ptr< PacmanModelgetPacman () const
unsigned int getLives () const
 The current amount of lives that Pacman has remaining.
std::pair< float, float > getCollissionCoordinates () const
 Pair that holds the X and Y coordinates of the last collission registered by the World.
float normalizeX (int value) const
 Normalizes Grid coordinates on a [-1, 1] bounded coordinate system.
float normalizeY (int value) const
 Normalizes Grid coordinates on a [-1, 1] bounded coordinate system.
bool collidesWithWall (float normalizedX, float normalizedY, bool passDoor) const
 Checks whether the provided coordinates collide with a wall. Takes door Wall types into consideration.
void loadMap (const std::string &path)
 Loads any map that is in a rectangular format and follows the specific ASCII formatting. Letters are linked to specific entities. So certain gibberish is unloadable.
void update (double dt)
 World Update function. Calls specific helper methods based on the current World state (RESTARTING, FRIGHTENED, PLAYING).
void handleMove (const Moves &move) const
 Passes a move down to Pacman.
void killPacman ()
 Kills Pacman, subtracts a live and puts the World in RESTARTING state.
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.

Additional Inherited Members

Protected Attributes inherited from logic::Subject
std::list< std::weak_ptr< Observer > > observers

Constructor & Destructor Documentation

◆ World()

World::World ( const std::shared_ptr< AbstractFactory > & factory,
int lives )
explicit

Creates a World instance. Creating an instance does nothing on its own.

Parameters
factoryConcere implementation of AbstractFactory.
livesAmount of lives that Pacman will begin with.

Member Function Documentation

◆ collidesWithWall()

bool World::collidesWithWall ( float normalizedX,
float normalizedY,
bool passDoor ) const
nodiscard

Checks whether the provided coordinates collide with a wall. Takes door Wall types into consideration.

Parameters
normalizedX
normalizedY
passDoorWhether doors may be seen non-colliding.
Returns
Whether provided coordinates are inside a Wall.

◆ getCollissionCoordinates()

std::pair< float, float > World::getCollissionCoordinates ( ) const
nodiscard

Pair that holds the X and Y coordinates of the last collission registered by the World.

Returns
Collission coordinates

◆ getGhostExitX()

int World::getGhostExitX ( ) const
nodiscard

Exit coordinates are the coordinates specified on the map which Ghosts must go to in their exiting state.

Returns
Ghost exit X coordinate

◆ getGhostExitY()

int World::getGhostExitY ( ) const
nodiscard

Exit coordinates are the coordinates specified on the map which Ghosts must go to in their exiting state.

Returns
Ghost exit Y coordinate

◆ getHeight()

float World::getHeight ( ) const
nodiscard

Returns the height of the currently loaded map (width is in tiles).

Returns
Height

◆ getLives()

unsigned int World::getLives ( ) const
nodiscard

The current amount of lives that Pacman has remaining.

Returns
Lives

◆ getPacman()

std::shared_ptr< PacmanModel > World::getPacman ( ) const
nodiscard
Returns
Pacman Model

◆ getWidth()

float World::getWidth ( ) const
nodiscard

Returns the width of the currently loaded map (width is in tiles).

Returns
Width

◆ handleMove()

void World::handleMove ( const Moves & move) const

Passes a move down to Pacman.

Parameters
moveMove

◆ killPacman()

void World::killPacman ( )

Kills Pacman, subtracts a live and puts the World in RESTARTING state.

◆ loadMap()

void World::loadMap ( const std::string & path)

Loads any map that is in a rectangular format and follows the specific ASCII formatting. Letters are linked to specific entities. So certain gibberish is unloadable.

  • - Pacman . - Coin F - Fruit

- Exit tile (acts like a coin and defines the exit coordinates).

B - Blinky P - Pinky I - Inky C - Clyde t b r e f h i j k l m u o p 1 2 3 4 5 6 d a c g n - Specific wall pieces

Parameters
pathPath to file

◆ normalizeX()

float World::normalizeX ( int value) const
nodiscard

Normalizes Grid coordinates on a [-1, 1] bounded coordinate system.

Parameters
valueGrid X value
Returns
Normalized X value

◆ normalizeY()

float World::normalizeY ( int value) const
nodiscard

Normalizes Grid coordinates on a [-1, 1] bounded coordinate system.

Parameters
valueGrid Y value
Returns
Normalized Y value

◆ update()

void World::update ( double dt)

World Update function. Calls specific helper methods based on the current World state (RESTARTING, FRIGHTENED, PLAYING).

Parameters
dtDeltatime

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