-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
47 lines (41 loc) · 1.58 KB
/
main.cpp
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
#include <iostream>
#include <raylib.h>
#include "include/Map.h"
#include "include/Entities.h"
int main() {
auto map = Map(mapWidth, mapHeight);
auto player = Player(mapWidth / 2, mapHeight / 2, 0, map);
InitWindow(screenWidth, screenHeight, "RaysGame");
SetWindowState(FLAG_WINDOW_RESIZABLE);
SetWindowState(FLAG_VSYNC_HINT);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(GRAY);
player.updatePlayer();
player.calculateAllRays([&](float r, RayData ray) {
float ray_length = player.calculateRayLength(ray);
float corrected_angle = player.angle - ray.angle;
if (corrected_angle < 0)
corrected_angle += 2 * pi;
if (corrected_angle > 2 * pi)
corrected_angle -= 2 * pi;
ray_length = ray_length * std::cos(corrected_angle);
float line_height = screenWidth / ray_length;
if (line_height > screenWidth)
line_height = screenWidth;
float line_offset = (float) screenHeight - line_height;
float lighting_factor = 1.0f / (1.0f + (ray_length * 0.05f));
Color color = {0,
0,
static_cast<unsigned char>(255 * lighting_factor),
255,};
DrawRectangle((r * lineThickness),
line_offset / 2,
lineThickness,
line_height,
color);
});
EndDrawing();
}
return EXIT_SUCCESS;
}