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

master
Zed A. Shaw 5 days ago
parent 8453e7c3b9
commit e015652f4c
  1. 30
      assets/tiles.json
  2. 22
      raycaster.cpp
  3. 3
      raycaster.hpp
  4. 1
      systems.cpp
  5. 6
      worldbuilder.cpp

@ -1,34 +1,38 @@
{
"FLOOR_TILE": {
"floor_tile": {
"texture": "assets/floor_tile_test-256.png",
"foreground": [40, 15, 125],
"background": [200, 15, 75],
"collision": false,
"display": 10398,
"id": 0
},
"WALL_PLAIN": {
"wall_plain": {
"texture": "assets/wall_texture_test-256.png",
"foreground": [230, 20, 30],
"background": [230, 20, 120],
"collision": true,
"display": 9608,
"id": 1
},
"WALL_MOSS": {
"wall_moss": {
"texture": "assets/glowing_moss_wall-256.png",
"foreground": [230, 20, 30],
"background": [230, 20, 120],
"collision": true,
"display": 8820,
"id": 2
},
"WALL_VINES": {
"wall_vines": {
"texture": "assets/wall_with_vines-256.png",
"foreground": [230, 20, 30],
"background": [230, 20, 120],
"collision": false,
"collision": true,
"display": 35,
"id": 3
},
"plain_ceiling": {
"texture": "assets/ceiling_test-256.png",
"collision": false,
"display": 35,
"id": 4
},
"lava_floor": {
"texture": "assets/lava_floor-256.png",
"collision": false,
"display": 35,
"id": 5
}
}

@ -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

@ -38,7 +38,8 @@ struct Raycaster {
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
GameLevel $level;
Matrix $map;
Matrix $tiles;
Matrix $walls;
std::vector<double> $zbuffer; // width
Raycaster(int width, int height);

@ -408,7 +408,6 @@ std::wstring System::draw_map(GameLevel level, size_t view_x, size_t view_y, int
}
}
// then get the enemy/item/device tiles and fill those in
world.query<Position, Tile>([&](auto ent, auto &pos, auto &entity_glyph) {
if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x

@ -15,7 +15,11 @@ void WorldBuilder::stylize_rooms() {
for(auto& room : $map.rooms()) {
for(matrix::box it{tiles, room.x, room.y, room.width+1, room.height+1}; it.next();) {
if(tiles[it.y][it.x] == 1) tiles[it.y][it.x] = 2;
if(tiles[it.y][it.x] == 1) {
tiles[it.y][it.x] = 2;
} else if(tiles[it.y][it.x] == 0) {
tiles[it.y][it.x] = 5;
}
}
}
}

Loading…
Cancel
Save