Map is way better and components::Tile is _vastly_ improved by switching to a wchar_t on display and letting nlohmann::json auto convert it for me.
This commit is contained in:
parent
2b57552152
commit
2e79cf8781
11 changed files with 70 additions and 71 deletions
|
@ -7,7 +7,7 @@
|
||||||
"inventory_count": 0,
|
"inventory_count": 0,
|
||||||
"randomized": false,
|
"randomized": false,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u2ac5",
|
{"_type": "Tile", "display": 10949,
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
"inventory_count": 0,
|
"inventory_count": 0,
|
||||||
"placement": "fixed",
|
"placement": "fixed",
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u2259",
|
{"_type": "Tile", "display": 8793,
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
"description": "Watch where you're going.",
|
"description": "Watch where you're going.",
|
||||||
"inventory_count": 0,
|
"inventory_count": 0,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u1ac7",
|
{"_type": "Tile", "display": 6855,
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"PLAYER_TILE": {
|
"PLAYER_TILE": {
|
||||||
"placement": "fixed",
|
"placement": "fixed",
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\ua66b",
|
{"_type": "Tile", "display": 42603,
|
||||||
"foreground": [255, 200, 125],
|
"foreground": [255, 200, 125],
|
||||||
"background": [30, 20, 75]
|
"background": [30, 20, 75]
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
},
|
},
|
||||||
"KNIGHT": {
|
"KNIGHT": {
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u088d",
|
{"_type": "Tile", "display": 2189,
|
||||||
"foreground": [131, 213, 238],
|
"foreground": [131, 213, 238],
|
||||||
"background": [30, 20, 75]
|
"background": [30, 20, 75]
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
},
|
},
|
||||||
"AXE_RANGER": {
|
"AXE_RANGER": {
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u076a",
|
{"_type": "Tile", "display": 1898,
|
||||||
"foreground": [156, 172, 197],
|
"foreground": [156, 172, 197],
|
||||||
"background": [30, 20, 75]
|
"background": [30, 20, 75]
|
||||||
},
|
},
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
},
|
},
|
||||||
"RAT_GIANT": {
|
"RAT_GIANT": {
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u08ac",
|
{"_type": "Tile", "display": 2220,
|
||||||
"foreground": [205, 164, 246],
|
"foreground": [205, 164, 246],
|
||||||
"background": [30, 20, 75]
|
"background": [30, 20, 75]
|
||||||
},
|
},
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
},
|
},
|
||||||
"SPIDER_GIANT_HAIRY": {
|
"SPIDER_GIANT_HAIRY": {
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u08ea",
|
{"_type": "Tile", "display": 2282,
|
||||||
"foreground": [205, 164, 246],
|
"foreground": [205, 164, 246],
|
||||||
"background": [30, 20, 75]
|
"background": [30, 20, 75]
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"inventory_count": 1,
|
"inventory_count": 1,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "LightSource", "strength": 50, "radius": 2.5},
|
{"_type": "LightSource", "strength": 50, "radius": 2.5},
|
||||||
{"_type": "Tile", "display": "\u0f08",
|
{"_type": "Tile", "display": 3848,
|
||||||
"foreground": [24, 120, 189],
|
"foreground": [24, 120, 189],
|
||||||
"background": [230,120, 120]
|
"background": [230,120, 120]
|
||||||
},
|
},
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
"inventory_count": 1,
|
"inventory_count": 1,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Weapon", "damage": 15},
|
{"_type": "Weapon", "damage": 15},
|
||||||
{"_type": "Tile", "display": "\u1e37",
|
{"_type": "Tile", "display": 7735,
|
||||||
"foreground": [24, 120, 189],
|
"foreground": [24, 120, 189],
|
||||||
"background": [24, 120, 189]
|
"background": [24, 120, 189]
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
"name": "Small Barrel",
|
"name": "Small Barrel",
|
||||||
"description": "A small rotten barrel that may hold things.",
|
"description": "A small rotten barrel that may hold things.",
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\uaaea",
|
{"_type": "Tile", "display": 43754,
|
||||||
"foreground": [150, 100, 189],
|
"foreground": [150, 100, 189],
|
||||||
"background": [150, 100, 189]
|
"background": [150, 100, 189]
|
||||||
},
|
},
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
"description": "Light Hanging from Ceiling",
|
"description": "Light Hanging from Ceiling",
|
||||||
"inventory_count": 0,
|
"inventory_count": 0,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u077e",
|
{"_type": "Tile", "display": 1918,
|
||||||
"foreground": [24, 205, 210],
|
"foreground": [24, 205, 210],
|
||||||
"background": [24, 205, 210]
|
"background": [24, 205, 210]
|
||||||
},
|
},
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
"description": "A small healing potion.",
|
"description": "A small healing potion.",
|
||||||
"inventory_count": 1,
|
"inventory_count": 1,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u03eb",
|
{"_type": "Tile", "display": 1003,
|
||||||
"foreground": [255, 205, 189],
|
"foreground": [255, 205, 189],
|
||||||
"background": [255, 205, 189]
|
"background": [255, 205, 189]
|
||||||
},
|
},
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
"description": "Something died here. Was this your doing?",
|
"description": "Something died here. Was this your doing?",
|
||||||
"inventory_count": 1,
|
"inventory_count": 1,
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "Tile", "display": "\u21ef",
|
{"_type": "Tile", "display": 8687,
|
||||||
"foreground": [32, 123, 164],
|
"foreground": [32, 123, 164],
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,20 +4,20 @@
|
||||||
"foreground": [40, 15, 125],
|
"foreground": [40, 15, 125],
|
||||||
"background": [200, 15, 75],
|
"background": [200, 15, 75],
|
||||||
"collision": false,
|
"collision": false,
|
||||||
"display":"."
|
"display": 10398
|
||||||
},
|
},
|
||||||
"WALL_PLAIN": {
|
"WALL_PLAIN": {
|
||||||
"texture": "assets/wall_texture_test-256.png",
|
"texture": "assets/wall_texture_test-256.png",
|
||||||
"foreground": [230, 20, 30],
|
"foreground": [230, 20, 30],
|
||||||
"background": [230, 20, 120],
|
"background": [230, 20, 120],
|
||||||
"collision": true,
|
"collision": true,
|
||||||
"display": "#"
|
"display": 9608
|
||||||
},
|
},
|
||||||
"WALL_VINES": {
|
"WALL_VINES": {
|
||||||
"texture": "assets/wall_with_vines-256.png",
|
"texture": "assets/wall_with_vines-256.png",
|
||||||
"foreground": [230, 20, 30],
|
"foreground": [230, 20, 30],
|
||||||
"background": [230, 20, 120],
|
"background": [230, 20, 120],
|
||||||
"collision": false,
|
"collision": false,
|
||||||
"display":"|"
|
"display": 35
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace components {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Tile {
|
struct Tile {
|
||||||
std::string display;
|
wchar_t display;
|
||||||
std::array<uint8_t, 3> foreground;
|
std::array<uint8_t, 3> foreground;
|
||||||
std::array<uint8_t, 3> background;
|
std::array<uint8_t, 3> background;
|
||||||
};
|
};
|
||||||
|
|
30
map_view.cpp
30
map_view.cpp
|
@ -5,6 +5,7 @@
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include "rand.hpp"
|
#include "rand.hpp"
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
|
#include "systems.hpp"
|
||||||
#include "rand.hpp"
|
#include "rand.hpp"
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -13,7 +14,9 @@ namespace gui {
|
||||||
using namespace components;
|
using namespace components;
|
||||||
|
|
||||||
MapViewUI::MapViewUI(GameLevel &level) :
|
MapViewUI::MapViewUI(GameLevel &level) :
|
||||||
$level(level), $tiles(level.map->width(), level.map->height())
|
$level(level),
|
||||||
|
$tiles(level.map->width(),
|
||||||
|
level.map->height())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +29,9 @@ namespace gui {
|
||||||
$gui.layout("[map_grid]");
|
$gui.layout("[map_grid]");
|
||||||
|
|
||||||
auto grid = $gui.entity("map_grid");
|
auto grid = $gui.entity("map_grid");
|
||||||
$gui.set<guecs::WideText>(grid, {L"Loading...", 45, ColorValue::DARK_LIGHT, 10});
|
$gui.set<guecs::WideText>(grid,
|
||||||
|
{L"Loading...", 45, ColorValue::DARK_LIGHT, 10});
|
||||||
|
|
||||||
$gui.set<guecs::Sprite>(grid, {"paper_ui_background"});
|
$gui.set<guecs::Sprite>(grid, {"paper_ui_background"});
|
||||||
|
|
||||||
$gui.init();
|
$gui.init();
|
||||||
|
@ -35,28 +40,11 @@ namespace gui {
|
||||||
void MapViewUI::render(sf::RenderWindow &window) {
|
void MapViewUI::render(sf::RenderWindow &window) {
|
||||||
$tiles = $level.map->tiles();
|
$tiles = $level.map->tiles();
|
||||||
auto grid = $gui.entity("map_grid");
|
auto grid = $gui.entity("map_grid");
|
||||||
auto player_pos = $level.world->get<Position>($level.player).location;
|
|
||||||
|
|
||||||
std::string map;
|
std::wstring map_out = System::draw_map($level, 13, 6);
|
||||||
|
|
||||||
matrix::box it{$level.map->walls(), player_pos.x, player_pos.y, 7, 3};
|
|
||||||
|
|
||||||
while(it.next())
|
|
||||||
{
|
|
||||||
if(it.x == player_pos.x && it.y == player_pos.y) {
|
|
||||||
map += "@";
|
|
||||||
} else {
|
|
||||||
map += $tiles.at(it.x, it.y).display;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(it.x == it.right - 1) map += "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
|
||||||
std::wstring map_wstr = converter.from_bytes(map);
|
|
||||||
|
|
||||||
auto& map_text = $gui.get<guecs::WideText>(grid);
|
auto& map_text = $gui.get<guecs::WideText>(grid);
|
||||||
map_text.update(map_wstr);
|
map_text.update(map_out);
|
||||||
|
|
||||||
$gui.render(window);
|
$gui.render(window);
|
||||||
}
|
}
|
||||||
|
|
48
systems.cpp
48
systems.cpp
|
@ -11,6 +11,8 @@
|
||||||
#include "sound.hpp"
|
#include "sound.hpp"
|
||||||
#include "ai.hpp"
|
#include "ai.hpp"
|
||||||
#include "ai_debug.hpp"
|
#include "ai_debug.hpp"
|
||||||
|
#include "shiterator.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
@ -332,21 +334,45 @@ void System::plan_motion(DinkyECS::World& world, Point move_to) {
|
||||||
* This one is called inside the MapViewUI very often so
|
* This one is called inside the MapViewUI very often so
|
||||||
* just avoid GameMap unlike the others.
|
* just avoid GameMap unlike the others.
|
||||||
*/
|
*/
|
||||||
void System::draw_entities(DinkyECS::World &world, Map &map, const Matrix &lights, const Point &cam_orig, size_t view_x, size_t view_y) {
|
std::wstring System::draw_map(GameLevel level, size_t view_x, size_t view_y) {
|
||||||
|
DinkyECS::World &world = *level.world;
|
||||||
|
Map &map = *level.map;
|
||||||
|
|
||||||
|
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 &tiles = map.tiles();
|
||||||
|
|
||||||
world.query<Position, Tile>([&](auto, auto &pos, auto &tile) {
|
// make a grid of chars to work with
|
||||||
|
auto grid = shiterator::make<wchar_t>(view_x+1, view_y+1);
|
||||||
|
|
||||||
|
// 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(tile_x < tiles.$width && tile_y < tiles.$height) {
|
||||||
|
grid[it.y][it.x] = tiles.at(tile_x, tile_y).display;
|
||||||
|
} else {
|
||||||
|
grid[it.y][it.x] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// then get the enemy/item/device tiles and fill those in
|
||||||
|
world.query<Position, Tile>([&](auto, 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
|
||||||
&& 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 loc = map.map_to_camera(pos.location, cam_orig);
|
Point view_pos = map.map_to_camera(pos.location, cam_orig);
|
||||||
|
grid[view_pos.y][view_pos.x] = entity_glyph.display;
|
||||||
float light_value = lights[pos.location.y][pos.location.x] * PERCENT;
|
|
||||||
const Tile& cell = tiles.at(pos.location.x, pos.location.y);
|
|
||||||
|
|
||||||
(void)loc; // not used yet, this after ripping out map so needs rewrite
|
|
||||||
(void)light_value;
|
|
||||||
(void)cell;
|
|
||||||
(void)tile;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// then generate the string to display, but this goes away soon
|
||||||
|
std::wstring result;
|
||||||
|
|
||||||
|
for(shiterator::each_row_t it{grid}; it.next();) {
|
||||||
|
result += grid[it.y][it.x];
|
||||||
|
if(it.row) result += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace System {
|
||||||
void init_positions(DinkyECS::World &world, SpatialMap &collider);
|
void init_positions(DinkyECS::World &world, SpatialMap &collider);
|
||||||
void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
|
void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
|
||||||
void plan_motion(DinkyECS::World& world, Point move_to);
|
void plan_motion(DinkyECS::World& world, Point move_to);
|
||||||
void draw_entities(DinkyECS::World &world, Map &map, const Matrix &lights, const Point &cam_orig, size_t view_x, size_t view_y);
|
std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y);
|
||||||
|
|
||||||
void enemy_ai(GameLevel &level);
|
void enemy_ai(GameLevel &level);
|
||||||
void combat(GameLevel &level);
|
void combat(GameLevel &level);
|
||||||
|
|
|
@ -37,11 +37,8 @@ namespace textures {
|
||||||
for(auto &el : tiles.items()) {
|
for(auto &el : tiles.items()) {
|
||||||
auto &config = el.value();
|
auto &config = el.value();
|
||||||
TMGR.surfaces.emplace_back(load_image(config["texture"]));
|
TMGR.surfaces.emplace_back(load_image(config["texture"]));
|
||||||
|
wchar_t tid = config["display"];
|
||||||
std::wstring display = assets.wstring(el.key(), "display");
|
|
||||||
int surface_i = TMGR.surfaces.size() - 1;
|
int surface_i = TMGR.surfaces.size() - 1;
|
||||||
wchar_t tid = display[0];
|
|
||||||
|
|
||||||
TMGR.char_to_texture[tid] = surface_i;
|
TMGR.char_to_texture[tid] = surface_i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ TileMap::TileMap(size_t width, size_t height) :
|
||||||
$width(width),
|
$width(width),
|
||||||
$height(height),
|
$height(height),
|
||||||
$tile_ids(height, matrix::Row(width, SPACE_VALUE)),
|
$tile_ids(height, matrix::Row(width, SPACE_VALUE)),
|
||||||
$display(height, TileRow(width, {"", {0,0,0}, {0,0,0}}))
|
$display(height, TileRow(width, {L'#', {0,0,0}, {0,0,0}}))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,9 @@ void TileMap::dump(int show_x, int show_y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileMap::set_tile(size_t x, size_t y, string tile_name) {
|
void TileMap::set_tile(size_t x, size_t y, string tile_name) {
|
||||||
std::wstring tile_id = $config.wstring(tile_name, "display");
|
|
||||||
json tile_conf = $config[tile_name];
|
json tile_conf = $config[tile_name];
|
||||||
auto tile = components::convert<Tile>(tile_conf);
|
auto tile = components::convert<Tile>(tile_conf);
|
||||||
$tile_ids[y][x] = tile_id[0];
|
$tile_ids[y][x] = tile.display;
|
||||||
$display[y][x] = tile;
|
$display[y][x] = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,6 @@
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using namespace components;
|
using namespace components;
|
||||||
|
|
||||||
inline void check_player(DinkyECS::World &world, DinkyECS::Entity entity) {
|
|
||||||
auto player = world.get_the<Player>();
|
|
||||||
dbc::check(player.entity != entity, "player shouldn't be added to world");
|
|
||||||
|
|
||||||
auto tile = world.get<Tile>(player.entity);
|
|
||||||
|
|
||||||
// dbc::check(tile.chr == "\ua66b", format("PLAYER TILE CHANGED {} != {}", tile.chr, "\ua66b"));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int make_split(Room &cur, bool horiz) {
|
inline int make_split(Room &cur, bool horiz) {
|
||||||
size_t dimension = horiz ? cur.height : cur.width;
|
size_t dimension = horiz ? cur.height : cur.width;
|
||||||
int min = dimension / WORLDBUILD_DIVISION;
|
int min = dimension / WORLDBUILD_DIVISION;
|
||||||
|
@ -238,8 +229,7 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config
|
||||||
auto entity_data = entity_db[key];
|
auto entity_data = entity_db[key];
|
||||||
|
|
||||||
// pass that to the config as it'll be a generic json
|
// pass that to the config as it'll be a generic json
|
||||||
auto entity = configure_entity_in_map(world, entity_data, room_num);
|
configure_entity_in_map(world, entity_data, room_num);
|
||||||
check_player(world, entity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +237,7 @@ void WorldBuilder::place_stairs(DinkyECS::World& world, GameConfig& config) {
|
||||||
auto& device_config = config.devices.json();
|
auto& device_config = config.devices.json();
|
||||||
auto entity_data = device_config["STAIRS_DOWN"];
|
auto entity_data = device_config["STAIRS_DOWN"];
|
||||||
int last_room = $map.room_count() - 1;
|
int last_room = $map.room_count() - 1;
|
||||||
auto entity = configure_entity_in_map(world, entity_data, last_room);
|
configure_entity_in_map(world, entity_data, last_room);
|
||||||
check_player(world, entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldBuilder::place_entities(DinkyECS::World &world) {
|
void WorldBuilder::place_entities(DinkyECS::World &world) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue