|
|
@ -8,9 +8,21 @@ |
|
|
|
using matrix::Matrix; |
|
|
|
using matrix::Matrix; |
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matrix MAP{ |
|
|
|
|
|
|
|
{1,1,1,1,1,1,1,1,1}, |
|
|
|
|
|
|
|
{1,0,1,0,0,0,0,0,1}, |
|
|
|
|
|
|
|
{1,0,1,0,0,1,1,0,1}, |
|
|
|
|
|
|
|
{1,0,0,0,0,0,0,0,1}, |
|
|
|
|
|
|
|
{1,1,0,0,0,0,0,0,1}, |
|
|
|
|
|
|
|
{1,0,0,1,1,1,0,0,1}, |
|
|
|
|
|
|
|
{1,0,0,0,1,0,0,0,1}, |
|
|
|
|
|
|
|
{1,0,0,0,0,0,1,1,1}, |
|
|
|
|
|
|
|
{1,1,1,1,1,1,1,1,1} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const int SCREEN_HEIGHT=480; |
|
|
|
const int SCREEN_HEIGHT=480; |
|
|
|
const int SCREEN_WIDTH=SCREEN_HEIGHT * 2; |
|
|
|
const int SCREEN_WIDTH=SCREEN_HEIGHT * 2; |
|
|
|
const int MAP_SIZE=8; |
|
|
|
const int MAP_SIZE=matrix::width(MAP); |
|
|
|
const int TILE_SIZE=(SCREEN_WIDTH/2) / MAP_SIZE; |
|
|
|
const int TILE_SIZE=(SCREEN_WIDTH/2) / MAP_SIZE; |
|
|
|
const float FOV = std::numbers::pi / 3.0; |
|
|
|
const float FOV = std::numbers::pi / 3.0; |
|
|
|
const float HALF_FOV = FOV / 2; |
|
|
|
const float HALF_FOV = FOV / 2; |
|
|
@ -19,17 +31,6 @@ const float STEP_ANGLE = FOV / CASTED_RAYS; |
|
|
|
const int MAX_DEPTH = MAP_SIZE * TILE_SIZE; |
|
|
|
const int MAX_DEPTH = MAP_SIZE * TILE_SIZE; |
|
|
|
const float SCALE = (SCREEN_WIDTH / 2) / CASTED_RAYS; |
|
|
|
const float SCALE = (SCREEN_WIDTH / 2) / CASTED_RAYS; |
|
|
|
|
|
|
|
|
|
|
|
Matrix MAP{ |
|
|
|
|
|
|
|
{1,1,1,1,1,1,1,1}, |
|
|
|
|
|
|
|
{1,0,1,0,0,0,0,1}, |
|
|
|
|
|
|
|
{1,0,1,0,0,1,1,1}, |
|
|
|
|
|
|
|
{1,0,0,0,0,0,0,1}, |
|
|
|
|
|
|
|
{1,1,0,0,0,0,0,1}, |
|
|
|
|
|
|
|
{1,0,0,1,1,1,0,1}, |
|
|
|
|
|
|
|
{1,0,0,0,1,0,0,1}, |
|
|
|
|
|
|
|
{1,1,1,1,1,1,1,1} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float player_x = SCREEN_WIDTH / 4; |
|
|
|
float player_x = SCREEN_WIDTH / 4; |
|
|
|
float player_y = SCREEN_WIDTH / 4; |
|
|
|
float player_y = SCREEN_WIDTH / 4; |
|
|
|
float player_angle = std::numbers::pi; |
|
|
|
float player_angle = std::numbers::pi; |
|
|
@ -44,7 +45,7 @@ void draw_rect(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, ui |
|
|
|
void draw_map_rect(sf::RenderWindow &window, int x, int y, uint8_t color) { |
|
|
|
void draw_map_rect(sf::RenderWindow &window, int x, int y, uint8_t color) { |
|
|
|
draw_rect(window, |
|
|
|
draw_rect(window, |
|
|
|
{float(x * TILE_SIZE), float(y * TILE_SIZE)}, |
|
|
|
{float(x * TILE_SIZE), float(y * TILE_SIZE)}, |
|
|
|
{TILE_SIZE-1, TILE_SIZE-1}, |
|
|
|
{float(TILE_SIZE-1), float(TILE_SIZE-1)}, |
|
|
|
color); |
|
|
|
color); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -107,6 +108,7 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) { |
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main() { |
|
|
|
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Raycaster"); |
|
|
|
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Raycaster"); |
|
|
|
|
|
|
|
window.setVerticalSyncEnabled(true); |
|
|
|
|
|
|
|
|
|
|
|
while(window.isOpen()) { |
|
|
|
while(window.isOpen()) { |
|
|
|
sf::Event event; |
|
|
|
sf::Event event; |
|
|
@ -125,7 +127,6 @@ int main() { |
|
|
|
|
|
|
|
|
|
|
|
ray_casting(window, MAP); |
|
|
|
ray_casting(window, MAP); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.display(); |
|
|
|
window.display(); |
|
|
|
|
|
|
|
|
|
|
|
while(window.pollEvent(event)) { |
|
|
|
while(window.pollEvent(event)) { |
|
|
|