Now have the ability to load different textures for the floor, not ceiling though, it just matches the floor.

This commit is contained in:
Zed A. Shaw 2025-05-26 00:29:32 -04:00
parent 8453e7c3b9
commit e015652f4c
5 changed files with 40 additions and 22 deletions

View file

@ -57,7 +57,6 @@ inline uint32_t lighting_calc(uint32_t pixel, float dist, int level) {
return conv.as_int;
}
Raycaster::Raycaster(int width, int height) :
$view_texture(sf::Vector2u{(unsigned int)width, (unsigned int)height}),
$view_sprite($view_texture),
@ -272,7 +271,7 @@ void Raycaster::cast_rays() {
side = 1;
}
if($map[map_y][map_x] > 0) hit = 1;
if($walls[map_y][map_x] == 1) hit = 1;
}
if(side == 0) {
@ -289,7 +288,7 @@ void Raycaster::cast_rays() {
int draw_end = line_height / 2 + $height / 2 + $pitch;
if(draw_end >= $height) draw_end = $height - 1;
auto texture = textures::get_surface($map[map_y][map_x]);
auto texture = textures::get_surface($tiles[map_y][map_x]);
// calculate value of wall_x
double wall_x; // where exactly the wall was hit
@ -329,6 +328,7 @@ void Raycaster::draw_ceiling_floor() {
constexpr static const int texture_width = TEXTURE_WIDTH;
constexpr static const int texture_height = TEXTURE_HEIGHT;
auto &lights = $level.lights->lighting();
size_t surface_i = 0;
for(int y = $height / 2 + 1; y < $height; ++y) {
// rayDir for leftmost ray (x=0) and rightmost (x = w)
@ -361,7 +361,6 @@ void Raycaster::draw_ceiling_floor() {
float floor_x = $pos_x + row_distance * ray_dir_x0;
float floor_y = $pos_y + row_distance * ray_dir_y0;
for(int x = 0; x < $width; ++x) {
// the cell coord is simply taken from the int parts of
// floor_x and floor_y.
@ -381,7 +380,17 @@ void Raycaster::draw_ceiling_floor() {
// floor_x cell_x to find the texture x/y. How?
int map_x = int(floor_x);
int map_y = int(floor_y);
int light_level = matrix::inbounds(lights, map_x, map_y) ? lights[map_y][map_x] : 30;
if(!matrix::inbounds(lights, map_x, map_y)) continue;
int light_level = lights[map_y][map_x];
size_t new_surface_i = $tiles[map_y][map_x];
if(new_surface_i != surface_i) {
surface_i = new_surface_i;
$floor_texture = textures::get_surface(surface_i);
$ceiling_texture = textures::get_surface(surface_i);
}
// NOTE: use map_x/y to get the floor, ceiling texture.
@ -418,7 +427,8 @@ void Raycaster::update_level(GameLevel level) {
$level = level;
$map = $level.map->tiles();
$tiles = $level.map->tiles();
$walls = $level.map->walls();
$level.world->query<components::Sprite>([&](const auto ent, auto& sprite) {
// player doesn't need a sprite