@ -28,9 +28,9 @@ struct Sprite {
# define uDiv 1
# define vDiv 1
const int RAY_VIEW_WIDTH = 128 0;
const int RAY_VIEW_WIDTH = 96 0;
const int RAY_VIEW_HEIGHT = 720 ;
const int RAY_VIEW_X = 0 ;
const int RAY_VIEW_X = 128 0 - RAY_VIEW_WIDTH ;
const int RAY_VIEW_Y = 0 ;
const int SCREEN_HEIGHT = RAY_VIEW_HEIGHT ;
@ -130,22 +130,16 @@ void draw_pixel_buffer(sf::RenderWindow &window) {
window . draw ( view_sprite ) ;
}
void draw_map_rect ( sf : : RenderWindow & window , int x , int y , uint32_t color ) {
void draw_gui ( sf : : RenderWindow & window , Matrix & map ) {
draw_sfml_rect ( window ,
{ float ( x * TILE_SIZE ) , float ( y * TILE_SIZE ) } ,
{ float ( TILE_SIZE - 1 ) , float ( TILE_SIZE - 1 ) } ,
color ) ;
}
void draw_map ( sf : : RenderWindow & window , Matrix & map ) {
uint32_t light_grey = gray_color ( 191 ) ;
uint32_t dark_grey = gray_color ( 65 ) ;
{ 0.0 , 0.0 } ,
{ SCREEN_WIDTH - RAY_VIEW_WIDTH , SCREEN_HEIGHT / 2 } ,
100 ) ;
for ( size_t y = 0 ; y < matrix : : height ( map ) ; y + + ) {
for ( size_t x = 0 ; x < matrix : : width ( map ) ; x + + ) {
draw_map_rect ( window , x , y , map [ y ] [ x ] = = 0 ? dark_grey : light_grey ) ;
}
}
draw_sfml_rect ( window ,
{ 0.0 , SCREEN_HEIGHT / 2 } ,
{ SCREEN_WIDTH - RAY_VIEW_WIDTH , SCREEN_HEIGHT / 2 } ,
150 ) ;
}
void draw_line ( sf : : RenderWindow & window , Point start , Point end , uint32_t color ) {
@ -181,10 +175,6 @@ void clear(sf::RenderWindow &window) {
window . clear ( ) ;
}
void draw_map_blocks ( sf : : RenderWindow & window , int col , int row ) {
draw_map_rect ( window , col , row , rgba_color ( 100 , 20 , 20 , 255 ) ) ;
}
void ray_casting ( sf : : RenderWindow & window , Matrix & map ) {
int w = RAY_VIEW_WIDTH ;
int h = RAY_VIEW_HEIGHT ;
@ -252,8 +242,6 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) {
perpWallDist = ( sideDistY - deltaDistY ) ;
}
// draw_map_blocks(window, mapX, mapY);
int lineHeight = int ( h / perpWallDist ) ;
int drawStart = - lineHeight / 2 + h / 2 + PITCH ;
@ -444,7 +432,7 @@ void draw_ceiling_floor(sf::RenderWindow &window) {
void draw_everything ( sf : : RenderWindow & window ) {
clear ( window ) ;
// draw_map(window, MAP);
draw_gui ( window , MAP ) ;
draw_ceiling_floor ( window ) ;
ray_casting ( window , MAP ) ;
draw_pixel_buffer ( window ) ;