Updated game structure
Some checks failed
Build and Package Tetris / build-windows (push) Has been cancelled
Build and Package Tetris / build-linux (push) Has been cancelled

This commit is contained in:
2025-08-16 12:10:19 +02:00
parent 71648fbaeb
commit 2afaea7fd3
36 changed files with 665 additions and 382 deletions

View File

@ -1,6 +1,6 @@
// LoadingState.cpp
#include "LoadingState.h"
#include "../Game.h"
#include "gameplay/Game.h"
#include <SDL3/SDL.h>
#include <cstdio>

View File

@ -1,7 +1,7 @@
// MenuState.cpp
#include "MenuState.h"
#include "../Scores.h"
#include "../Font.h"
#include "persistence/Scores.h"
#include "graphics/Font.h"
#include <SDL3/SDL.h>
#include <cstdio>
#include <algorithm>
@ -11,25 +11,11 @@
static constexpr int LOGICAL_W = 1200;
static constexpr int LOGICAL_H = 1000;
extern bool showLevelPopup; // from main
extern bool showSettingsPopup; // from main
extern bool musicEnabled; // from main
extern int hoveredButton; // from main
// Call wrappers defined in main.cpp
extern void menu_drawFireworks(SDL_Renderer* renderer);
extern void menu_updateFireworks(double frameMs);
extern double menu_getLogoAnimCounter();
extern int menu_getHoveredButton();
extern void menu_drawEnhancedButton(SDL_Renderer* renderer, FontAtlas& font, float cx, float cy, float w, float h,
const std::string& label, bool isHovered, bool isSelected);
// Menu button wrapper implemented in main.cpp
extern void menu_drawMenuButton(SDL_Renderer* renderer, FontAtlas& font, float cx, float cy, float w, float h,
const std::string& label, SDL_Color bgColor, SDL_Color borderColor);
// wrappers for popups (defined in main.cpp)
extern void menu_drawLevelSelectionPopup(SDL_Renderer* renderer, FontAtlas& font, SDL_Texture* bgTex, int selectedLevel);
extern void menu_drawSettingsPopup(SDL_Renderer* renderer, FontAtlas& font, bool musicEnabled);
// Shared flags and resources are provided via StateContext `ctx`.
// Removed fragile extern declarations and use `ctx.showLevelPopup`, `ctx.showSettingsPopup`,
// `ctx.musicEnabled` and `ctx.hoveredButton` instead to avoid globals.
// Menu helper wrappers are declared in a shared header implemented in main.cpp
#include "../audio/MenuWrappers.h"
MenuState::MenuState(StateContext& ctx) : State(ctx) {}
@ -79,7 +65,7 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
}
// Fireworks (draw above high scores / near buttons)
menu_drawFireworks(renderer);
menu_drawFireworks(renderer, ctx.blocksTex);
// Score list and top players with a sine-wave vertical animation (use pixelFont for retro look)
float topPlayersY = LOGICAL_H * 0.30f + contentOffsetY; // more top padding

View File

@ -1,7 +1,7 @@
#include "PlayingState.h"
#include "../Game.h"
#include "../LineEffect.h"
#include "../Scores.h"
#include "gameplay/Game.h"
#include "gameplay/LineEffect.h"
#include "persistence/Scores.h"
#include <SDL3/SDL.h>
PlayingState::PlayingState(StateContext& ctx) : State(ctx) {}

View File

@ -29,6 +29,8 @@ struct StateContext {
int logoSmallW = 0;
int logoSmallH = 0;
SDL_Texture* backgroundTex = nullptr;
// backgroundTex is set once in `main.cpp` and passed to states via this context.
// Prefer reading this field instead of relying on any `extern SDL_Texture*` globals.
SDL_Texture* blocksTex = nullptr;
// Audio / SFX - forward declared types in main