Add freeze_in_void property to PhysicsEntity
This commit is contained in:
@@ -19,6 +19,7 @@ namespace CaveGame::Core
|
||||
{
|
||||
class PhysicsEntity : public Entity {
|
||||
public:
|
||||
bool freeze_in_void = true;
|
||||
explicit PhysicsEntity(const Vector2& spawnPoint);
|
||||
|
||||
[[nodiscard]] Vector2 Velocity() const;
|
||||
@@ -45,7 +46,18 @@ namespace CaveGame::Core
|
||||
|
||||
TileID id = map->GetTile(tileBoxPos.x, tileBoxPos.y);
|
||||
|
||||
if (id == TileID::VOID || id == TileID::AIR)
|
||||
if (id == TileID::VOID) {
|
||||
if (freeze_in_void)
|
||||
{
|
||||
velocity = {0,0};
|
||||
next_position = position;
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (id == TileID::AIR)
|
||||
continue;
|
||||
|
||||
coll_tests++;
|
||||
@@ -117,6 +129,11 @@ namespace CaveGame::Core
|
||||
|
||||
void Update(float elapsed) override {
|
||||
|
||||
if (!on_ground)
|
||||
airtime += elapsed;
|
||||
else
|
||||
airtime = 0;
|
||||
|
||||
// TODO: Sophisticated mechanism to maintain locked-timestep, multiple-iteration physics steps.
|
||||
PhysicsUpdate(elapsed);
|
||||
|
||||
|
Reference in New Issue
Block a user