dungeongen

package
v0.0.0-...-76fdd16 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectionWest  = 0
	DirectionNorth = 1
	DirectionEast  = 2
	DirectionSouth = 3
)
View Source
const (
	RoomDensityLow    RoomDensity = 1
	RoomDensityMedium             = 2
	RoomDensityHigh               = 3
	RoomDensityMax                = 4
)

Variables

This section is empty.

Functions

func GetRandomColorInRgb

func GetRandomColorInRgb() (c color.RGBA)

func ParseHexColor

func ParseHexColor(s string) (c color.RGBA, err error)

TODO: Extract to utils package? ParseHexColor ...

Types

type AreaMask

type AreaMask interface {
	IsInside(x, y int) bool
}

AreaMask ...

type BitmapMask

type BitmapMask struct {
	Width  int
	Height int
	Mask   []bool
}

func LoadFromFile

func LoadFromFile(file string) *BitmapMask

LoadFromFile ...

func (*BitmapMask) IsInside

func (bm *BitmapMask) IsInside(x, y int) bool

check if mask is white at that point

type Builder

type Builder interface {
	Build() *DungeonData

	WithSmallSize() Builder
	WithMask(mask AreaMask) Builder
	WithSize(width int, height int) Builder
	WithCreationStrategy(strategy DungeonCreationStrategy) Builder
}

Builder ..

func DefaultBuilder

func DefaultBuilder() Builder

DefaultBuilder ...

type CircleMask

type CircleMask struct {
	Radius  int
	CenterX int
	CenterY int
}

CircleMask ...

func (*CircleMask) IsInside

func (cm *CircleMask) IsInside(x, y int) bool

IsInside tet for CircleMask

type DirectionCallback

type DirectionCallback struct {
	DirectionCallbackWest  func()
	DirectionCallbackNorth func()
	DirectionCallbackEast  func()
	DirectionCallbackSouth func()
}

func NewDirectionCallback

func NewDirectionCallback(west, north, east, south func()) *DirectionCallback

func (*DirectionCallback) On

func (dc *DirectionCallback) On(direction int)

type DungeonCreationStrategy

type DungeonCreationStrategy interface {
	Create(data *DungeonData, mask AreaMask)
}

DungeonCreationStrategy ...

type DungeonData

type DungeonData struct {
	Width  int
	Height int

	MapData  MapData2D
	PathData PathData2D
	Rooms    []*RoomData
}

DungeonData ...

func (*DungeonData) FindRoomForCoord

func (data *DungeonData) FindRoomForCoord(x, y int) (*RoomData, error)

FindRoomForCoord ...

func (*DungeonData) ForEachTile

func (data *DungeonData) ForEachTile(fun func(x, y int, tile TileType, data *DungeonData))

func (*DungeonData) Get

func (data *DungeonData) Get(x int, y int) TileType

Get ...

func (*DungeonData) GetPath

func (data *DungeonData) GetPath(x int, y int) uint8

GetPath ...

func (*DungeonData) Init

func (data *DungeonData) Init()

Init ...

func (*DungeonData) IsOutside

func (data *DungeonData) IsOutside(x, y int) bool

IsOutside checks if coords are outside of the dungeon space

func (*DungeonData) Set

func (data *DungeonData) Set(x int, y int, tile TileType)

Set ...

func (*DungeonData) SetPath

func (data *DungeonData) SetPath(x int, y int, tile uint8)

SetPath ...

func (*DungeonData) SetRoomPath

func (data *DungeonData) SetRoomPath(x, y, width, height int, tile uint8)

SetRoomPath ...

type EmptyMask

type EmptyMask struct {
}

EmptyMask ...

func (*EmptyMask) IsInside

func (em *EmptyMask) IsInside(x, y int) bool

IsInside tet for EmptyMask

type Explorer

type Explorer struct {
}

Explorer is used to explore a generated dungeon and create walkable path to be able to generate an interactive story

func NewExplorer

func NewExplorer() *Explorer

NewExplorer convenience function to create an explorer instance

func (*Explorer) Explore

func (e *Explorer) Explore(data *DungeonData)

Explore starts the dungeon exploring

type Exporter

type Exporter interface {
	Export(data DungeonData, format ExporterFormat) interface{}
}

Exporter exports data according to format

type ExporterFormat

type ExporterFormat int8

ExporterFormat is the format used for exporter the DungeonData

const (
	FormatPNG ExporterFormat = iota + 1
	FormatJSON
)

type MapData2D

type MapData2D []TileType

MapData2D ...

type PNGExporter

type PNGExporter struct {
}

func (*PNGExporter) ExportAsFile

func (exp *PNGExporter) ExportAsFile(data DungeonData, format ExporterFormat, fileName string) interface{}

Export PNG

func (*PNGExporter) ExportAsImage

func (exp *PNGExporter) ExportAsImage(data DungeonData, format ExporterFormat) *image.Image

Export PNG

type PathData2D

type PathData2D []uint8

PathData2D ...

type RandomRoomStrategy

type RandomRoomStrategy struct {
	Density               RoomDensity
	MaxRooms              int
	UseRandomSeed         bool
	Seed                  int
	MaxRoomWidth          int
	MaxRoomHeight         int
	MinRoomWidth          int
	MinRoomHeight         int
	SpaceBetweenRooms     int
	ChanceOfAdjacentRooms int
	ChanceForDivergence   int
	RoomConnectedness     int
}

RandomRoomStrategy...

func NewRandomRoomStrategy

func NewRandomRoomStrategy() *RandomRoomStrategy

NewRandomRoomStrategy returns a default RandomRoomStrategy

func (*RandomRoomStrategy) Create

func (strategy *RandomRoomStrategy) Create(data *DungeonData, mask AreaMask)

Create ...

type RoomData

type RoomData struct {
	X      int
	Y      int
	Width  int
	Height int

	IsConnected bool
	Visited     bool
	Section     uint8
	// contains filtered or unexported fields
}

RoomData ...

func NewRoomData

func NewRoomData(x int, y int, width int, height int) *RoomData

NewRoomData creates a new room data instance

func (*RoomData) AddDoor

func (r *RoomData) AddDoor(direction int, pos Vec2D)

AddDoor ...

func (*RoomData) Collides

func (r *RoomData) Collides(r2 RoomData) bool

Collides returns true if two rooms overlap

func (*RoomData) Doors

func (r *RoomData) Doors() []RoomDoor

Doors ...

func (*RoomData) Extrude

func (r *RoomData) Extrude(factor int) *RoomData

Extrude extrudes a room by factor returning a bigger or smaller room

func (*RoomData) GetWallForPosition

func (r *RoomData) GetWallForPosition(x, y int) (int, error)

GetWallForPosition ...

func (*RoomData) HasDoor

func (r *RoomData) HasDoor(direction int) bool

HasDoor ...returns if room has at least one door

func (*RoomData) IsCorner

func (r *RoomData) IsCorner(x, y int) bool

IsCorner returns if coord is a room corner (dont add doors there)

func (*RoomData) IsInside

func (r *RoomData) IsInside(x, y int) bool

IsInside returns true if a point is within the bounds of the room

type RoomDensity

type RoomDensity int8

type RoomDoor

type RoomDoor struct {
	Direction int
	Position  Vec2D
}

RoomDoor... room door

func NewRoomDoor

func NewRoomDoor(direction int, pos Vec2D) RoomDoor

NewRoomDoor ... creates a new room door

type TileType

type TileType int16

TileType ...

const (
	EmptyTileType TileType = iota + 1
	FloorTileType
	WallTileType
	DoorTileType
)

type Vec2D

type Vec2D struct {
	X int
	Y int
}

func NewVec2D

func NewVec2D(x, y int) Vec2D

func (Vec2D) Add

func (v Vec2D) Add(v2 Vec2D) Vec2D

func (Vec2D) Invert

func (v Vec2D) Invert() Vec2D

Jump to

Keyboard shortcuts

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