Updated game speed
This commit is contained in:
52
src/states/PlayingState.cpp
Normal file
52
src/states/PlayingState.cpp
Normal 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.
|
||||
}
|
||||
Reference in New Issue
Block a user