Updated game speed

This commit is contained in:
2025-08-16 08:24:26 +02:00
parent d161b2c550
commit 71648fbaeb
20 changed files with 690 additions and 334 deletions

View File

@ -0,0 +1,52 @@
#include "PlayingState.h"
#include "../Game.h"
#include "../LineEffect.h"
#include "../Scores.h"
#include <SDL3/SDL.h>
PlayingState::PlayingState(StateContext& ctx) : State(ctx) {}
void PlayingState::onEnter() {
// Nothing yet; main still owns game creation
}
void PlayingState::onExit() {
}
void PlayingState::handleEvent(const SDL_Event& e) {
// We keep short-circuited input here; main still handles mouse UI
if (e.type == SDL_EVENT_KEY_DOWN && !e.key.repeat) {
if (!ctx.game) return;
// Pause toggle (P)
if (e.key.scancode == SDL_SCANCODE_P) {
bool paused = ctx.game->isPaused();
ctx.game->setPaused(!paused);
}
// Other gameplay keys already registered by main's Playing handler for now
}
}
void PlayingState::update(double frameMs) {
if (!ctx.game) return;
// forward per-frame gameplay updates (gravity, elapsed)
if (!ctx.game->isPaused()) {
ctx.game->tickGravity(frameMs);
ctx.game->addElapsed(frameMs);
if (ctx.lineEffect && ctx.lineEffect->isActive()) {
if (ctx.lineEffect->update(frameMs / 1000.0f)) {
ctx.game->clearCompletedLines();
}
}
}
if (ctx.game->isGameOver()) {
if (ctx.scores) ctx.scores->submit(ctx.game->score(), ctx.game->lines(), ctx.game->level(), ctx.game->elapsed());
// Transitioning state must be done by the owner (main via StateManager hooks). We can't set state here.
}
}
void PlayingState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) {
if (!ctx.game) return;
// Rendering kept in main for now to avoid changing many layout calculations in one change.
}