feat: walls for future ray cast

This commit is contained in:
Floriansylvain
2025-12-28 04:18:53 +01:00
parent 683096351f
commit 62655038f3
6 changed files with 64 additions and 7 deletions
+12
View File
@@ -10,6 +10,17 @@ Game::Game() : gridLines(WIDTH, HEIGHT, 20.f), player(15.f, sf::Color::Green) {
worldView.setSize({(float)WIDTH, (float)HEIGHT});
worldView.setCenter({(float)WIDTH / 2.f, (float)HEIGHT / 2.f});
walls.add({1.f, 1.f}, {WIDTH - 1.f, 1.f});
walls.add({1.f, 1.f}, {1.f, HEIGHT - 1.f});
walls.add({WIDTH - 1.f, 1.f}, {WIDTH - 1.f, HEIGHT - 1.f});
walls.add({1.f, HEIGHT - 1.f}, {WIDTH - 1.f, HEIGHT - 1.f});
walls.add({1000.f, 500.f}, {1500.f, 500.f});
walls.add({500.f, 240.f}, {500.f, 760.f});
walls.add({420.f, 240.f}, {420.f, 760.f});
walls.add({420.f, 240.f}, {500.f, 240.f});
walls.add({420.f, 760.f}, {500.f, 760.f});
}
void Game::run() {
@@ -64,6 +75,7 @@ void Game::render() {
gridLines.render(window);
debug.render(window);
player.render(window);
walls.render(window);
window.display();
};
+2
View File
@@ -6,6 +6,7 @@
#include "DebugUI.hpp"
#include "GridLines.hpp"
#include "Player.hpp"
#include "Walls.hpp"
constexpr bool VSYNC = true;
constexpr int WIDTH = 1920;
@@ -25,6 +26,7 @@ private:
Player player;
DebugUI debug;
GridLines gridLines;
Walls walls;
void onResize();
void processEvents();
+6 -6
View File
@@ -2,18 +2,18 @@
#include <SFML/Graphics/Vertex.hpp>
GridLines::GridLines(float width, float height, float spacing)
: m_lines(sf::PrimitiveType::Lines) {
: lines(sf::PrimitiveType::Lines) {
sf::Color gray(64, 64, 64);
for (float x = 0; x <= width; x += spacing) {
m_lines.append({{x, 0.f}, gray});
m_lines.append({{x, height}, gray});
lines.append({{x, 0.f}, gray});
lines.append({{x, height}, gray});
}
for (float y = 0; y <= height; y += spacing) {
m_lines.append({{0.f, y}, gray});
m_lines.append({{width, y}, gray});
lines.append({{0.f, y}, gray});
lines.append({{width, y}, gray});
}
}
void GridLines::render(sf::RenderWindow &window) const { window.draw(m_lines); }
void GridLines::render(sf::RenderWindow &window) const { window.draw(lines); }
+1 -1
View File
@@ -11,7 +11,7 @@ public:
void render(sf::RenderWindow &window) const;
private:
sf::VertexArray m_lines;
sf::VertexArray lines;
};
#endif // GRIDLINES_HPP
+14
View File
@@ -0,0 +1,14 @@
#include "Walls.hpp"
#include <SFML/Graphics/Vertex.hpp>
Walls::Walls() : walls(sf::PrimitiveType::Lines) {};
void Walls::add(sf::Vector2f pointA, sf::Vector2f pointB) {
walls.append({pointA, sf::Color::Red});
walls.append({pointB, sf::Color::Red});
vertices.emplace_back(Wall{pointA, pointB});
};
std::vector<Wall> Walls::get() { return vertices; };
void Walls::render(sf::RenderWindow &window) { window.draw(walls); };
+29
View File
@@ -0,0 +1,29 @@
#ifndef WALLS_HPP
#define WALLS_HPP
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/System/Vector2.hpp>
#include <vector>
struct Wall {
sf::Vector2f start;
sf::Vector2f end;
};
class Walls {
public:
Walls();
void add(sf::Vector2f pointA, sf::Vector2f pointB);
std::vector<Wall> get();
void render(sf::RenderWindow &window);
private:
sf::VertexArray walls;
std::vector<Wall> vertices;
};
#endif // WALLS_HPP