diff --git a/source/core/defaults.hpp b/source/core/defaults.hpp index 3353f94..8f284fb 100644 --- a/source/core/defaults.hpp +++ b/source/core/defaults.hpp @@ -17,6 +17,7 @@ #include "core/defaults/entities.hpp" #include "core/defaults/floating_score.hpp" #include "core/defaults/game.hpp" +#include "core/defaults/grid.hpp" #include "core/defaults/hud.hpp" #include "core/defaults/math.hpp" #include "core/defaults/notifier.hpp" diff --git a/source/core/defaults/grid.hpp b/source/core/defaults/grid.hpp new file mode 100644 index 0000000..4c3097e --- /dev/null +++ b/source/core/defaults/grid.hpp @@ -0,0 +1,12 @@ +// grid.hpp - Configuració de la grilla de fons del playfield +// © 2026 JailDesigner + +#pragma once + +namespace Defaults::Grid { + + constexpr int COLUMNS = 16; // cel·les omplen tota la PLAYAREA: cell_w = w/16 + constexpr int ROWS = 8; // cel·les omplen tota la PLAYAREA: cell_h = h/8 (≈2% més altes que amples) + constexpr float BRIGHTNESS = 0.20F; // intensitat respecte al color global (border = 1.0) + +} // namespace Defaults::Grid diff --git a/source/core/graphics/playfield_grid.cpp b/source/core/graphics/playfield_grid.cpp new file mode 100644 index 0000000..cfe5c4f --- /dev/null +++ b/source/core/graphics/playfield_grid.cpp @@ -0,0 +1,37 @@ +// playfield_grid.cpp - Implementació de la grilla de fons +// © 2026 JailDesigner + +#include "core/graphics/playfield_grid.hpp" + +#include "core/defaults.hpp" +#include "core/rendering/line_renderer.hpp" + +namespace Graphics { + + PlayfieldGrid::PlayfieldGrid(Rendering::Renderer* renderer) + : renderer_(renderer) {} + + void PlayfieldGrid::draw() const { + const SDL_FRect& zona = Defaults::Zones::PLAYAREA; + const float CELL_W = zona.w / static_cast(Defaults::Grid::COLUMNS); + const float CELL_H = zona.h / static_cast(Defaults::Grid::ROWS); + + const int X1 = static_cast(zona.x); + const int Y1 = static_cast(zona.y); + const int X2 = static_cast(zona.x + zona.w); + const int Y2 = static_cast(zona.y + zona.h); + + // Línies verticals interiors (i=1..COLUMNS-1: no repetim el border) + for (int i = 1; i < Defaults::Grid::COLUMNS; i++) { + const int X = static_cast(zona.x + (static_cast(i) * CELL_W)); + Rendering::linea(renderer_, X, Y1, X, Y2, Defaults::Grid::BRIGHTNESS); + } + + // Línies horitzontals interiors (j=1..ROWS-1: no repetim el border) + for (int j = 1; j < Defaults::Grid::ROWS; j++) { + const int Y = static_cast(zona.y + (static_cast(j) * CELL_H)); + Rendering::linea(renderer_, X1, Y, X2, Y, Defaults::Grid::BRIGHTNESS); + } + } + +} // namespace Graphics diff --git a/source/core/graphics/playfield_grid.hpp b/source/core/graphics/playfield_grid.hpp new file mode 100644 index 0000000..fa2a04f --- /dev/null +++ b/source/core/graphics/playfield_grid.hpp @@ -0,0 +1,23 @@ +// playfield_grid.hpp - Grilla de fons del playfield (línies verdes fosques) +// © 2026 JailDesigner + +#pragma once + +#include "core/rendering/render_context.hpp" + +namespace Graphics { + + // Pinta una graella interior dins de Defaults::Zones::PLAYAREA. + // Cel·les quadrades; el nombre de columnes és fix (Defaults::Grid::COLUMNS), + // les files es deriven del que cap dins de l'altura. + // Color: oscil·lador global (mateix to que el border); brightness fixa al 25%. + class PlayfieldGrid { + public: + explicit PlayfieldGrid(Rendering::Renderer* renderer); + void draw() const; + + private: + Rendering::Renderer* renderer_; + }; + +} // namespace Graphics diff --git a/source/game/scenes/game_scene.cpp b/source/game/scenes/game_scene.cpp index e6f9417..26d0a6b 100644 --- a/source/game/scenes/game_scene.cpp +++ b/source/game/scenes/game_scene.cpp @@ -30,7 +30,8 @@ GameScene::GameScene(SDLManager& sdl, SceneContext& context) firework_manager_(sdl.getRenderer()), floating_score_manager_(sdl.getRenderer()), trail_manager_(sdl.getRenderer()), - text_(sdl.getRenderer()) { + text_(sdl.getRenderer()), + playfield_grid_(sdl.getRenderer()) { // Recuperar configuración de match des del context match_config_ = context_.getMatchConfig(); @@ -595,6 +596,7 @@ void GameScene::drawInitHudState() { } void GameScene::drawLevelStartState() { + playfield_grid_.draw(); drawMargins(); trail_manager_.draw(); drawActiveShipsAlive(); @@ -607,6 +609,7 @@ void GameScene::drawLevelStartState() { } void GameScene::drawPlayingState() { + playfield_grid_.draw(); drawMargins(); trail_manager_.draw(); drawActiveShipsAlive(); @@ -619,6 +622,7 @@ void GameScene::drawPlayingState() { } void GameScene::drawLevelCompletedState() { + playfield_grid_.draw(); drawMargins(); trail_manager_.draw(); drawActiveShipsAlive(); diff --git a/source/game/scenes/game_scene.hpp b/source/game/scenes/game_scene.hpp index 6b99b5b..4774e88 100644 --- a/source/game/scenes/game_scene.hpp +++ b/source/game/scenes/game_scene.hpp @@ -8,6 +8,7 @@ #include #include +#include "core/graphics/playfield_grid.hpp" #include "core/graphics/vector_text.hpp" #include "core/physics/physics_world.hpp" #include "core/rendering/sdl_manager.hpp" @@ -80,6 +81,9 @@ class GameScene final : public Scene { // Text vectorial Graphics::VectorText text_; + // Grilla de fons del playfield + Graphics::PlayfieldGrid playfield_grid_; + // [NEW] Stage system std::unique_ptr stage_config_; std::unique_ptr stage_manager_;