mirror of
https://github.com/Floriansylvain/whateversfml.git
synced 2026-08-19 11:43:22 +02:00
feat: world class
This commit is contained in:
+6
-7
@@ -1,10 +1,11 @@
|
||||
#include "Game.hpp"
|
||||
#include "Lighting.hpp"
|
||||
#include "World.hpp"
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
+2
-6
@@ -8,10 +8,8 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
#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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user