feat(entities): fase 4 - moviment de la momia amb col·lisió, z-order per peus i contacte amb el jugador
This commit is contained in:
1 parent
e6b612d164
commit
ee8dc25181
17 files changed
+378
-66
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
#include "game/map/map.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -42,6 +43,23 @@ RollingRock::RollingRock(const fkyaml::node& yaml) {
|
||||
applyInitialDirection(initial, *this);
|
||||
}
|
||||
|
||||
void RollingRock::step(float delta_time) {
|
||||
const float DX = dir_x_ * speed_ * delta_time;
|
||||
const float DY = dir_y_ * speed_ * delta_time;
|
||||
if (DX == 0.0F && DY == 0.0F) { return; }
|
||||
|
||||
auto candidate = getCollisionRect();
|
||||
candidate.x += DX;
|
||||
candidate.y += DY;
|
||||
if (Map::insidePlayfield(candidate) && !Map::collides(candidate)) {
|
||||
pixel_rect_.x += DX;
|
||||
pixel_rect_.y += DY;
|
||||
return;
|
||||
}
|
||||
// Bloqueig: aturada definitiva (la roca no rebota).
|
||||
setDirection(0.0F, 0.0F);
|
||||
}
|
||||
|
||||
void RollingRock::onPlayerContact(Player* /*player*/) {
|
||||
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user