Giter Site home page Giter Site logo

bonegen's Introduction

BoneGen

Herringbone Wang Tile dungeon generators

The original work done by Sean T. Barrett on Herringbone Wang Tile dungeon generation produces some very high-quality dungeons, but the C library he graciously made available is hard to integrate into non-C/C++ applications. Here, I modified the STB source to output JSON instead of a bitmap, and used that JSON in a C# loader (then a Java loader). The plan is to keep porting, using the JSON in similar ways in different languages. A variant is used for Lua, which actually doesn't depend on any JSON library because I made another change to the STB source to generate Lua source code, and it's loaded easily by the Lua generator at runtime.

How to Use

The library works primarily by generating 2D char arrays to use as dungeons.

In Java

You can use a slightly-augmented version of this dungeon generator via Cuttlebone, which is on Maven Central and can be fetched with Maven, Gradle, Scala's SBT, Clojure's Leiningen, or similar tools using the instructions on that page. Cuttlebone also features Field of View code from Eben Howard's fantastic library SquidLib, but with the graphical display code removed to maximize portability. Cuttlebone's one dependency is Google GSON, a JSON parser lib. An example:

import squid.squidgrid.map.styled.*;
public class Example
{
    public static void main( String[] args )
    {
        DungeonGen dg = new DungeonGen();
        for(TilesetType tt : TilesetType.values())
        {
            dg.generate(tt, 80, 80);
            dg.wallWrap();
            System.out.println(dg + "\n");
        }
    }
}

In CSharp

It isn't available on NuGet yet, but there's a download available in the Releases section of this project. Usage is similar to Cuttlebone's DungeonGen, but it doesn't store the char[,] for later (yet, that should be a feature soon). BoneGen in C# has one dependency, JSON.NET. An example:

using BoneGen;
namespace MyStuff
{
    public class Example
    {
        public static void Main(string[] args)
        {
            int height = 80, width = 80;
            BoneGen bg = new BoneGen();
            char[,] dungeon = BoneGen.WallWrap(bg.Generate(TilesetType.DEFAULT_DUNGEON, height, width));
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Console.Write(dungeon[y, x]);
                }
            }
        }
    }
}

In Lua

The Lua library depends on the LuaJIT-supplied bit library, which can also be used on Lua 5.1 or 5.2 (it's available here, and you will need it if you aren't using LuaJIT). The only other code you need is in the Lua/bonegen/ folder, including the entire styles subfolder. It isn't organized into a module because I have no idea how Lua games would want it set up, and because I don't use Lua very much. Feel free to edit it or even submit a pull request if you organize it better! I would really appreciate it!

-- load bonegen.lua somehow first.
local donjon = wall_wrap(generate("default_dungeon", 60, 60, os.time()))
show2d(donjon)

License

Released into the public domain with the Unlicense (see LICENSE file in this directory).

Sample output

Using the TilesetType ROUND_ROOMS_DIAGONAL_CORRIDORS:

################################################################################
########..............############......############....############...........#
########...............##########.......############.....############..........#
########...............#########..........##########.....###########...........#
########...............########.............#########.....#########............#
#######.................######...............########.....#########............#
#.####.....##....#......#####.....#####.......########....#########.....#....#.#
#........##########.......#.....#######........#######.....#######......########
#.......#############..........#######..........######........#.......##########
#.......##############........########.....##....######..............###########
##......##############.......#########....####.....####............#############
###....###############......#########.....#####.....##.............#############
###.....##############.....#########.....######...................##############
####....##############....##########....########...................#############
#####....############....##########....##########..................#############
######....##########.....#########....############.................#############
#######....#######.........#####.....##############................###########.#
########....#####...........###.......##############...................######..#
########......##.............#.........#############......................##...#
#####..........#.............#.........#############.............###.......#...#
###....................................#############............#####..........#
##.....................................############......#....##########.......#
#...........##..........................##########......##################.....#
#............##...............#..........##....#.......####################....#
#............##...............##......................#####################....#
#............###.............########.................######################...#
#............###.............#########...............############.....######...#
##..........#####...........###########.............###########.........#####..#
##..........######.........###########..............##########...........#####.#
###........#########.....#############..............#########.............######
#####....############....#############..............#########.............######
######################....############..............########...............#####
######################.....############.............########...............#####
########.....#########.....###########..............########...............#####
######........#########.....#########................#######...............###.#
#####..........########.....#########................#######...............###.#
#####...........########....#########.....#....#......#####.................#..#
#####......#.....#######.....#######......########.....##......................#
#.##.......###....######........#.......###########..........#...........#.....#
#.........#####....######..............#############........###.........###....#
#......#########.....####............###############.......######......#####...#
#......##########.....##.............################.....########.....######..#
#.....###########...................#################....#########....##########
#......###########...................###############....##########....##########
#......############..................##############....##########....###########
#......#############.................#############....#########.....############
#......##############..................##########....########.........##########
#.....################....................#######...########...........#########
#.....################......................####....#######.............########
#......###############.......................###....#######.............########
#......###############............####..............######................######
#.#......############......#....##########...........#####.................#####
#####......#########......##################..........####..................##.#
######.....##....#.......###########...######.........####.....................#
#######.................##########.......#####........####...............#.....#
########................#########.........####........#####.............###....#
########...............#########...........####......######.............####...#
#########.............##########...........#####....########...........######..#
########..............#########.............#####....########.........########.#
########..............#########.............######....#########.....############
########..............#########.............#######....#########....############
########................########...........#########....#########....###########
#####....................#######...........##########...#########.....##########
####.......................######...........#########....#######......##########
##..........................######..........######.......######........#########
#..................####......#####.....##....###.........####...........########
#..................#####......###....#####....#...........##............########
#....###............######..........#######...............#.............########
#..#####............########........########............................########
########............#########......##########................#..........########
########............##########.....##########...............##..........########
#########..........############......########..............####........#########
#########..........#############......#######..............#####......##########
######...............#############....########............########....##########
#####....###....##....#############....#######............#######....###########
####....###########....#############....#######..........#######....############
###.....############....#...#########....#######........#######....#############
###....#############..........#######....#########....########........##########
##.....##############..........######....####################.............######
################################################################################

Using the TilesetType DEFAULT_DUNGEON:

################################################################################
#....########......##.......######..#####.......####.......###############.....#
#.....######................######......#........###..........############.....#
#......####............##...#..............#......##...........#####...#####...#
#.......##....###......##..................#..#...##...........####.....####...#
#.##....##....####.....##.......#####......#.....###............##.......###...#
#.##....##....#####....##.......#................###.....................###...#
####...####...###########..##...#............#..####.......##............###...#
####...####...#########.....#####......##......#####.......##........##........#
####..######..#########.....########...###.....#####..#########.....###........#
####..######..############..########...#####..######..#########.....############
#..#.....##..................#######...#####.....##......######......###########
#..#......#.......................##...#####...............###.............#####
#..#......#..#########..###.......######.#####.............###....#........#...#
#..####...#..##..........##..###..######..####.......##.....#.....##..###..#...#
#.....#......##..........##..###..##.......###........###.........##..#........#
#.....#......###..#########..###...........###..........##........###.#........#
#..####......................###......##...###...........##......######........#
#........##..................#######..###........###.....####....######........#
#........#####..######..############..###........###.....#####..#########.....##
############.....#####......########..################..######......#####.....##
###########........###.............#..#############........###..............####
#........##........###.............#.........######........#................#..#
#.........#........###.........#...#.........#....#..####..#......###########..#
######....####.....###....######...#..#####..#....#.....#..#..##...............#
#............##....###....#....#####..###...............#..#..##...............#
#.............###.........#....#......###...............#.........##############
#.........#...............#...........###.........#.....#......................#
#........##........#####..#...........###........############..................#
######..######.....#####..######......#####.....################..#####..#######
######..##############.....#####..#########.....###........##......#####......##
######..###........##........###................###........###.....#####......##
#....#.............##......................................####..##########...##
#....#......##..#...#..##..........##..####..................##..#...#....#....#
#.#..#..##..##..#...#..###........##......#########..............#...#....#....#
#.......##......#......####......##..........######..............#...#....####.#
#.#.....##......#......#####....##............#####.......................####.#
#....#..###.##..###.#########...#....##........####...........#................#
#....#..#####.....###.......#####....#####......###........####..#######.......#
##..#########.....###........###.....#####......########..#####......###.....###
##......#####.....####..##...###.....#####..#########.....#####......#####..####
##......#.........###....##..###.......##...........#.....#########..##........#
##......#................##..#####.....##...........#..........####..##........#
##......#..####...........#..#...##....####..########..#.......####...#..####..#
###....##..####...........#..#....##...##.....#........#....#...###...#..#..#..#
####..###..####...........#........##..##.....#........#....#...###......#..#..#
#..........#.............##.........#......#..#....#........##..###......#..#..#
#..........#.......##....##..#......#......#..#....#......####........####..#..#
####..######..########..##...###....#..#####..#....#......####.......##.....####
####..######..############..#####......###....######......########..###........#
##.....#####.....#######....#####......###.....#####......#####.....###..#.....#
#......####........#.........###....#..##........##.......#..##.....###..#.....#
#......#..#........#................#..##.........#...#####..#...........#...###
#......#..#........................##..##.........#...#......#...........#...#.#
#####..#...........................##..#######....#..........#..##...#...#...#.#
#..........................###....##.........#....#..........#..#...##...#####.#
#............................#...###.........#........#......#.....###.........#
#####...........#....#.......######....##.............####...#....#####........#
###########.....#....#.......######....##........###.....#...#...######.......##
#############...######.....#########..##############.....#####..#########.....##
#..#########.....#####..#########.....################..######......#####.....##
#...##########..######..#....#..#.....################.....##...........##.....#
#....########....#####..#....#..#...........##########.....##...........###....#
#.......#####....#####..#....#..#...........##.....######..##....#####..###....#
#.......######..######..#....#..#......#....##......##.....##....#####..###....#
#....#..........######..###..#..#......#....##.......#.....##....###....###....#
#....#.......................#..#####..#.....#.......#..#........###....###....#
#....#..#####................#.........##...............#........###....##.....#
#....#..########..####.......#.........##........##.....#####.....#######......#
######..#####......###.....#####..#########.....###.....######.....#####......##
####....#####......#####..######......#####.....################...#####..######
#........####......#####..#####.......#..##.....###........#####.....###..#...##
#...........#......#####..#...#...#####..#.................######.....##..#...##
#...........############..#...#...#......#.................#######....##..#...##
#.................######..#...#..........#..##...###..###..#######....##..#...##
#......###.............#..#...#..........#..#...####..###......###....##..#...##
#........#..#..........#..#.......#......#.....####....##.......##.............#
##.......####....####..#..#.......####...#....#####.....#####...##.............#
##.......####....####..#..#..###.....#...#...######......#####...#...#####..####
################################################################################

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.