updated stars in game play grid
This commit is contained in:
@ -265,6 +265,39 @@ void GameRenderer::renderPlayingState(
|
||||
const float deltaSeconds = std::clamp(static_cast<float>(sparkDeltaMs) / 1000.0f, 0.0f, 0.033f);
|
||||
s_inGridStarfield.update(deltaSeconds);
|
||||
|
||||
bool appliedMagnet = false;
|
||||
if (game) {
|
||||
const Game::Piece& activePiece = game->current();
|
||||
const int pieceType = static_cast<int>(activePiece.type);
|
||||
if (pieceType >= 0 && pieceType < PIECE_COUNT) {
|
||||
float sumLocalX = 0.0f;
|
||||
float sumLocalY = 0.0f;
|
||||
int filledCells = 0;
|
||||
for (int cy = 0; cy < 4; ++cy) {
|
||||
for (int cx = 0; cx < 4; ++cx) {
|
||||
if (!Game::cellFilled(activePiece, cx, cy)) {
|
||||
continue;
|
||||
}
|
||||
sumLocalX += (activePiece.x + cx + 0.5f) * finalBlockSize;
|
||||
sumLocalY += (activePiece.y + cy + 0.5f) * finalBlockSize;
|
||||
++filledCells;
|
||||
}
|
||||
}
|
||||
if (filledCells > 0) {
|
||||
float magnetLocalX = sumLocalX / static_cast<float>(filledCells);
|
||||
float magnetLocalY = sumLocalY / static_cast<float>(filledCells);
|
||||
magnetLocalX = std::clamp(magnetLocalX, 0.0f, GRID_W);
|
||||
magnetLocalY = std::clamp(magnetLocalY, 0.0f, GRID_H);
|
||||
const float magnetStrength = finalBlockSize * 2.2f;
|
||||
s_inGridStarfield.setMagnetTarget(magnetLocalX, magnetLocalY, magnetStrength);
|
||||
appliedMagnet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!appliedMagnet) {
|
||||
s_inGridStarfield.clearMagnetTarget();
|
||||
}
|
||||
|
||||
SDL_BlendMode oldBlend = SDL_BLENDMODE_NONE;
|
||||
SDL_GetRenderDrawBlendMode(renderer, &oldBlend);
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
Reference in New Issue
Block a user