added stars to gameplay grid
This commit is contained in:
@ -137,16 +137,16 @@ void Starfield3D::update(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void Starfield3D::drawStar(SDL_Renderer* renderer, float x, float y, int type) {
|
||||
const SDL_Color& color = STAR_COLORS[type % COLOR_COUNT];
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||
void Starfield3D::drawStar(SDL_Renderer* renderer, float x, float y, SDL_Color color, float alphaScale) {
|
||||
Uint8 alpha = static_cast<Uint8>(std::clamp(color.a * alphaScale, 0.0f, 255.0f));
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
||||
|
||||
// Draw star as a small rectangle (1x1 pixel)
|
||||
SDL_FRect rect{x, y, 1.0f, 1.0f};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
void Starfield3D::draw(SDL_Renderer* renderer) {
|
||||
void Starfield3D::draw(SDL_Renderer* renderer, float offsetX, float offsetY, float alphaScale, bool grayscale) {
|
||||
for (const Star3D& star : stars) {
|
||||
// Calculate perspective projection factor
|
||||
const float k = DEPTH_FACTOR / star.z;
|
||||
@ -158,7 +158,12 @@ void Starfield3D::draw(SDL_Renderer* renderer) {
|
||||
// Only draw stars that are within the viewport
|
||||
if (px >= 0.0f && px <= static_cast<float>(width) &&
|
||||
py >= 0.0f && py <= static_cast<float>(height)) {
|
||||
drawStar(renderer, px, py, star.type);
|
||||
SDL_Color baseColor = STAR_COLORS[star.type % COLOR_COUNT];
|
||||
if (grayscale) {
|
||||
Uint8 gray = static_cast<Uint8>(0.299f * baseColor.r + 0.587f * baseColor.g + 0.114f * baseColor.b);
|
||||
baseColor.r = baseColor.g = baseColor.b = gray;
|
||||
}
|
||||
drawStar(renderer, px + offsetX, py + offsetY, baseColor, alphaScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user