used tileset sprite sheet for asteroids
This commit is contained in:
@ -282,6 +282,62 @@ void GameRenderer::drawRect(SDL_Renderer* renderer, float x, float y, float w, f
|
||||
SDL_RenderFillRect(renderer, &fr);
|
||||
}
|
||||
|
||||
static void drawAsteroid(SDL_Renderer* renderer, SDL_Texture* asteroidTex, float x, float y, float size, const AsteroidCell& cell) {
|
||||
auto outlineGravity = [&](float inset, SDL_Color color) {
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_FRect glow{ x + inset, y + inset, size - inset * 2.0f, size - inset * 2.0f };
|
||||
SDL_RenderRect(renderer, &glow);
|
||||
};
|
||||
|
||||
if (asteroidTex) {
|
||||
const float SPRITE_SIZE = 90.0f;
|
||||
int col = 0;
|
||||
switch (cell.type) {
|
||||
case AsteroidType::Normal: col = 0; break;
|
||||
case AsteroidType::Armored: col = 1; break;
|
||||
case AsteroidType::Falling: col = 2; break;
|
||||
case AsteroidType::Core: col = 3; break;
|
||||
}
|
||||
int row = std::clamp<int>(cell.visualState, 0, 2);
|
||||
SDL_FRect src{ col * SPRITE_SIZE, row * SPRITE_SIZE, SPRITE_SIZE, SPRITE_SIZE };
|
||||
SDL_FRect dst{ x, y, size, size };
|
||||
SDL_RenderTexture(renderer, asteroidTex, &src, &dst);
|
||||
|
||||
if (cell.gravityEnabled) {
|
||||
outlineGravity(2.0f, SDL_Color{255, 230, 120, 180});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: draw a colored quad (previous implementation)
|
||||
SDL_Color base{};
|
||||
switch (cell.type) {
|
||||
case AsteroidType::Normal: base = SDL_Color{172, 138, 104, 255}; break;
|
||||
case AsteroidType::Armored: base = SDL_Color{130, 150, 176, 255}; break;
|
||||
case AsteroidType::Falling: base = SDL_Color{210, 120, 82, 255}; break;
|
||||
case AsteroidType::Core: base = SDL_Color{198, 78, 200, 255}; break;
|
||||
}
|
||||
float hpScale = std::clamp(static_cast<float>(cell.hitsRemaining) / 3.0f, 0.25f, 1.0f);
|
||||
SDL_Color fill{
|
||||
static_cast<Uint8>(base.r * hpScale + 40 * (1.0f - hpScale)),
|
||||
static_cast<Uint8>(base.g * hpScale + 40 * (1.0f - hpScale)),
|
||||
static_cast<Uint8>(base.b * hpScale + 40 * (1.0f - hpScale)),
|
||||
255
|
||||
};
|
||||
SDL_SetRenderDrawColor(renderer, fill.r, fill.g, fill.b, fill.a);
|
||||
SDL_FRect body{x, y, size - 1.0f, size - 1.0f};
|
||||
SDL_RenderFillRect(renderer, &body);
|
||||
|
||||
SDL_Color outline = base;
|
||||
outline.a = 220;
|
||||
SDL_FRect border{x + 1.0f, y + 1.0f, size - 2.0f, size - 2.0f};
|
||||
SDL_SetRenderDrawColor(renderer, outline.r, outline.g, outline.b, outline.a);
|
||||
SDL_RenderRect(renderer, &border);
|
||||
if (cell.gravityEnabled) {
|
||||
outlineGravity(2.0f, SDL_Color{255, 230, 120, 180});
|
||||
}
|
||||
}
|
||||
|
||||
void GameRenderer::drawBlockTexture(SDL_Renderer* renderer, SDL_Texture* blocksTex, float x, float y, float size, int blockType) {
|
||||
if (!blocksTex || blockType < 0 || blockType >= PIECE_COUNT) {
|
||||
// Fallback to colored rectangle if texture isn't available
|
||||
@ -515,6 +571,7 @@ void GameRenderer::renderPlayingState(
|
||||
FontAtlas* pixelFont,
|
||||
LineEffect* lineEffect,
|
||||
SDL_Texture* blocksTex,
|
||||
SDL_Texture* asteroidsTex,
|
||||
SDL_Texture* statisticsPanelTex,
|
||||
SDL_Texture* scorePanelTex,
|
||||
SDL_Texture* nextPanelTex,
|
||||
@ -960,32 +1017,7 @@ void GameRenderer::renderPlayingState(
|
||||
bool isAsteroid = challengeMode && asteroidCells[cellIdx].has_value();
|
||||
if (isAsteroid) {
|
||||
const AsteroidCell& cell = *asteroidCells[cellIdx];
|
||||
SDL_Color base{};
|
||||
switch (cell.type) {
|
||||
case AsteroidType::Normal: base = SDL_Color{172, 138, 104, 255}; break;
|
||||
case AsteroidType::Armored: base = SDL_Color{130, 150, 176, 255}; break;
|
||||
case AsteroidType::Falling: base = SDL_Color{210, 120, 82, 255}; break;
|
||||
case AsteroidType::Core: base = SDL_Color{198, 78, 200, 255}; break;
|
||||
}
|
||||
float hpScale = std::clamp(static_cast<float>(cell.hitsRemaining) / 3.0f, 0.25f, 1.0f);
|
||||
SDL_Color fill{
|
||||
static_cast<Uint8>(base.r * hpScale + 40 * (1.0f - hpScale)),
|
||||
static_cast<Uint8>(base.g * hpScale + 40 * (1.0f - hpScale)),
|
||||
static_cast<Uint8>(base.b * hpScale + 40 * (1.0f - hpScale)),
|
||||
255
|
||||
};
|
||||
drawRect(renderer, bx, by, finalBlockSize - 1, finalBlockSize - 1, fill);
|
||||
// Subtle outline to differentiate types
|
||||
SDL_Color outline = base;
|
||||
outline.a = 220;
|
||||
SDL_FRect border{bx + 1.0f, by + 1.0f, finalBlockSize - 2.0f, finalBlockSize - 2.0f};
|
||||
SDL_SetRenderDrawColor(renderer, outline.r, outline.g, outline.b, outline.a);
|
||||
SDL_RenderRect(renderer, &border);
|
||||
if (cell.gravityEnabled) {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 230, 120, 180);
|
||||
SDL_FRect glow{bx + 2.0f, by + 2.0f, finalBlockSize - 4.0f, finalBlockSize - 4.0f};
|
||||
SDL_RenderRect(renderer, &glow);
|
||||
}
|
||||
drawAsteroid(renderer, asteroidsTex, bx, by, finalBlockSize, cell);
|
||||
} else {
|
||||
drawBlockTexture(renderer, blocksTex, bx, by, finalBlockSize, v - 1);
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ public:
|
||||
FontAtlas* pixelFont,
|
||||
LineEffect* lineEffect,
|
||||
SDL_Texture* blocksTex,
|
||||
SDL_Texture* asteroidsTex,
|
||||
SDL_Texture* statisticsPanelTex,
|
||||
SDL_Texture* scorePanelTex,
|
||||
SDL_Texture* nextPanelTex,
|
||||
|
||||
Reference in New Issue
Block a user