genmap2d

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: 8 Imported by: 1

README

Simple 2D Map Generator in Golang (WIP)

This package provides functionality to generate 2D maps using procedural methods.

Scope

  • Reproducible using seeds
  • Village placement
  • Terrain / biome types differentiated by color
  • Heightmap
    • Noise based
TODO
  • Rivers, lakes
  • Resources
  • Heightmap
    • Primitive based
    • Erosion

Map!

alt text

Documentation

Overview

Package genmap2d implements... <drumroll...> a simple 2d map generator!

Index

Constants

View Source
const (
	TileIDGrass byte = iota
	TileIDWater
	TileIDTree
	TileIDSand
	TileIDMountain
	TileIDSnow
	TileIDVillage
	TileIDMax
)

Various tile IDs.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map struct {
	Width     int               // Width of the map
	Height    int               // Height of the map
	Villages  []*VillageScore   // Generated villages
	Elevation []float64         // Elevation values for each cell
	Cells     []byte            // Cells contains the assigned tile IDs
	Rand      *rand.Rand        // Rand initialized with the provided seed
	Noise     opensimplex.Noise // Noise initialized with the provided seed
}

Map represents a generated map.

func New

func New(width, height int, seed int64) *Map

New returns a new map with the given dimensions generated using the given seed.

func (*Map) ExportPng

func (m *Map) ExportPng(path string) error

Export last frame to a PNG under the given path.

func (*Map) GetCoordinates

func (m *Map) GetCoordinates(idx int) (int, int)

GetCoordinates returns the x and y coordinates for the given index.

func (*Map) GetIndex

func (m *Map) GetIndex(x, y int) int

GetIndex returns the index for the given x and y coordinates.

func (*Map) PlaceVillage

func (m *Map) PlaceVillage()

PlaceVillage calculates the suitability score for each point on the map and will add a new village that gets the optimal score while being as far as possible from other villages. TODO: Factor out suitability function.

func (*Map) TileColor

func (m *Map) TileColor(tID byte) color.Color

TileColor returns the color of a tile based on the given tile ID.

func (*Map) TileFromHeight

func (m *Map) TileFromHeight(h int) byte

TileFromHeight returns the tile ID for a given height.

type VillageScore

type VillageScore struct {
	X, Y  int
	Score float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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