14 constexpr
float HopDistance = 64.f;
15 constexpr
float HopHeight = 20.f;
16 constexpr
float MaxHeightPoint = 0.25f;
17 constexpr
float HopUpHeightMult = 1.f / MaxHeightPoint;
18 constexpr
float HopDownHeightMult = 1.f / (1.f - MaxHeightPoint);
19 constexpr
float ShadowSize = 16.f;
20 constexpr
float ShadowShrinkage = 3.f;
22 glm::vec2 getPixels(bl::tmap::Direction dir,
float x,
float y,
float interp) {
24 case bl::tmap::Direction::Up:
25 return {x, y + interp};
26 case bl::tmap::Direction::Right:
27 return {x - interp, y};
28 case bl::tmap::Direction::Down:
29 return {x, y - interp};
30 case bl::tmap::Direction::Left:
32 return {x + interp, y};
39 , movementSpeed(speed)
40 , fastMovementSpeed(fastSpeed)
41 , state(MoveState::Still) {}
49 state = fast ? MoveState::MovingFast : (isHop ? MoveState::LedgeHopping : MoveState::Moving);
54 if (state != MoveState::Still) {
55 if (!position.transform) {
56 BL_LOG_WARN <<
"Entity with movable component missing transform: " << owner;
60 if (state != MoveState::LedgeHopping) {
62 const float speed = state == MoveState::MovingFast ? fastMovementSpeed : movementSpeed;
63 const float displacement = dt * speed;
64 interpRemaining = std::max(interpRemaining - displacement, 0.f);
69 position.transform->setPosition(getPixels(moveDir, xTile, yTile, interpRemaining));
71 if (interpRemaining <= 0.f) {
73 state = MoveState::Still;
74 bl::event::Dispatcher::dispatch<event::EntityMoveFinished>({owner, position});
78 interpRemaining = std::max(interpRemaining - movementSpeed * dt, 0.f);
79 const float percent = 1.f - interpRemaining / HopDistance;
80 const float hp = percent <= MaxHeightPoint ?
81 percent * HopUpHeightMult :
82 1.f - (percent - MaxHeightPoint) * HopDownHeightMult;
83 const float height = HopHeight * hp;
87 systems.
player().
player(), height, ShadowSize - ShadowShrinkage * hp);
92 position.transform->setPosition(xTile, yTile - interpRemaining - height);
95 if (interpRemaining <= 0.f) {
97 state = MoveState::Still;
98 bl::event::Dispatcher::dispatch<event::EntityMoveFinished>({owner, position});
Core classes and functionality for both the editor and game.
bool goingFast() const
Returns whether or not the entity is going fast.
bool moving() const
Returns whether or not the entity is moving.
void update(bl::ecs::Entity owner, system::Systems &systems, float dt)
Updates the interpolation of the entity if moving.
Movable(bl::tmap::Position &pos, float speed, float fastSpeed)
Construct a new Movable component.
void move(bl::tmap::Direction dir, bool fast, bool isLedgeHop)
Starts the entity moving in the given direction. Only updates the interpolated position,...
static int PixelsPerTile()
bl::ecs::Entity player() const
Returns the id of the player entity.
void removeShadow(bl::ecs::Entity entity)
Removes the shadow from the given entity.
void updateShadow(bl::ecs::Entity entity, float distance, float radius)
Adds or updates the shadow of the given entity.
Owns all primary systems and a reference to the engine.
Render & render()
Returns the render system.
Player & player()
Returns the player system.