The sfmlrenderer now has a 3:4 aspect ratio which makes it look better, and then there's space for a gui on the left. I put some squares there to prototype the look.

master
Zed A. Shaw 2 months ago
parent 75a33084f8
commit d6a2f83f10
  1. 34
      sfmlcaster.cpp

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

Loading…
Cancel
Save