-
Notifications
You must be signed in to change notification settings - Fork 1
/
Level.h
71 lines (50 loc) · 1.86 KB
/
Level.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef SUPERMARIOBROS_LEVEL_H
#define SUPERMARIOBROS_LEVEL_H
#include "Event.h"
#include "Input.h"
#include "Text.h"
#include "entities/Mario.h"
class InvisibleWall;
/*
* Encapsulates the game logic and entities for a single
* level.
*/
class Level
{
public:
/*
* Construct a new level from Mario and the entities in the level.
* Current, the Level has ownership of Mario and the entities
*/
Level(std::unique_ptr<Mario> mario,
std::vector<std::unique_ptr<Entity>>&& entities,
sf::RenderWindow& window,
InvisibleWall& wall);
void setMarioMovementFromController(const KeyboardInput& currentInput);
void executeFrame(const KeyboardInput& input);
void drawFrame(sf::RenderWindow& window);
[[nodiscard]] const Mario& getMario() const;
private:
void addEntityToFront(std::unique_ptr<Entity> entity);
void addHUDOverlay();
void scroll();
std::vector<std::shared_ptr<Text>> mTextElements;
std::unique_ptr<Mario> mMario;
std::shared_ptr<Points> mPoints;
std::vector<std::unique_ptr<Entity>> mEntities;
sf::RenderWindow& mWindow;
InvisibleWall& mWall;
[[nodiscard]] bool physicsAreOn() const;
float setVerticalVelocityDueToJumpStart(const KeyboardInput& currentInput,
const sf::Vector2f& velocity) const;
float calculateVerticalAcceleration(const KeyboardInput& currentInput,
float xVelocity) const;
void onPointsEarned(const Event::PointsEarned&);
void onItemSpawned(const Event::ItemSpawned&);
void onBlockShattered(const Event::BlockShattered&);
void onAnimationCompleted(const Event::AnimationCompleted&);
void onFireballSpawned(const Event::FireballSpawned&);
};
std::vector<Event>& getEventQueue();
void addEvent(Event event);
#endif // SUPERMARIOBROS_LEVEL_H