Fixed the map view on the left so it shows the correct visible squares.
This commit is contained in:
parent
ec332a3e2d
commit
bf77723f70
1 changed files with 24 additions and 18 deletions
|
@ -69,6 +69,28 @@ void draw_line(sf::RenderWindow &window, sf::Vector2f start, sf::Vector2f end) {
|
||||||
window.draw(line, 2, sf::Lines);
|
window.draw(line, 2, sf::Lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_map_rays(sf::RenderWindow &window, int col, int row, sf::Vector2f target) {
|
||||||
|
draw_map_rect(window, col, row, 100);
|
||||||
|
draw_line(window, {player_x, player_y}, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_3d_view(sf::RenderWindow &window, int depth, float start_angle, int ray) {
|
||||||
|
uint8_t color = 255 / (1 + depth * depth * 0.0001);
|
||||||
|
|
||||||
|
float fixed_depth = depth * std::cos(player_angle - start_angle);
|
||||||
|
|
||||||
|
float wall_height = 21000 / fixed_depth;
|
||||||
|
|
||||||
|
if(wall_height > SCREEN_HEIGHT){
|
||||||
|
wall_height = SCREEN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_rect(window,
|
||||||
|
{SCREEN_HEIGHT + ray * SCALE, (SCREEN_HEIGHT / 2) - wall_height / 2},
|
||||||
|
{SCALE, wall_height},
|
||||||
|
color);
|
||||||
|
}
|
||||||
|
|
||||||
void ray_casting(sf::RenderWindow &window, Matrix& map) {
|
void ray_casting(sf::RenderWindow &window, Matrix& map) {
|
||||||
float start_angle = player_angle - HALF_FOV;
|
float start_angle = player_angle - HALF_FOV;
|
||||||
|
|
||||||
|
@ -82,24 +104,8 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) {
|
||||||
int row = int(target_y / TILE_SIZE);
|
int row = int(target_y / TILE_SIZE);
|
||||||
|
|
||||||
if(map[row][col] == 1) {
|
if(map[row][col] == 1) {
|
||||||
draw_map_rect(window, col & TILE_SIZE, row * TILE_SIZE, 100);
|
draw_map_rays(window, col, row, {target_x, target_y});
|
||||||
|
draw_3d_view(window, depth, start_angle, ray);
|
||||||
draw_line(window, {player_x, player_y}, {target_x, target_y});
|
|
||||||
|
|
||||||
uint8_t color = 255 / (1 + depth * depth * 0.0001);
|
|
||||||
|
|
||||||
float fixed_depth = depth * std::cos(player_angle - start_angle);
|
|
||||||
|
|
||||||
float wall_height = 21000 / fixed_depth;
|
|
||||||
|
|
||||||
if(wall_height > SCREEN_HEIGHT){
|
|
||||||
wall_height = SCREEN_HEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_rect(window,
|
|
||||||
{SCREEN_HEIGHT + ray * SCALE, (SCREEN_HEIGHT / 2) - wall_height / 2},
|
|
||||||
{SCALE, wall_height},
|
|
||||||
color);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue