-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
69 lines (52 loc) · 1.33 KB
/
Copy pathmain.cpp
File metadata and controls
69 lines (52 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Boundary.h"
#include "Ray.h"
#include "Particle.h"
#define W 800
#define H 600
int main()
{
srand(time(0));
sf::RenderWindow window(sf::VideoMode(W, H), "Raycasting2D");
std::vector<Boundary> walls;
for (int i = 0; i < 5; i++)
{
int x1 = rand() % W;
int y1 = rand() % H;
int x2 = rand() % W;
int y2 = rand() % H;
walls.emplace_back(Boundary(x1, y1, x2, y2));
}
walls.emplace_back(Boundary(0, 0, 0, H));
walls.emplace_back(Boundary(0, 0, W, 0));
walls.emplace_back(Boundary(0, H, W, H));
walls.emplace_back(Boundary(W - 1, 0, W - 1, H));
//Ray ray(100, 200);
Particle particle(W, H);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
sf::Vector2i mousePos = sf::Mouse::getPosition();
sf::Vector2i windowPos = window.getPosition();
if (mousePos.x > windowPos.x&& mousePos.x < windowPos.x + W && mousePos.y > windowPos.y&& mousePos.y < windowPos.y + H)
{
sf::Vector2f newPos = { (float)mousePos.x - windowPos.x, (float)mousePos.y - windowPos.y };
particle.update(newPos);
}
particle.show(window);
for (auto wall : walls)
{
wall.show(window);
}
particle.look(walls, window);
window.display();
}
return 0;
}