Pacman Torben Petré
Loading...
Searching...
No Matches
EntityModel.h
Go to the documentation of this file.
1#ifndef ENTITYMODEL_H
2#define ENTITYMODEL_H
3
4#include "../Observer.h"
5
6
7namespace logic {
8 enum Moves { UP, LEFT, RIGHT, DOWN };
9
10 class World;
11
12 class EntityModel : public Subject {
13 public:
19 explicit EntityModel(float normalizedX, float normalizedY);
20 ~EntityModel() override = default;
21
22
26 [[nodiscard]] float getX() const;
27
31 [[nodiscard]] float getY() const;
32
33 protected:
34 float x;
35 float y;
36 };
37
38
40 public:
46 explicit CollectibleEntityModel(float normalizedX, float normalizedY);
47
48
54 [[nodiscard]] virtual Events collect() = 0;
55 };
56
57
58 constexpr float TARGET_EPSILON = 0.001f;
59
61 public:
70 MovingEntityModel(float normalizedX, float normalizedY, float mapWidth, float mapHeight, float speed);
71
72
77 [[nodiscard]] Moves getDirection() const;
78
82 [[nodiscard]] int getGridX() const;
83
87 [[nodiscard]] int getGridY() const;
88
89
96 virtual void move(const World &world, float dt) = 0;
97
102 virtual void respawn() = 0;
103
104 protected:
111 virtual bool gridTargetReached(const World& world) = 0;
112
118 void normalizeTarget();
119
120 float mapWidth;
122
123 float spawnX;
124 float spawnY;
125
126 int gridY;
127 int gridX;
128 float targetX;
129 float targetY;
130
132 float speed;
133 };
134}
135
136
137
138#endif //ENTITYMODEL_H
virtual Events collect()=0
Function that will be called when Pacman interacts with a collectible entity. Must handle this intera...
CollectibleEntityModel(float normalizedX, float normalizedY)
Subclass of EntityModel to be used by collectible entities.
Definition EntityModel.cpp:19
float x
Definition EntityModel.h:34
~EntityModel() override=default
EntityModel(float normalizedX, float normalizedY)
Base class for entities.
Definition EntityModel.cpp:7
float y
Definition EntityModel.h:35
float getY() const
Definition EntityModel.cpp:14
float getX() const
Definition EntityModel.cpp:10
float targetX
Definition EntityModel.h:128
int gridX
Definition EntityModel.h:127
float mapWidth
Definition EntityModel.h:120
int gridY
Definition EntityModel.h:126
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
void normalizeTarget()
Normalizes the grid coordinates and stores these values in as target coordinates. Moving entities str...
Definition EntityModel.cpp:44
int getGridY() const
Definition EntityModel.cpp:39
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...
float spawnX
Definition EntityModel.h:123
float targetY
Definition EntityModel.h:129
Moves direction
Definition EntityModel.h:131
virtual void respawn()=0
Called when an entity should respawn, this means it died and should be 'reset' to some extent.
int getGridX() const
Definition EntityModel.cpp:35
float speed
Definition EntityModel.h:132
Moves getDirection() const
Get the direction the entity is currently moving in.
Definition EntityModel.cpp:31
virtual bool gridTargetReached(const World &world)=0
This function should be called when the MovingEntity has reached its targetX and targetY values (with...
float spawnY
Definition EntityModel.h:124
float mapHeight
Definition EntityModel.h:121
Definition Observer.h:32
Definition World.h:16
Definition Difficulty.h:6
constexpr float TARGET_EPSILON
Definition EntityModel.h:58
Moves
Definition EntityModel.h:8
@ DOWN
Definition EntityModel.h:8
@ LEFT
Definition EntityModel.h:8
@ RIGHT
Definition EntityModel.h:8
@ UP
Definition EntityModel.h:8
Events
Definition Observer.h:14