Now entities are drawn after the map so that there's no holes.
This commit is contained in:
parent
72ecca8c82
commit
0d1eacdc5c
4 changed files with 23 additions and 14 deletions
2
map.hpp
2
map.hpp
|
@ -20,6 +20,8 @@ struct Room {
|
||||||
size_t height = 0;
|
size_t height = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using EntityGrid = std::unordered_map<Point, wchar_t>;
|
||||||
|
|
||||||
class Map {
|
class Map {
|
||||||
public:
|
public:
|
||||||
size_t $width;
|
size_t $width;
|
||||||
|
|
18
systems.cpp
18
systems.cpp
|
@ -407,13 +407,15 @@ void System::plan_motion(World& world, Position move_to) {
|
||||||
motion.dy = move_to.location.y - player_position.location.y;
|
motion.dy = move_to.location.y - player_position.location.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::draw_map(GameLevel& level, Matrix& grid, int compass_dir) {
|
void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map, int compass_dir) {
|
||||||
(void)compass_dir;
|
(void)compass_dir;
|
||||||
World &world = *level.world;
|
World &world = *level.world;
|
||||||
Map &map = *level.map;
|
Map &map = *level.map;
|
||||||
size_t view_x = matrix::width(grid) - 1;
|
size_t view_x = matrix::width(grid) - 1;
|
||||||
size_t view_y = matrix::height(grid) - 1;
|
size_t view_y = matrix::height(grid) - 1;
|
||||||
|
|
||||||
|
entity_map.clear();
|
||||||
|
|
||||||
auto player_pos = world.get<Position>(level.player).location;
|
auto player_pos = world.get<Position>(level.player).location;
|
||||||
Point cam_orig = map.center_camera(player_pos, view_x, view_y);
|
Point cam_orig = map.center_camera(player_pos, view_x, view_y);
|
||||||
auto &tiles = map.tiles();
|
auto &tiles = map.tiles();
|
||||||
|
@ -436,17 +438,13 @@ void System::draw_map(GameLevel& level, Matrix& grid, int compass_dir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, auto &pos, auto &entity_glyph) {
|
||||||
|
// BUG: don't I have a within bounds macro somewhere?
|
||||||
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
|
||||||
&& pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y) {
|
&& pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y)
|
||||||
|
{
|
||||||
Point view_pos = map.map_to_camera(pos.location, cam_orig);
|
Point view_pos = map.map_to_camera(pos.location, cam_orig);
|
||||||
|
entity_map.insert_or_assign(view_pos, entity_glyph.display);
|
||||||
if(ent == level.player) {
|
|
||||||
// grid[view_pos.y][view_pos.x] = COMPASS[compass_dir][0];
|
|
||||||
grid[view_pos.y][view_pos.x] = 41981;
|
|
||||||
} else {
|
|
||||||
grid[view_pos.y][view_pos.x] = entity_glyph.display;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace System {
|
||||||
void init_positions(World &world, SpatialMap &collider);
|
void init_positions(World &world, SpatialMap &collider);
|
||||||
void device(World &world, Entity actor, Entity item);
|
void device(World &world, Entity actor, Entity item);
|
||||||
void plan_motion(World& world, Position move_to);
|
void plan_motion(World& world, Position move_to);
|
||||||
void draw_map(GameLevel& level, Matrix& grid, int compass_dir);
|
void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map, int compass_dir);
|
||||||
Entity spawn_item(World& world, const string& name);
|
Entity spawn_item(World& world, const string& name);
|
||||||
bool drop_item(GameLevel& level, Entity item);
|
bool drop_item(GameLevel& level, Entity item);
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,8 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Sprite render_map(Matrix& tiles, sf::RenderTexture& render) {
|
sf::Sprite render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render) {
|
||||||
|
(void) entity_map;
|
||||||
sf::Vector2i size{MAP_TILE_DIM,MAP_TILE_DIM};
|
sf::Vector2i size{MAP_TILE_DIM,MAP_TILE_DIM};
|
||||||
|
|
||||||
sf::Vector2u dim{
|
sf::Vector2u dim{
|
||||||
|
@ -101,6 +102,12 @@ sf::Sprite render_map(Matrix& tiles, sf::RenderTexture& render) {
|
||||||
render.draw(sprite);
|
render.draw(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(auto [point, display] : entity_map) {
|
||||||
|
auto& sprite = textures::get_map_sprite(display);
|
||||||
|
sprite.setPosition({float(point.x * size.x), float(point.y * size.y)});
|
||||||
|
render.draw(sprite);
|
||||||
|
}
|
||||||
|
|
||||||
render.display();
|
render.display();
|
||||||
return sf::Sprite{render.getTexture()};
|
return sf::Sprite{render.getTexture()};
|
||||||
}
|
}
|
||||||
|
@ -112,6 +119,8 @@ TEST_CASE("map image test", "[map-sprite]") {
|
||||||
LevelManager levels;
|
LevelManager levels;
|
||||||
GameLevel level = levels.current();
|
GameLevel level = levels.current();
|
||||||
Matrix map_tiles = matrix::make(7,7);
|
Matrix map_tiles = matrix::make(7,7);
|
||||||
|
EntityGrid entity_map;
|
||||||
|
|
||||||
auto render = std::make_shared<sf::RenderTexture>();
|
auto render = std::make_shared<sf::RenderTexture>();
|
||||||
auto player = level.world->get_the<components::Player>();
|
auto player = level.world->get_the<components::Player>();
|
||||||
auto& player_pos = level.world->get<components::Position>(player.entity);
|
auto& player_pos = level.world->get<components::Position>(player.entity);
|
||||||
|
@ -120,9 +129,9 @@ TEST_CASE("map image test", "[map-sprite]") {
|
||||||
player_pos.location.x = it.x;
|
player_pos.location.x = it.x;
|
||||||
player_pos.location.y = it.y;
|
player_pos.location.y = it.y;
|
||||||
|
|
||||||
System::draw_map(level, map_tiles, 2);
|
System::draw_map(level, map_tiles, entity_map, 2);
|
||||||
// on level start make one render texture with the base map
|
// on level start make one render texture with the base map
|
||||||
auto map_sprite = render_map(map_tiles, *render);
|
auto map_sprite = render_map(map_tiles, entity_map, *render);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue