some problems fixed
This commit is contained in:
@ -3,12 +3,18 @@
|
||||
#include "gameplay/Game.h"
|
||||
#include "gameplay/LineEffect.h"
|
||||
#include "persistence/Scores.h"
|
||||
#include "../audio/Audio.h"
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
PlayingState::PlayingState(StateContext& ctx) : State(ctx) {}
|
||||
|
||||
void PlayingState::onEnter() {
|
||||
// Nothing yet; main still owns game creation
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[PLAYING] Entering Playing state");
|
||||
// Initialize the game with the selected starting level
|
||||
if (ctx.game && ctx.startLevelSelection) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[PLAYING] Resetting game with level %d", *ctx.startLevelSelection);
|
||||
ctx.game->reset(*ctx.startLevelSelection);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayingState::onExit() {
|
||||
@ -54,12 +60,40 @@ void PlayingState::handleEvent(const SDL_Event& e) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Other gameplay keys already registered by main's Playing handler for now
|
||||
// Tetris controls (only when not paused)
|
||||
if (!ctx.game->isPaused()) {
|
||||
// Rotation (still event-based for precise timing)
|
||||
if (e.key.scancode == SDL_SCANCODE_UP || e.key.scancode == SDL_SCANCODE_W ||
|
||||
e.key.scancode == SDL_SCANCODE_Z) {
|
||||
ctx.game->rotate(1); // Clockwise rotation
|
||||
return;
|
||||
}
|
||||
if (e.key.scancode == SDL_SCANCODE_X) {
|
||||
ctx.game->rotate(-1); // Counter-clockwise rotation
|
||||
return;
|
||||
}
|
||||
|
||||
// Hard drop (space)
|
||||
if (e.key.scancode == SDL_SCANCODE_SPACE) {
|
||||
ctx.game->hardDrop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: Left/Right movement and soft drop are now handled by
|
||||
// ApplicationManager's update handler for proper DAS/ARR timing
|
||||
}
|
||||
|
||||
void PlayingState::update(double frameMs) {
|
||||
if (!ctx.game) return;
|
||||
|
||||
static bool debugPrinted = false;
|
||||
if (!debugPrinted) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[PLAYING] Starting updates, frameMs=%.2f, paused=%d", frameMs, ctx.game->isPaused());
|
||||
debugPrinted = true;
|
||||
}
|
||||
|
||||
// forward per-frame gameplay updates (gravity, elapsed)
|
||||
if (!ctx.game->isPaused()) {
|
||||
ctx.game->tickGravity(frameMs);
|
||||
@ -71,11 +105,8 @@ void PlayingState::update(double frameMs) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
}
|
||||
|
||||
// Note: Game over detection and state transition is now handled by ApplicationManager
|
||||
}
|
||||
|
||||
void PlayingState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) {
|
||||
|
||||
Reference in New Issue
Block a user