This commit is contained in:
2025-12-06 17:51:54 +01:00
parent f086ed3021
commit 12110bd8b4
4 changed files with 124 additions and 22 deletions

View File

@ -105,10 +105,22 @@ void SpaceWarp::spawnComet() {
float shade = randomRange(0.85f, 1.0f);
Uint8 c = static_cast<Uint8>(std::clamp(220.0f + shade * 35.0f, 0.0f, 255.0f));
comet.color = SDL_Color{c, Uint8(std::min(255.0f, c * 0.95f)), 255, 255};
comet.prevScreenX = centerX;
comet.prevScreenY = centerY;
comet.screenX = centerX;
comet.screenY = centerY;
// Initialize screen positions based on projection so the comet is not stuck at center
float sx = 0.0f, sy = 0.0f;
if (projectPoint(comet.x, comet.y, comet.z, sx, sy)) {
comet.screenX = sx;
comet.screenY = sy;
// Place prev slightly behind the head so the first frame shows motion/trail
float jitter = std::max(4.0f, comet.trailLength * 0.08f);
float ang = randomRange(0.0f, 6.28318530718f);
comet.prevScreenX = comet.screenX - std::cos(ang) * jitter;
comet.prevScreenY = comet.screenY - std::sin(ang) * jitter;
} else {
comet.prevScreenX = centerX;
comet.prevScreenY = centerY;
comet.screenX = centerX;
comet.screenY = centerY;
}
comets.push_back(comet);
}
@ -135,10 +147,22 @@ void SpaceWarp::respawn(WarpStar& star, bool randomDepth) {
static constexpr Uint8 GRAY_SHADES[] = {160, 180, 200, 220, 240};
int idx = randomIntInclusive(rng, 0, int(std::size(GRAY_SHADES)) - 1);
star.baseShade = GRAY_SHADES[idx];
star.prevScreenX = centerX;
star.prevScreenY = centerY;
star.screenX = centerX;
star.screenY = centerY;
// Compute initial projected screen position so newly spawned stars aren't frozen at center
float sx = 0.0f, sy = 0.0f;
if (projectPoint(star.x, star.y, star.z, sx, sy)) {
star.screenX = sx;
star.screenY = sy;
// give a small previous offset so trails and motion are visible immediately
float jitter = std::max(1.0f, settings.maxTrailLength * 0.06f);
float ang = randomRange(0.0f, 6.28318530718f);
star.prevScreenX = star.screenX - std::cos(ang) * jitter;
star.prevScreenY = star.screenY - std::sin(ang) * jitter;
} else {
star.prevScreenX = centerX;
star.prevScreenY = centerY;
star.screenX = centerX;
star.screenY = centerY;
}
}
bool SpaceWarp::project(const WarpStar& star, float& outX, float& outY) const {