Now have a working compass based directional player sprite in the map, but using the compass isn't going to work long term. Need to move that into the raycaster.cpp and get real degrees for facing direction.

master
Zed A. Shaw 6 hours ago
parent 3b81959aa9
commit aa72cfe4a4
  1. 2
      assets/enemies.json
  2. 2
      assets/map_tiles.json
  3. BIN
      assets/map_tiles.png
  4. 12
      assets/tiles.json
  5. 6
      gui/map_view.cpp
  6. 1
      gui/map_view.hpp
  7. 99
      systems.cpp
  8. 4
      systems.hpp
  9. 5
      tests/map.cpp

@ -2,7 +2,7 @@
"PLAYER_TILE": {
"placement": "fixed",
"components": [
{"_type": "Tile", "display": 41981,
{"_type": "Tile", "display": 10733,
"foreground": "enemies/fg:player",
"background": "color:transparent"
},

@ -109,7 +109,7 @@
},
{
"centered": true,
"display": 41981,
"display": 10733,
"x": 512,
"y": 64
},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

@ -1,7 +1,6 @@
{
"floor_tile": {
"texture": "assets/textures/floor_gray_stone.png",
"collision": false,
"display": 8284,
"ceiling": "ceiling_black",
"light": 0,
@ -11,7 +10,6 @@
},
"wall_plain": {
"texture": "assets/textures/wall_plain.png",
"collision": true,
"display": 9608,
"light": 0,
"foreground": "tiles/fg:wall_plain",
@ -20,7 +18,6 @@
},
"wall_moss": {
"texture": "assets/textures/glowing_moss_wall.png",
"collision": true,
"display": 9256,
"light": 20,
"foreground": "tiles/fg:wall_moss",
@ -29,7 +26,6 @@
},
"ceiling_black": {
"texture": "assets/textures/ceiling_black.png",
"collision": false,
"display": 35,
"light": 0,
"foreground": "tiles/fg:ceiling_black",
@ -38,7 +34,6 @@
},
"lava_floor": {
"texture": "assets/textures/lava_floor.png",
"collision": false,
"display": 10899,
"ceiling": "ceiling_black",
"light": 20,
@ -48,7 +43,6 @@
},
"gray_stone_floor_light": {
"texture": "assets/textures/gray_stone_floor_light.png",
"collision": false,
"display": 11590,
"ceiling": "zBUGceiling_blue_light",
"light": 40,
@ -58,20 +52,18 @@
},
"wood_wall": {
"texture": "assets/textures/wood_wall.png",
"collision": false,
"display": 10747,
"light": 0,
"foreground": "tiles/fg:wood_wall",
"background": "tiles/bg:wood_wall",
"id": 8
"id": 7
},
"zBUGceiling_blue_light": {
"texture": "assets/textures/ceiling_blue_light.png",
"collision": false,
"display": 8285,
"light": 0,
"foreground": "color:BAD",
"background": "color:BAD",
"id": 7
"id": 8
}
}

@ -27,6 +27,8 @@ namespace gui {
$map_sprite($map_render->getTexture()),
$map_tiles(matrix::make(map_width, map_height))
{
auto player = $level.world->get_the<Player>();
$player_display = $level.world->get<Tile>(player.entity).display;
}
void MapViewUI::update_level(GameLevel &level) {
@ -60,8 +62,8 @@ namespace gui {
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
$gui.render(window);
System::draw_map($level, $map_tiles, $entity_map, compass_dir);
System::render_map($map_tiles, $entity_map, *$map_render);
System::draw_map($level, $map_tiles, $entity_map);
System::render_map($map_tiles, $entity_map, *$map_render, compass_dir, $player_display);
$map_sprite.setTexture($map_render->getTexture(), true);
window.draw($map_sprite);
// $gui.debug_layout(window);

@ -9,6 +9,7 @@ namespace gui {
class MapViewUI {
public:
guecs::UI $gui;
wchar_t $player_display = L'@';
DinkyECS::Entity $log_to;
EntityGrid $entity_map;
std::deque<std::wstring> $messages;

@ -407,47 +407,6 @@ void System::plan_motion(World& world, Position move_to) {
motion.dy = move_to.location.y - player_position.location.y;
}
void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map, int compass_dir) {
(void)compass_dir;
World &world = *level.world;
Map &map = *level.map;
size_t view_x = matrix::width(grid) - 1;
size_t view_y = matrix::height(grid) - 1;
entity_map.clear();
auto player_pos = world.get<Position>(level.player).location;
Point cam_orig = map.center_camera(player_pos, view_x, view_y);
auto &tiles = map.tiles();
auto &tile_set = textures::get_map_tile_set();
/* I'm doing double tid->wchar_t conversion here, maybe just
* render the tids into the grid then let someone else do this. */
// first fill it with the map cells
for(shiterator::each_cell_t it{grid}; it.next();) {
size_t tile_y = size_t(it.y) + cam_orig.y;
size_t tile_x = size_t(it.x) + cam_orig.x;
if(matrix::inbounds(tiles, tile_x, tile_y)) {
size_t tid = tiles[tile_y][tile_x];
grid[it.y][it.x] = tile_set[tid];
} else {
grid[it.y][it.x] = L' ';
}
}
// then get the enemy/item/device tiles and fill those in
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
&& 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);
entity_map.insert_or_assign(view_pos, entity_glyph.display);
}
});
}
void System::player_status(GameLevel &level) {
auto& combat = level.world->get<Combat>(level.player);
@ -567,7 +526,49 @@ bool System::inventory_occupied(GameLevel& level, Entity container_id, const std
}
void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render) {
void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) {
World &world = *level.world;
Map &map = *level.map;
size_t view_x = matrix::width(grid) - 1;
size_t view_y = matrix::height(grid) - 1;
entity_map.clear();
auto player_pos = world.get<Position>(level.player).location;
Point cam_orig = map.center_camera(player_pos, view_x, view_y);
auto &tiles = map.tiles();
auto &tile_set = textures::get_map_tile_set();
/* I'm doing double tid->wchar_t conversion here, maybe just
* render the tids into the grid then let someone else do this. */
// first fill it with the map cells
for(shiterator::each_cell_t it{grid}; it.next();) {
size_t tile_y = size_t(it.y) + cam_orig.y;
size_t tile_x = size_t(it.x) + cam_orig.x;
if(matrix::inbounds(tiles, tile_x, tile_y)) {
size_t tid = tiles[tile_y][tile_x];
grid[it.y][it.x] = tile_set[tid];
} else {
grid[it.y][it.x] = L' ';
}
}
// then get the enemy/item/device tiles and fill those in
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
&& 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);
entity_map.insert_or_assign(view_pos, entity_glyph.display);
}
});
}
void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) {
sf::Vector2i size{MAP_TILE_DIM,MAP_TILE_DIM};
unsigned int width = matrix::width(tiles);
unsigned int height = matrix::height(tiles);
@ -591,7 +592,19 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
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)});
if(display == player_display) {
sf::Vector2f size = sprite.getLocalBounds().size;
sf::Vector2f center{size.x / 2, size.y / 2};
float degrees = (((compass_dir * 45) + 270) % 360);
sprite.setOrigin(center);
sprite.setRotation(sf::degrees(degrees));
sprite.setPosition({float(point.x * size.x) + center.x, float(point.y * size.y) + center.y});
} else {
sprite.setPosition({float(point.x * size.x), float(point.y * size.y)});
}
render.draw(sprite);
}

@ -19,7 +19,6 @@ namespace System {
void init_positions(World &world, SpatialMap &collider);
void device(World &world, Entity actor, Entity item);
void plan_motion(World& world, Position move_to);
void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map, int compass_dir);
Entity spawn_item(World& world, const string& name);
bool drop_item(GameLevel& level, Entity item);
@ -40,5 +39,6 @@ namespace System {
void inventory_swap(GameLevel &level, Entity container_id, const std::string& a_name, const std::string &b_name);
bool inventory_occupied(GameLevel& level, Entity container_id, const std::string& name);
void render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render);
void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map);
void render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display);
}

@ -95,13 +95,14 @@ TEST_CASE("map image test", "[map-sprite]") {
sf::Sprite sprite{render->getTexture()};
auto player = level.world->get_the<components::Player>();
auto& player_pos = level.world->get<components::Position>(player.entity);
auto player_display = level.world->get<components::Tile>(player.entity).display;
for(matrix::each_row it{level.map->walls()}; it.next();) {
player_pos.location.x = it.x;
player_pos.location.y = it.y;
System::draw_map(level, map_tiles, entity_map, 2);
System::render_map(map_tiles, entity_map, *render);
System::draw_map(level, map_tiles, entity_map);
System::render_map(map_tiles, entity_map, *render, 2, player_display);
#ifdef TEST_RENDER
// confirm we get two different maps

Loading…
Cancel
Save