mirror of
https://github.com/Floriansylvain/whateversfml.git
synced 2026-08-19 11:43:22 +02:00
feat: walls for future ray cast
This commit is contained in:
@@ -10,6 +10,17 @@ Game::Game() : gridLines(WIDTH, HEIGHT, 20.f), player(15.f, sf::Color::Green) {
|
|||||||
|
|
||||||
worldView.setSize({(float)WIDTH, (float)HEIGHT});
|
worldView.setSize({(float)WIDTH, (float)HEIGHT});
|
||||||
worldView.setCenter({(float)WIDTH / 2.f, (float)HEIGHT / 2.f});
|
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() {
|
void Game::run() {
|
||||||
@@ -64,6 +75,7 @@ void Game::render() {
|
|||||||
gridLines.render(window);
|
gridLines.render(window);
|
||||||
debug.render(window);
|
debug.render(window);
|
||||||
player.render(window);
|
player.render(window);
|
||||||
|
walls.render(window);
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "DebugUI.hpp"
|
#include "DebugUI.hpp"
|
||||||
#include "GridLines.hpp"
|
#include "GridLines.hpp"
|
||||||
#include "Player.hpp"
|
#include "Player.hpp"
|
||||||
|
#include "Walls.hpp"
|
||||||
|
|
||||||
constexpr bool VSYNC = true;
|
constexpr bool VSYNC = true;
|
||||||
constexpr int WIDTH = 1920;
|
constexpr int WIDTH = 1920;
|
||||||
@@ -25,6 +26,7 @@ private:
|
|||||||
Player player;
|
Player player;
|
||||||
DebugUI debug;
|
DebugUI debug;
|
||||||
GridLines gridLines;
|
GridLines gridLines;
|
||||||
|
Walls walls;
|
||||||
|
|
||||||
void onResize();
|
void onResize();
|
||||||
void processEvents();
|
void processEvents();
|
||||||
|
|||||||
+6
-6
@@ -2,18 +2,18 @@
|
|||||||
#include <SFML/Graphics/Vertex.hpp>
|
#include <SFML/Graphics/Vertex.hpp>
|
||||||
|
|
||||||
GridLines::GridLines(float width, float height, float spacing)
|
GridLines::GridLines(float width, float height, float spacing)
|
||||||
: m_lines(sf::PrimitiveType::Lines) {
|
: lines(sf::PrimitiveType::Lines) {
|
||||||
sf::Color gray(64, 64, 64);
|
sf::Color gray(64, 64, 64);
|
||||||
|
|
||||||
for (float x = 0; x <= width; x += spacing) {
|
for (float x = 0; x <= width; x += spacing) {
|
||||||
m_lines.append({{x, 0.f}, gray});
|
lines.append({{x, 0.f}, gray});
|
||||||
m_lines.append({{x, height}, gray});
|
lines.append({{x, height}, gray});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (float y = 0; y <= height; y += spacing) {
|
for (float y = 0; y <= height; y += spacing) {
|
||||||
m_lines.append({{0.f, y}, gray});
|
lines.append({{0.f, y}, gray});
|
||||||
m_lines.append({{width, 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
@@ -11,7 +11,7 @@ public:
|
|||||||
void render(sf::RenderWindow &window) const;
|
void render(sf::RenderWindow &window) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sf::VertexArray m_lines;
|
sf::VertexArray lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRIDLINES_HPP
|
#endif // GRIDLINES_HPP
|
||||||
|
|||||||
@@ -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); };
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user