change to physics based ship movement

This commit is contained in:
2026-05-19 21:53:55 +02:00
parent d397b9969a
commit 34c6dea505
10 changed files with 183 additions and 44 deletions

View File

@@ -93,13 +93,15 @@ TEST_CASE("BehaviorSystem: clearMovementIntents resets all ships to priority 0",
// tickMovement
// ---------------------------------------------------------------------------
TEST_CASE("BehaviorSystem: tickMovement advances ship by speedPerTick toward target",
// With facing=0 and target due east, main thrust drives the ship east. The test
// config uses very high thrust so the ship reaches maxSpeedPerTick in one tick.
TEST_CASE("BehaviorSystem: tickMovement advances ship by maxSpeedPerTick toward target",
"[behavior]")
{
Fixture f;
const EntityId id = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const float speed = f.ships.findShip(id)->speedPerTick;
const float speed = f.ships.findShip(id)->maxSpeedPerTick;
const QVector2D target(100.0f, 0.0f);
f.ships.forEach([&target](Ship& s) {
@@ -112,6 +114,8 @@ TEST_CASE("BehaviorSystem: tickMovement advances ship by speedPerTick toward tar
REQUIRE(s->position.y() == Approx(0.0f));
}
// With very high maneuvering thrust the stopping distance is ~0, so desiredSpeed
// still exceeds maxSpeedPerTick and the snap-to-target branch fires.
TEST_CASE("BehaviorSystem: tickMovement stops exactly at target without overshoot",
"[behavior]")
{
@@ -119,7 +123,7 @@ TEST_CASE("BehaviorSystem: tickMovement stops exactly at target without overshoo
const EntityId id = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
// Place target closer than one tick's travel.
const float speed = f.ships.findShip(id)->speedPerTick;
const float speed = f.ships.findShip(id)->maxSpeedPerTick;
const QVector2D target(speed * 0.5f, 0.0f);
f.ships.forEach([&target](Ship& s) {

View File

@@ -77,7 +77,7 @@ TEST_CASE("ShipSystem: interceptor level 5 hp matches formula", "[ship]")
REQUIRE(ship->maxHp == Approx(65.0f));
}
TEST_CASE("ShipSystem: interceptor level 0 speedPerTick matches formula / kTickRateHz", "[ship]")
TEST_CASE("ShipSystem: interceptor level 0 maxSpeedPerTick matches formula / kTickRateHz", "[ship]")
{
const GameConfig cfg = loadConfig();
EntityId nextId = 1;
@@ -86,9 +86,9 @@ TEST_CASE("ShipSystem: interceptor level 0 speedPerTick matches formula / kTickR
const EntityId id = ss.spawn("interceptor", 0, QVector2D(0.0f, 0.0f));
const Ship* ship = ss.findShip(id);
// speed_formula = "200 + 5*x" at x=0 → 200; speedPerTick = 200/30
// speed_formula = "200 + 5*x" at x=0 → 200; maxSpeedPerTick = 200/30
const float expected = 200.0f / static_cast<float>(kTickRateHz);
REQUIRE(ship->speedPerTick == Approx(expected));
REQUIRE(ship->maxSpeedPerTick == Approx(expected));
}
// ---------------------------------------------------------------------------