Giter VIP home page Giter VIP logo

dngn's Introduction

dngn

dngn_v0.2

pkg.go.dev docs

What is dngn?

dngn is a golang library specifically created to help make generating random maps easier. This does not create maps from hand-crafted pieces randomly slotted together, but rather generates cellular rooms in a grid.

Why is it called that?

Because it's short, simple, and to the point. Also, vwls r vrrtd.

Why did you create dngn?

Because I needed to do random map generation for a game and didn't seem to find a library around anywhere.

And so, here we are.

How do I install it?

Just go get it and import it in your game application.

go get github.com/SolarLune/dngn

Or import and use it directly in your code with a go.mod file in your project directory, and it will go ahead and automatically download it and use it for your project. See the Go wiki.

How do I use it?

dngn is based around Layouts and Selections. A Layout contains a rune array, which is the internal data. You can either manipulate the data array manually, or use Selections to grab a selection of cells in the Layout to alter. Layouts have Generate functions to generate a game map; they each take different arguments to influence how the function generates a map. To start off, you can just create a Layout, and then use one of the included Generate functions to generate the data:

import "github.com/solarlune/dngn"

var GameMap *dngn.Layout

func Init() {

    // This line creates a new *dngn.Layout. The size is 10x10.
    GameMap = dngn.NewLayout(10, 10)

    // This will generate a map using BSP map generation and some sensible default settings.
    GameMap.GenerateBSP(dngn.NewDefaultBSPOptions())

    // Layout.DataToString() will present the data in a nice, easy-to-understand visual format, useful when debugging.
    fmt.Println(GameMap.DataToString())

    // Now we're done! We can visualize and use the Layout.

}

After generating the Layout, Selections can be used to filter out pieces of the Layout to alter them. Selections can also be chained together. As an example, say you wanted to randomly change a small percentage of floor tiles (' ') into trap tiles ('z'). You could easily do this with Selections, like so:

    GameMap.Select().FilterByValue(' ').FilterByPercentage(0.1).Fill('z')

And that's about it! There are also some nice additional features to make it easier to handle working with and altering Layouts directly.

Wait... How do I actually LOOK at it?

dngn just does map generation - it doesn't handle visualization / rendering of the map. For that, you can use another framework, like pixel, Ebiten, raylib-goplus, or go-sdl2.

That's about it. You can run the example by simply running the example from the project's root directory:

$ go run ./example/

pkg.go.dev docs

Dependencies?

For the actual package, there are no external dependencies. dngn just uses the built-in "fmt" and "math" packages.

For the tests, dngn requires Ebiten to create the window, handle input, and draw the shapes.

dngn's People

Contributors

solarlune avatar

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.