3 #include <BLIB/Logging.hpp>
4 #include <BLIB/Util/Random.hpp>
19 constexpr
float LanternRadius = 32.f * 6.f;
20 constexpr
float MaxVariance = 19.f;
21 constexpr
float MaxVarianceHoldtime = 0.22f;
22 constexpr
float VarianceMinConvergeRate = MaxVariance / 0.25f;
23 constexpr
float VarianceMaxConvergeRate = MaxVariance / 0.15f;
24 constexpr glm::vec3 LanternColor(0.94f, 0.94f, 0.05f);
33 playerId = owner.
engine().ecs().createEntity(bl::ecs::Flags::WorldObject);
34 BL_LOG_INFO <<
"New player id: " << playerId;
36 _position = owner.
engine().ecs().addComponent<bl::tmap::Position>(playerId, pos);
66 #ifdef PEOPLEMON_DEBUG
80 BL_LOG_ERROR <<
"Failed to get controllable component handle for " << entity;
85 entity, {owner, *controllable});
95 void Player::init(bl::engine::Engine&) { bl::event::Dispatcher::subscribe(
this); }
102 void Player::update(std::mutex&,
float dt,
float,
float,
float) {
103 if (lantern.isValid()) { updateLantern(dt); }
107 if (!lantern.isValid()) {
108 lanternVariance = 0.f;
109 lanternTargetVariance = 0.f;
112 startLanternVarianceHold();
116 void Player::updateLantern(
float dt) {
119 if (lighting.lightsAreOn()) {
120 if (lanternVariance != lanternTargetVariance) {
121 if (lanternVariance < lanternTargetVariance) {
123 if (lanternVariance >= lanternTargetVariance) { startLanternVarianceHold(); }
127 if (lanternVariance <= lanternTargetVariance) { startLanternVarianceHold(); }
137 lantern.setPosition(lpos);
138 lantern.setRadius(LanternRadius + lanternVariance);
140 else { lantern.removeFromScene(); }
143 void Player::startLanternVarianceHold() {
144 lanternVariance = lanternTargetVariance;
148 void Player::startLanternVarianceChange() {
149 lanternTargetVariance = bl::util::Random::get<float>(-MaxVariance, MaxVariance);
151 bl::util::Random::get<float>(VarianceMinConvergeRate, VarianceMaxConvergeRate);
174 if (ent.
entity == playerId) {
185 if (bl::util::Random::get<int>(0, 1000) < 5) {
192 ppl.holdItem() = pickedUp;
195 " they found on the ground.");
Id
Represents an item in its simplist form.
@ Key
Key items. Covers ids [101, 200].
Gender
Possible genders for the player.
Core classes and functionality for both the editor and game.
bl::serial::json::Serializer< Player > Serializer
Empty component to indicate that an entity cannot be moved through.
Adding this component to an entity allows it to be controlled.
Adding this component to an entity will allow it to move.
Add this component to an entity to make it controlled by player input.
void start()
Activate this listener and receive player input. Does not have effect if already activated but anothe...
static Renderable & createFromFastMoveAnims(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component for movement animations with running.
Fired when an entity completes a move from one tile to another.
const bl::ecs::Entity entity
The entity that moved.
Fired when the game is saving or loading. Allows systems to hook in their data.
file::GameSave & gameSave
Game save being initialized.
struct core::file::GameSave::PlayerDataPointers player
std::unordered_map< pplmn::Id, std::string > * firstSightingLocations
std::array< std::vector< pplmn::StoredPeoplemon >, player::StorageSystem::BoxCount > * storage
std::string * whiteoutMap
unsigned int * whiteoutSpawn
unsigned int * repelSteps
std::unordered_set< std::string > * visitedTowns
std::vector< pplmn::OwnedPeoplemon > * peoplemon
std::unordered_map< pplmn::Id, std::uint32_t > * seenPeoplemon
static Category getCategory(Id item)
Returns the category of the given item.
static const std::string & getName(item::Id item)
Returns the name of the given item.
static const std::vector< Id > & validIds()
Returns the list of valid item ids.
The primary map class that represents a usable map in the game.
LightingSystem & lightingSystem()
Returns a reference to the lighting system in this map.
bl::rc::lgt::Scene2DLighting & getSceneLighting()
Returns the scene lighting for this map. Only valid after enter() is called.
bl::rc::SceneRef getScene()
Returns the scene for this map.
void setupEntityPosition(bl::ecs::Entity entity)
Performs the final setup of the position components for the given entity. Must already have a bl::tma...
void clear()
Removes all items.
unsigned int whiteoutSpawn
std::vector< pplmn::OwnedPeoplemon > peoplemon
void healPeoplemon()
Restores HP and removes all ailments.
std::unordered_set< std::string > visitedTowns
static int PixelsPerTile()
static const std::string & PlayerAnimations(player::Gender gender)
static float CharacterMoveSpeed()
static float FastCharacterMoveSpeed()
void displayMessage(const std::string &message, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Messages are queued in order that they arrive.
float varianceConvergeRate
void showLantern()
Creates a light for the player's lantern. Keeps it updated as well.
player::State & state()
Returns the state of the player.
Player(Systems &owner)
Construct a new Player system.
void newGame(const std::string &name, player::Gender gender)
Initializes all player data structures for a new game.
const bl::tmap::Position & position() const
Returns the current position of the player.
void whiteout()
Heals all Peoplemon and respawns at the last PC center.
void removePlayerControlled(bl::ecs::Entity entity)
Removes the PlayerControlled component from the given entity, if any.
bool spawnPlayer(const bl::tmap::Position &position, map::Map &map)
Spawns the player into the world.
bl::ecs::Entity player() const
Returns the id of the player entity.
bool makePlayerControlled(bl::ecs::Entity entity)
Makes the given entity controlled by the player. Only one entity may be player controlled at a time.
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
HUD & hud()
Returns the HUD.
World & world()
Modifiable accessor for the world system.
void whiteout(const std::string &newMap, int spawnId)
Switches to the new map and resets the last map to empty.
map::Map & activeMap()
Returns a reference to the active map.