Pacman Torben Petré
Loading...
Searching...
No Matches
World.h
Go to the documentation of this file.
1#ifndef WORLD_H
2#define WORLD_H
3
4#include <vector>
5#include <string>
6
8#include "Difficulty.h"
9
10
11namespace logic {
13
14 constexpr float COLLISSION_EPSILON = 0.07f;
15
16 class World final : public Subject {
17 public:
24 explicit World(const std::shared_ptr<AbstractFactory> &factory, int lives);
25
26
32 [[nodiscard]] float getWidth() const;
38 [[nodiscard]] float getHeight() const;
39
40
46 [[nodiscard]] int getGhostExitX() const;
47
53 [[nodiscard]] int getGhostExitY() const;
54
55
59 [[nodiscard]] std::shared_ptr<PacmanModel> getPacman() const;
60
65 [[nodiscard]] unsigned int getLives() const;
66
67
73 [[nodiscard]] std::pair<float, float> getCollissionCoordinates() const;
74
75
82 [[nodiscard]] float normalizeX(int value) const;
83
90 [[nodiscard]] float normalizeY(int value) const;
91
92
101 [[nodiscard]] bool collidesWithWall(float normalizedX, float normalizedY, bool passDoor) const;
102
103
121 void loadMap(const std::string& path);
122
123
129 void update(double dt);
130
131
136 void handleMove(const Moves& move) const;
137
138
143 void killPacman();
144
145 private:
151 static bool isColliding(const EntityModel& a, const EntityModel& b);
152
153
158 void respawnEntities();
159
163 void startFrightened();
164
168 void endFrightened();
169
170
176 void updateRestartingState(double dt);
177
183 void updateFrightenedState(double dt);
184
191 void updatePlayingState(double dt);
192
193
198 void updateGhosts(double dt);
199
203 void updateCollectibles();
204
205 float mapHeight = 20;
206 float mapWidth = 20;
207
208 float tileWidth = 16;
209 float tileHeight = 16;
210
211 int ghostExitX;
212 int ghostExitY;
213
214 float DEATH_DURATION = 2;
215 float FEAR_DURATION = Difficulty::getInstance().getFrightenedTime();
216 float FLASH_TIMESTAMP = FEAR_DURATION - (0.4f * Difficulty::getInstance().getFlashesh());
217
218 WorldState state;
219 double timer = 0;
220 bool flashing = false;
221
222 std::pair<float, float> collissionCoordinates;
223
224 std::shared_ptr<AbstractFactory> factory;
225 std::vector<std::shared_ptr<CollectibleEntityModel>> collectibles;
226 std::vector<std::shared_ptr<GhostModel>> ghosts;
227 std::vector<std::shared_ptr<WallModel>> walls;
228
229 std::shared_ptr<PacmanModel> pacman;
230 unsigned int lives;
231 };
232}
233
234
235
236#endif //WORLD_H
float getFrightenedTime() const
This duration differs on every level and goes up and down.
Definition Difficulty.cpp:66
static Difficulty & getInstance()
Returns an instance of the Difficulty class.
Definition Difficulty.cpp:30
int getFlashesh() const
Flashes determine how many warnings the player gets before frightened ghosts turn normal again.
Definition Difficulty.cpp:70
Definition EntityModel.h:12
Definition Observer.h:32
std::pair< float, float > getCollissionCoordinates() const
Pair that holds the X and Y coordinates of the last collission registered by the World.
Definition World.cpp:37
std::shared_ptr< PacmanModel > getPacman() const
Definition World.cpp:28
float normalizeY(int value) const
Normalizes Grid coordinates on a [-1, 1] bounded coordinate system.
Definition World.cpp:46
int getGhostExitX() const
Exit coordinates are the coordinates specified on the map which Ghosts must go to in their exiting st...
Definition World.cpp:19
World(const std::shared_ptr< AbstractFactory > &factory, int lives)
Creates a World instance. Creating an instance does nothing on its own.
Definition World.cpp:7
unsigned int getLives() const
The current amount of lives that Pacman has remaining.
Definition World.cpp:32
void loadMap(const std::string &path)
Loads any map that is in a rectangular format and follows the specific ASCII formatting....
Definition World.cpp:70
void killPacman()
Kills Pacman, subtracts a live and puts the World in RESTARTING state.
Definition World.cpp:276
int getGhostExitY() const
Exit coordinates are the coordinates specified on the map which Ghosts must go to in their exiting st...
Definition World.cpp:23
void update(double dt)
World Update function. Calls specific helper methods based on the current World state (RESTARTING,...
Definition World.cpp:249
float normalizeX(int value) const
Normalizes Grid coordinates on a [-1, 1] bounded coordinate system.
Definition World.cpp:42
float getHeight() const
Returns the height of the currently loaded map (width is in tiles).
Definition World.cpp:15
void handleMove(const Moves &move) const
Passes a move down to Pacman.
Definition World.cpp:269
float getWidth() const
Returns the width of the currently loaded map (width is in tiles).
Definition World.cpp:11
bool collidesWithWall(float normalizedX, float normalizedY, bool passDoor) const
Checks whether the provided coordinates collide with a wall. Takes door Wall types into consideration...
Definition World.cpp:56
Definition Difficulty.h:6
Moves
Definition EntityModel.h:8
WorldState
Definition World.h:12
@ RESTARTING
Definition World.h:12
@ FRIGHTENED
Definition World.h:12
@ PLAYING
Definition World.h:12
@ AWAITING_MAP
Definition World.h:12
constexpr float COLLISSION_EPSILON
Definition World.h:14