Now have more fancy rooms with different floors to play with.

main
Zed A. Shaw 1 week ago
parent f46b5f15ef
commit 9c03e850b5
  1. 31
      assets/tiles.json
  2. 1
      lights.hpp
  3. 9
      meson.build
  4. 19
      scratchpad/luatest.cpp
  5. 8
      tests/lighting.cpp
  6. 62
      worldbuilder.cpp
  7. 1
      worldbuilder.hpp

@ -5,9 +5,24 @@
"display": "\ua5b8"
},
"FLOOR_TILE": {
"foreground": [80, 100, 0],
"background": [30, 20, 2],
"display":"\u2849"
"foreground": [40, 15, 0],
"background": [200, 15, 2],
"display":"\u289e"
},
"MOSAIC_TILE_1": {
"foreground": [40, 15, 0],
"background": [200, 29, 2],
"display":"\u19f0"
},
"MOSAIC_TILE_2": {
"foreground": [40, 15, 0],
"background": [200, 29, 2],
"display":"\u16de"
},
"MOSAIC_TILE_3": {
"foreground": [40, 15, 0],
"background": [200, 29, 2],
"display":"\u1378"
},
"PLAYER_TILE": {
"foreground": [255, 200, 0],
@ -28,5 +43,15 @@
"foreground": [132, 200, 0],
"background": [147, 220, 2],
"display":"\u098c"
},
"SAND_TILE": {
"foreground": [24, 106, 0],
"background": [24, 123, 2],
"display":"\u17f6"
},
"GRASS_TILE": {
"foreground": [41, 180, 0],
"background": [75, 100, 2],
"display":"\u0799"
}
}

@ -55,5 +55,6 @@ namespace lighting {
void render_compass_light(LightSource source, Point at, PointList &has_light);
void render_circle_light(LightSource source, Point at, PointList &has_light);
Matrix &lighting() { return $lightmap; }
Matrix &paths() { return $paths.paths(); }
};
}

@ -8,15 +8,13 @@ ftxui_screen = dependency('ftxui-screen')
ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component')
sfml = dependency('sfml')
lua = dependency('lua')
sol2 = dependency('sol2')
freetype2 = dependency('freetype2')
dependencies = [
catch2, fmt,
ftxui_screen, ftxui_dom,
ftxui_component, json,
sfml, lua, sol2, freetype2
sfml, freetype2
]
runtests = executable('runtests', [
@ -113,9 +111,4 @@ img2ansi = executable('img2ansi', [
],
dependencies: dependencies)
luatest = executable('luatest', [
'scratchpad/luatest.cpp'
],
dependencies: dependencies)
test('tests', runtests)

@ -1,17 +1,26 @@
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
#include <cassert>
#include <iostream>
#include <fmt/core.h>
#include "components.hpp"
using namespace fmt;
using namespace components;
int main(int, char*[]) {
std::cout << "=== opening a state ===" << std::endl;
sol::state lua;
// open some common libraries
lua.open_libraries(sol::lib::base, sol::lib::package);
lua.script("print('bark bark bark!')");
lua.open_libraries(sol::lib::base);
auto motion = Motion{1, -1};
lua.new_usertype<Motion>("Motion",
"dx", &Motion::dx,
"dy", &Motion::dy
);
std::cout << std::endl;
lua["motion"] = &motion;
lua.script("print('dx', motion.dx, 'dy', motion.dy)");
return 0;
}

@ -16,8 +16,8 @@ TEST_CASE("lighting a map works", "[lighting]") {
Point light1 = map.place_entity(0);
Point light2 = map.place_entity(1);
LightSource source1{0,2};
LightSource source2{1,3};
LightSource source1{6, 1.0};
LightSource source2{4,3};
LightRender lr(map.width(), map.height());
@ -37,7 +37,9 @@ TEST_CASE("lighting a map works", "[lighting]") {
Matrix &lighting = lr.lighting();
matrix::dump("WALLS=====", map.walls(), light1.x, light1.y);
matrix::dump("LIGHTING======", lighting, light1.x, light1.y);
matrix::dump("PATHS=====", lr.paths(), light1.x, light1.y);
matrix::dump("LIGHTING 1", lighting, light1.x, light1.y);
matrix::dump("LIGHTING 2", lighting, light2.x, light2.y);
// confirm light is set at least at and around the two points
REQUIRE(lighting[light1.y][light1.x] == lighting::LEVELS[source1.strength]);

@ -106,6 +106,19 @@ void WorldBuilder::tunnel_doors(PointList &holes, Room &src, Room &target) {
$map.clear_target(target.entry);
}
void WorldBuilder::stylize_room(int room, string tile_name, float size) {
Point center = $map.place_entity(room);
for(matrix::circle it{$map.$walls, center, size}; it.next();) {
for(int x = it.left; x < it.right; x++) {
if(!$map.iswall(x, it.y)) {
$map.$tiles.set_tile(x, it.y, tile_name);
}
}
}
}
void WorldBuilder::generate() {
PointList holes;
Room root{
@ -140,15 +153,10 @@ void WorldBuilder::generate() {
}
$map.load_tiles();
Point center = $map.place_entity(1);
for(matrix::circle it{$map.$walls, center, 3}; it.next();) {
for(int x = it.left; x < it.right; x++) {
if(!$map.iswall(x, it.y)) {
$map.$tiles.set_tile(x, it.y, "WATER_TILE");
}
}
}
stylize_room(3, "WATER_TILE", 2.5);
stylize_room(2, "SAND_TILE", 4.5);
stylize_room(4, "MOSAIC_TILE_2", 7.0);
stylize_room(1, "GRASS_TILE", 3.4);
}
void WorldBuilder::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
@ -176,20 +184,14 @@ void WorldBuilder::place_rooms() {
}
}
bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
Matrix &paths = $map.paths();
dbc::check(paths[src.y][src.x] != WALL_PATH_LIMIT,
"source room has path as a wall");
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
"target room has path as a wall");
inline bool random_path(Map &map, PointList &holes, Point src, Point target) {
bool found = false;
Matrix &paths = map.paths();
Point out{src.x, src.y};
int count = 0;
do {
found = $map.neighbors(out, true);
found = map.neighbors(out, true);
holes.push_back(out);
if(paths[out.y][out.x] == 0) {
@ -197,5 +199,27 @@ bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
}
} while(found && ++count < WORLDBUILD_MAX_PATH);
return false;
return found;
}
inline void straight_path(PointList &holes, Point src, Point target) {
for(matrix::line dig{src, target}; dig.next();) {
holes.push_back({size_t(dig.x), size_t(dig.y)});
holes.push_back({size_t(dig.x+1), size_t(dig.y)});
}
}
bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
Matrix &paths = $map.paths();
dbc::check(paths[src.y][src.x] != WALL_PATH_LIMIT,
"source room has path as a wall");
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
"target room has path as a wall");
if(!random_path($map, holes, src, target)) {
straight_path(holes, src, target);
}
return true;
}

@ -17,4 +17,5 @@ class WorldBuilder {
bool dig_tunnel(PointList &holes, Point &src, Point &target);
void tunnel_doors(PointList &holes, Room &src, Room &target);
void update_door(Point &at, int wall_or_space);
void stylize_room(int room, string tile_name, float size);
};

Loading…
Cancel
Save