gendungeon

package
v0.0.0-...-ce97658 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

Go Dungeon Generator

NOTE: This code is a modified fork of https://github.com/brad811/go-dungeon/, which is an implementation of http://journal.stuffwithstuff.com/2014/12/21/rooms-and-mazes/.

Please check out the original code as it has great features like a local web interface for rendering the dungeon. I stripped out a lot of the additional features, so please check out the original :)

TODO

  • Add 2D dungeon generation
    • Add new room shapes
      • Oval
      • Apse (one sided)
      • Apse (two sided)
      • Hexagon
      • Octagon
    • Use float vector polygons for room generation
  • Add multi-level dungeon generation
    • Levels with identical dimensions
    • Levels with different dimensions
    • Add stairs
      • Connect levels using stairs
      • Add custom number of stairs
      • Ensure we don't override existing stairs
    • Add constraint solver to prevent non-overlapping levels

alt text

alt text

Documentation

Overview

Package gendungeon implements a simple dungeon generator forked from https://github.com/brad811/go-dungeon which is in turn based on http://journal.stuffwithstuff.com/2014/12/21/rooms-and-mazes/

Index

Constants

This section is empty.

Variables

View Source
var (
	RoomAttempts = 200
	MinRoomSize  = 5
	MaxRoomSize  = 15
)

Suggested default values for the dungeon generation.

Functions

This section is empty.

Types

type Config

type Config struct {
	Width        int
	Height       int
	RoomAttempts int
	MinRoomSize  int
	MaxRoomSize  int
	AllowNonRect bool // Allow non-rectangular rooms.
}

Config is a configuration for dungeon generation.

type Dungeon

type Dungeon struct {
	Tiles  [][]Tile // dungeon grid
	Rooms  []Room   // rooms in the dungeon
	Width  int      // width of the dungeon
	Height int      // height of the dungeon
	// contains filtered or unexported fields
}

Dungeon represents a generated dungeon.

func Generate

func Generate(width, height, roomAttempts, minRoomSize, maxRoomSize int, seed int64) *Dungeon

Generate generates a new dungeon with the given width and height. Further parameters include the number of attempts to use to place rooms, the minimum and maximum room size, and the seed to use.

func GenerateFromConfig

func GenerateFromConfig(cfg Config, seed int64) *Dungeon

GenerateFromConfig generates a new dungeon with the given configuration.

func (*Dungeon) RenderToConsole

func (dng *Dungeon) RenderToConsole()

RenderToConsole prints the dungeon layout to the console.

type DungeonMultiLevel

type DungeonMultiLevel struct {
	Levels []*Dungeon
}

DungeonMultiLevel represents a multi level dungeon.

func GenerateMultiLevelFromConfig

func GenerateMultiLevelFromConfig(cfg Config, n int, seed int64) *DungeonMultiLevel

GenerateMultiLevelFromConfig generates a mult level dungeon.

func NewDungeonMultiLevel

func NewDungeonMultiLevel() *DungeonMultiLevel

NewDungeonMultiLevel creates a new multi level dungeon.

func (*DungeonMultiLevel) AddLevel

func (d *DungeonMultiLevel) AddLevel(level *Dungeon)

AddLevel adds a level to the dungeon.

func (*DungeonMultiLevel) CreateNLevels

func (d *DungeonMultiLevel) CreateNLevels(cfg Config, n int, seed int64)

CreateNLevels creates n levels for the dungeon using the supplied config.

func (*DungeonMultiLevel) CreateStairs

func (d *DungeonMultiLevel) CreateStairs()

CreateStairs creates stairs between levels. Call this after all levels have been created.

func (*DungeonMultiLevel) RenderToConsole

func (d *DungeonMultiLevel) RenderToConsole()

RenderToConsole renders the dungeon to the console.

type Material

type Material int

Material represents the material of a tile.

const (
	MatWall       Material = iota // stone wall
	MatFloor                      // room floor
	MatDoor                       // door
	MatTunnel                     // tunnel / maze
	MatStairsUp                   // stairs up
	MatStairsDown                 // stairs down
)

The various valid materials.

type Point

type Point struct {
	X int
	Y int
}

Point is a point at a specific x,y coordinate.

type Rect

type Rect struct {
	X, Y, Width, Height int
}

Rect is a rectangle with a specific width and height.

func (*Rect) Center

func (r *Rect) Center() Point

Center returns the center of the rectangle.

type Room

type Room struct {
	Width    int       // width of the room
	Height   int       // height of the room
	Location Point     // top left corner of the room
	Edges    []Point   // the edges of the room
	Style    RoomStyle // style / shape of the room
}

Room represents a room in the dungeon.

func (*Room) Center

func (r *Room) Center() Point

Center returns the center of the room.

func (*Room) Overlap

func (r *Room) Overlap(r2 Room) (Rect, bool)

Overlap finds the rectangle representing the overlap between two rooms.

type RoomStyle

type RoomStyle int

RoomStyle represents the style of a room.

const (
	RoomStyleRect         RoomStyle = iota // [ ]
	RoomStyleOval                          // ()
	RoomStyleApseOneSided                  // [ )

)

The various valid room styles.

type Tile

type Tile struct {
	Region   int      // Associates a region with a tile.
	Material Material // The material of the tile.
}

Tile represents a tile on the dungeon grid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL