From 1babe31f479dddbdfc13a1b046a7cf367e4299c6 Mon Sep 17 00:00:00 2001 From: Floriansylvain Date: Sun, 28 Dec 2025 18:06:02 +0100 Subject: [PATCH] feat: world class --- src/Game.cpp | 13 ++++++------- src/Game.hpp | 8 ++------ src/World.cpp | 22 ++++++++++++++++++++++ src/World.hpp | 20 ++++++++++++++++++++ 4 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 src/World.cpp create mode 100644 src/World.hpp diff --git a/src/Game.cpp b/src/Game.cpp index 1b9212e..79459b5 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,10 +1,11 @@ #include "Game.hpp" #include "Lighting.hpp" +#include "World.hpp" #include #include #include -Game::Game() : gridLines(WIDTH, HEIGHT, 20.f), player(15.f, sf::Color::Green) { +Game::Game() { window.create(sf::VideoMode({WIDTH, HEIGHT}), "SFML Game"); window.setVerticalSyncEnabled(VSYNC); @@ -58,19 +59,17 @@ void Game::processEvents() { void Game::update(double dt) { debug.update(dt); - player.update(dt, window, worldView); - lighting.update(dt, player.position, walls); + world.update(dt, window, worldView); + lighting.update(dt, world.player.position, world.walls); }; void Game::render() { window.clear(); window.setView(worldView); - gridLines.render(window); - debug.render(window); - player.render(window); - walls.render(window); + world.render(window); lighting.render(window); + debug.render(window); window.display(); }; diff --git a/src/Game.hpp b/src/Game.hpp index 517e7f7..9b4f227 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -8,10 +8,8 @@ #include #include "DebugUI.hpp" -#include "GridLines.hpp" #include "Lighting.hpp" -#include "Player.hpp" -#include "Walls.hpp" +#include "World.hpp" constexpr bool VSYNC = true; constexpr int WIDTH = 1920; @@ -28,10 +26,8 @@ private: sf::RenderWindow window; sf::View worldView; - Player player; + World world; DebugUI debug; - GridLines gridLines; - Walls walls; Lighting lighting; void onResize(); diff --git a/src/World.cpp b/src/World.cpp new file mode 100644 index 0000000..0b1245a --- /dev/null +++ b/src/World.cpp @@ -0,0 +1,22 @@ +#include "World.hpp" +#include "Game.hpp" +#include "GridLines.hpp" +#include "Player.hpp" +#include "Walls.hpp" + +World::World() + : player(15.f, sf::Color::Green), gridLines(WIDTH, HEIGHT, 20.f), + walls() {}; + +World::World(Player player, GridLines grid, Walls walls) + : player(player), gridLines(grid), walls(walls) {} + +void World::update(double dt, sf::RenderWindow &window, const sf::View &view) { + player.update(dt, window, view); +} + +void World::render(sf::RenderWindow &window) { + gridLines.render(window); + player.render(window); + walls.render(window); +} diff --git a/src/World.hpp b/src/World.hpp new file mode 100644 index 0000000..72fd66d --- /dev/null +++ b/src/World.hpp @@ -0,0 +1,20 @@ +#ifndef WORLD_HPP +#define WORLD_HPP + +#include "GridLines.hpp" +#include "Player.hpp" +#include "Walls.hpp" + +struct World { + World(); + World(Player player, GridLines gridLines, Walls walls); + + Player player; + GridLines gridLines; + Walls walls; + + void update(double dt, sf::RenderWindow &window, const sf::View &view); + void render(sf::RenderWindow &window); +}; + +#endif // WORLD_HPP