Peoplemon  0.1.0
Peoplemon 3 game source documentation
Player.hpp
Go to the documentation of this file.
1 #ifndef CORE_SYSTEMS_PLAYER_HPP
2 #define CORE_SYSTEMS_PLAYER_HPP
3 
4 #include <BLIB/ECS.hpp>
5 #include <BLIB/Engine/System.hpp>
6 #include <BLIB/Events.hpp>
7 #include <BLIB/Tilemap/Position.hpp>
10 #include <Core/Events/GameSave.hpp>
13 #include <Core/Player/Bag.hpp>
14 #include <Core/Player/Gender.hpp>
15 #include <Core/Player/State.hpp>
16 
17 namespace core
18 {
19 namespace map
20 {
21 class Map;
22 }
23 namespace system
24 {
25 class Systems;
26 
33 class Player
34 : public bl::engine::System
35 , public bl::event::Listener<event::GameSaveInitializing, event::EntityMoveFinished> {
36 public:
42  Player(Systems& owner);
43 
47  virtual ~Player() = default;
48 
56  bool spawnPlayer(const bl::tmap::Position& position, map::Map& map);
57 
65  bool makePlayerControlled(bl::ecs::Entity entity);
66 
72  void removePlayerControlled(bl::ecs::Entity entity);
73 
78  bl::ecs::Entity player() const;
79 
84  const bl::tmap::Position& position() const;
85 
92  void newGame(const std::string& name, player::Gender gender);
93 
98  void whiteout();
99 
104  player::State& state();
105 
110  const player::State& state() const;
111 
116  void showLantern();
117 
118 private:
119  Systems& owner;
120  bl::ecs::Entity playerId;
121  bl::tmap::Position* _position;
122  component::Movable* movable;
123 
124  bl::rc::lgt::Light2D lantern;
125  float lanternVariance;
126  float lanternTargetVariance;
127  union {
130  };
131 
132  player::State data;
133 
134  virtual void observe(const event::GameSaveInitializing& save) override;
135  virtual void observe(const event::EntityMoveFinished& ent) override;
136 
137  void updateLantern(float dt);
138  void startLanternVarianceHold();
139  void startLanternVarianceChange();
140 
141  virtual void init(bl::engine::Engine&) override;
142  virtual void update(std::mutex&, float dt, float, float, float) override;
143 
144  friend struct bl::serial::SerializableObject<Player>;
145 };
146 
147 } // namespace system
148 } // namespace core
149 
150 #endif
Gender
Possible genders for the player.
Definition: Gender.hpp:24
Core classes and functionality for both the editor and game.
Adding this component to an entity will allow it to move.
Definition: Movable.hpp:26
Fired when an entity completes a move from one tile to another.
Definition: EntityMoved.hpp:52
Fired when the game is saving or loading. Allows systems to hook in their data.
Definition: GameSave.hpp:22
The primary map class that represents a usable map in the game.
Definition: Map.hpp:49
Stores all player state.
Definition: State.hpp:21
Primary system for managing the player and their data.
Definition: Player.hpp:35
float varianceConvergeRate
Definition: Player.hpp:128
float varianceSwitchTime
Definition: Player.hpp:129
void showLantern()
Creates a light for the player's lantern. Keeps it updated as well.
Definition: Player.cpp:106
player::State & state()
Returns the state of the player.
Definition: Player.cpp:154
Player(Systems &owner)
Construct a new Player system.
Definition: Player.cpp:29
void newGame(const std::string &name, player::Gender gender)
Initializes all player data structures for a new game.
Definition: Player.cpp:59
const bl::tmap::Position & position() const
Returns the current position of the player.
Definition: Player.cpp:57
virtual ~Player()=default
Destroys the system.
void whiteout()
Heals all Peoplemon and respawns at the last PC center.
Definition: Player.cpp:97
void removePlayerControlled(bl::ecs::Entity entity)
Removes the PlayerControlled component from the given entity, if any.
Definition: Player.cpp:91
bool spawnPlayer(const bl::tmap::Position &position, map::Map &map)
Spawns the player into the world.
Definition: Player.cpp:32
bl::ecs::Entity player() const
Returns the id of the player entity.
Definition: Player.cpp:55
bool makePlayerControlled(bl::ecs::Entity entity)
Makes the given entity controlled by the player. Only one entity may be player controlled at a time.
Definition: Player.cpp:76
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47