Pacman Torben Petré
Loading...
Searching...
No Matches
LevelState.h
Go to the documentation of this file.
1#ifndef LEVELSTATE_H
2#define LEVELSTATE_H
3
4#include <unordered_map>
5
7#include "StateManager.h"
8
9
10class LevelState final :
11 public State,
12 public logic::Observer,
13 public std::enable_shared_from_this<LevelState> {
14
15 // The Pass-Key pattern is a way to control who can create instances of a
16 // class when using smart pointers. Smart pointers do not work with private
17 // constructors, so a different method is used.
18 struct passkey{};
19
20public:
27 static std::shared_ptr<LevelState> create(StateManager& context);
28
36 explicit LevelState(passkey, StateManager& context);
37
42 void handleInput(const sf::Event::KeyEvent &keyPressed) override;
43
47 void resized() override;
48
53 void update(double dt) override;
54
59 void render() override;
60
61private:
70 void update(logic::Events event) override;
71
72 std::shared_ptr<ConcreteFactory> factory;
73 std::shared_ptr<logic::Score> scoreSystem;
74 std::shared_ptr<SoundManager> soundManager;
75 std::shared_ptr<logic::World> world;
76 std::shared_ptr<WorldView> worldView;
77
78 bool cleanupRequired;
79 bool resizeRequired;
80
81 std::unordered_map<Layer, std::vector<std::shared_ptr<EntityView>>> entityViews{
82 {Layer::BACKGROUND, std::vector<std::shared_ptr<EntityView>>()},
83 {Layer::FOREGROUND, std::vector<std::shared_ptr<EntityView>>()},
84 {Layer::PACMAN, std::vector<std::shared_ptr<EntityView>>()}
85 };
86};
87
88
89
90#endif //LEVELSTATE_H
@ PACMAN
Definition ConcreteFactory.h:17
@ FOREGROUND
Definition ConcreteFactory.h:17
@ BACKGROUND
Definition ConcreteFactory.h:17
static std::shared_ptr< LevelState > create(StateManager &context)
Creates a LevelState which initiates a Pacman Level by setting up a logic::Word and rendering the gam...
Definition LevelState.cpp:47
LevelState(passkey, StateManager &context)
This State initiates a Pacman level by setting up a logic::World and rendering the game views.
Definition LevelState.cpp:13
void render() override
Renders all Views associated with this level. Does this on a layer basis.
Definition LevelState.cpp:122
void resized() override
Will resize the Game Views.
Definition LevelState.cpp:92
void update(double dt) override
Updates ScoreSystem and World.
Definition LevelState.cpp:97
void handleInput(const sf::Event::KeyEvent &keyPressed) override
Passes concrete Moves to the World instance & handles pausing.
Definition LevelState.cpp:55
State(StateManager &ctx)
Creates the base State object.
Definition StateManager.cpp:4
StateManager & context
Definition StateManager.h:54
Definition StateManager.h:96
Definition Observer.h:16
Events
Definition Observer.h:14