Now have the ability to load different textures for the floor, not ceiling though, it just matches the floor.
This commit is contained in:
parent
8453e7c3b9
commit
e015652f4c
5 changed files with 40 additions and 22 deletions
|
@ -1,34 +1,38 @@
|
||||||
{
|
{
|
||||||
"FLOOR_TILE": {
|
"floor_tile": {
|
||||||
"texture": "assets/floor_tile_test-256.png",
|
"texture": "assets/floor_tile_test-256.png",
|
||||||
"foreground": [40, 15, 125],
|
|
||||||
"background": [200, 15, 75],
|
|
||||||
"collision": false,
|
"collision": false,
|
||||||
"display": 10398,
|
"display": 10398,
|
||||||
"id": 0
|
"id": 0
|
||||||
},
|
},
|
||||||
"WALL_PLAIN": {
|
"wall_plain": {
|
||||||
"texture": "assets/wall_texture_test-256.png",
|
"texture": "assets/wall_texture_test-256.png",
|
||||||
"foreground": [230, 20, 30],
|
|
||||||
"background": [230, 20, 120],
|
|
||||||
"collision": true,
|
"collision": true,
|
||||||
"display": 9608,
|
"display": 9608,
|
||||||
"id": 1
|
"id": 1
|
||||||
},
|
},
|
||||||
"WALL_MOSS": {
|
"wall_moss": {
|
||||||
"texture": "assets/glowing_moss_wall-256.png",
|
"texture": "assets/glowing_moss_wall-256.png",
|
||||||
"foreground": [230, 20, 30],
|
|
||||||
"background": [230, 20, 120],
|
|
||||||
"collision": true,
|
"collision": true,
|
||||||
"display": 8820,
|
"display": 8820,
|
||||||
"id": 2
|
"id": 2
|
||||||
},
|
},
|
||||||
"WALL_VINES": {
|
"wall_vines": {
|
||||||
"texture": "assets/wall_with_vines-256.png",
|
"texture": "assets/wall_with_vines-256.png",
|
||||||
"foreground": [230, 20, 30],
|
"collision": true,
|
||||||
"background": [230, 20, 120],
|
|
||||||
"collision": false,
|
|
||||||
"display": 35,
|
"display": 35,
|
||||||
"id": 3
|
"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;
|
return conv.as_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Raycaster::Raycaster(int width, int height) :
|
Raycaster::Raycaster(int width, int height) :
|
||||||
$view_texture(sf::Vector2u{(unsigned int)width, (unsigned int)height}),
|
$view_texture(sf::Vector2u{(unsigned int)width, (unsigned int)height}),
|
||||||
$view_sprite($view_texture),
|
$view_sprite($view_texture),
|
||||||
|
@ -272,7 +271,7 @@ void Raycaster::cast_rays() {
|
||||||
side = 1;
|
side = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($map[map_y][map_x] > 0) hit = 1;
|
if($walls[map_y][map_x] == 1) hit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(side == 0) {
|
if(side == 0) {
|
||||||
|
@ -289,7 +288,7 @@ void Raycaster::cast_rays() {
|
||||||
int draw_end = line_height / 2 + $height / 2 + $pitch;
|
int draw_end = line_height / 2 + $height / 2 + $pitch;
|
||||||
if(draw_end >= $height) draw_end = $height - 1;
|
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
|
// calculate value of wall_x
|
||||||
double wall_x; // where exactly the wall was hit
|
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_width = TEXTURE_WIDTH;
|
||||||
constexpr static const int texture_height = TEXTURE_HEIGHT;
|
constexpr static const int texture_height = TEXTURE_HEIGHT;
|
||||||
auto &lights = $level.lights->lighting();
|
auto &lights = $level.lights->lighting();
|
||||||
|
size_t surface_i = 0;
|
||||||
|
|
||||||
for(int y = $height / 2 + 1; y < $height; ++y) {
|
for(int y = $height / 2 + 1; y < $height; ++y) {
|
||||||
// rayDir for leftmost ray (x=0) and rightmost (x = w)
|
// 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_x = $pos_x + row_distance * ray_dir_x0;
|
||||||
float floor_y = $pos_y + row_distance * ray_dir_y0;
|
float floor_y = $pos_y + row_distance * ray_dir_y0;
|
||||||
|
|
||||||
|
|
||||||
for(int x = 0; x < $width; ++x) {
|
for(int x = 0; x < $width; ++x) {
|
||||||
// the cell coord is simply taken from the int parts of
|
// the cell coord is simply taken from the int parts of
|
||||||
// floor_x and floor_y.
|
// 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?
|
// floor_x cell_x to find the texture x/y. How?
|
||||||
int map_x = int(floor_x);
|
int map_x = int(floor_x);
|
||||||
int map_y = int(floor_y);
|
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.
|
// NOTE: use map_x/y to get the floor, ceiling texture.
|
||||||
|
|
||||||
|
@ -418,7 +427,8 @@ void Raycaster::update_level(GameLevel level) {
|
||||||
|
|
||||||
$level = 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) {
|
$level.world->query<components::Sprite>([&](const auto ent, auto& sprite) {
|
||||||
// player doesn't need a sprite
|
// player doesn't need a sprite
|
||||||
|
|
|
@ -38,7 +38,8 @@ struct Raycaster {
|
||||||
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
|
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
|
||||||
|
|
||||||
GameLevel $level;
|
GameLevel $level;
|
||||||
Matrix $map;
|
Matrix $tiles;
|
||||||
|
Matrix $walls;
|
||||||
std::vector<double> $zbuffer; // width
|
std::vector<double> $zbuffer; // width
|
||||||
|
|
||||||
Raycaster(int width, int height);
|
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
|
// then get the enemy/item/device tiles and fill those in
|
||||||
world.query<Position, Tile>([&](auto ent, auto &pos, auto &entity_glyph) {
|
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
|
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(auto& room : $map.rooms()) {
|
||||||
for(matrix::box it{tiles, room.x, room.y, room.width+1, room.height+1}; it.next();) {
|
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…
Add table
Add a link
Reference in a new issue