Now have more fancy rooms with different floors to play with.
This commit is contained in:
parent
f46b5f15ef
commit
9c03e850b5
7 changed files with 96 additions and 41 deletions
|
@ -5,9 +5,24 @@
|
||||||
"display": "\ua5b8"
|
"display": "\ua5b8"
|
||||||
},
|
},
|
||||||
"FLOOR_TILE": {
|
"FLOOR_TILE": {
|
||||||
"foreground": [80, 100, 0],
|
"foreground": [40, 15, 0],
|
||||||
"background": [30, 20, 2],
|
"background": [200, 15, 2],
|
||||||
"display":"\u2849"
|
"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": {
|
"PLAYER_TILE": {
|
||||||
"foreground": [255, 200, 0],
|
"foreground": [255, 200, 0],
|
||||||
|
@ -28,5 +43,15 @@
|
||||||
"foreground": [132, 200, 0],
|
"foreground": [132, 200, 0],
|
||||||
"background": [147, 220, 2],
|
"background": [147, 220, 2],
|
||||||
"display":"\u098c"
|
"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_compass_light(LightSource source, Point at, PointList &has_light);
|
||||||
void render_circle_light(LightSource source, Point at, PointList &has_light);
|
void render_circle_light(LightSource source, Point at, PointList &has_light);
|
||||||
Matrix &lighting() { return $lightmap; }
|
Matrix &lighting() { return $lightmap; }
|
||||||
|
Matrix &paths() { return $paths.paths(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,13 @@ ftxui_screen = dependency('ftxui-screen')
|
||||||
ftxui_dom = dependency('ftxui-dom')
|
ftxui_dom = dependency('ftxui-dom')
|
||||||
ftxui_component = dependency('ftxui-component')
|
ftxui_component = dependency('ftxui-component')
|
||||||
sfml = dependency('sfml')
|
sfml = dependency('sfml')
|
||||||
lua = dependency('lua')
|
|
||||||
sol2 = dependency('sol2')
|
|
||||||
freetype2 = dependency('freetype2')
|
freetype2 = dependency('freetype2')
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
catch2, fmt,
|
catch2, fmt,
|
||||||
ftxui_screen, ftxui_dom,
|
ftxui_screen, ftxui_dom,
|
||||||
ftxui_component, json,
|
ftxui_component, json,
|
||||||
sfml, lua, sol2, freetype2
|
sfml, freetype2
|
||||||
]
|
]
|
||||||
|
|
||||||
runtests = executable('runtests', [
|
runtests = executable('runtests', [
|
||||||
|
@ -113,9 +111,4 @@ img2ansi = executable('img2ansi', [
|
||||||
],
|
],
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
luatest = executable('luatest', [
|
|
||||||
'scratchpad/luatest.cpp'
|
|
||||||
],
|
|
||||||
dependencies: dependencies)
|
|
||||||
|
|
||||||
test('tests', runtests)
|
test('tests', runtests)
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
#define SOL_ALL_SAFETIES_ON 1
|
#define SOL_ALL_SAFETIES_ON 1
|
||||||
#include <sol/sol.hpp>
|
#include <sol/sol.hpp>
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include "components.hpp"
|
||||||
|
|
||||||
|
using namespace fmt;
|
||||||
|
using namespace components;
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
std::cout << "=== opening a state ===" << std::endl;
|
std::cout << "=== opening a state ===" << std::endl;
|
||||||
|
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
// open some common libraries
|
lua.open_libraries(sol::lib::base);
|
||||||
lua.open_libraries(sol::lib::base, sol::lib::package);
|
auto motion = Motion{1, -1};
|
||||||
lua.script("print('bark bark bark!')");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ TEST_CASE("lighting a map works", "[lighting]") {
|
||||||
|
|
||||||
Point light1 = map.place_entity(0);
|
Point light1 = map.place_entity(0);
|
||||||
Point light2 = map.place_entity(1);
|
Point light2 = map.place_entity(1);
|
||||||
LightSource source1{0,2};
|
LightSource source1{6, 1.0};
|
||||||
LightSource source2{1,3};
|
LightSource source2{4,3};
|
||||||
|
|
||||||
LightRender lr(map.width(), map.height());
|
LightRender lr(map.width(), map.height());
|
||||||
|
|
||||||
|
@ -37,7 +37,9 @@ TEST_CASE("lighting a map works", "[lighting]") {
|
||||||
Matrix &lighting = lr.lighting();
|
Matrix &lighting = lr.lighting();
|
||||||
|
|
||||||
matrix::dump("WALLS=====", map.walls(), light1.x, light1.y);
|
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
|
// confirm light is set at least at and around the two points
|
||||||
REQUIRE(lighting[light1.y][light1.x] == lighting::LEVELS[source1.strength]);
|
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);
|
$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() {
|
void WorldBuilder::generate() {
|
||||||
PointList holes;
|
PointList holes;
|
||||||
Room root{
|
Room root{
|
||||||
|
@ -140,15 +153,10 @@ void WorldBuilder::generate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$map.load_tiles();
|
$map.load_tiles();
|
||||||
|
stylize_room(3, "WATER_TILE", 2.5);
|
||||||
Point center = $map.place_entity(1);
|
stylize_room(2, "SAND_TILE", 4.5);
|
||||||
for(matrix::circle it{$map.$walls, center, 3}; it.next();) {
|
stylize_room(4, "MOSAIC_TILE_2", 7.0);
|
||||||
for(int x = it.left; x < it.right; x++) {
|
stylize_room(1, "GRASS_TILE", 3.4);
|
||||||
if(!$map.iswall(x, it.y)) {
|
|
||||||
$map.$tiles.set_tile(x, it.y, "WATER_TILE");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldBuilder::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
|
void WorldBuilder::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
|
||||||
|
@ -176,6 +184,31 @@ void WorldBuilder::place_rooms() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
holes.push_back(out);
|
||||||
|
|
||||||
|
if(paths[out.y][out.x] == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
||||||
|
|
||||||
|
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) {
|
bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
||||||
Matrix &paths = $map.paths();
|
Matrix &paths = $map.paths();
|
||||||
|
|
||||||
|
@ -184,18 +217,9 @@ bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
||||||
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
|
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
|
||||||
"target room has path as a wall");
|
"target room has path as a wall");
|
||||||
|
|
||||||
bool found = false;
|
if(!random_path($map, holes, src, target)) {
|
||||||
Point out{src.x, src.y};
|
straight_path(holes, src, target);
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
found = $map.neighbors(out, true);
|
|
||||||
holes.push_back(out);
|
|
||||||
|
|
||||||
if(paths[out.y][out.x] == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,5 @@ class WorldBuilder {
|
||||||
bool dig_tunnel(PointList &holes, Point &src, Point &target);
|
bool dig_tunnel(PointList &holes, Point &src, Point &target);
|
||||||
void tunnel_doors(PointList &holes, Room &src, Room &target);
|
void tunnel_doors(PointList &holes, Room &src, Room &target);
|
||||||
void update_door(Point &at, int wall_or_space);
|
void update_door(Point &at, int wall_or_space);
|
||||||
|
void stylize_room(int room, string tile_name, float size);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue