world

package
v0.0.0-...-8b39f33 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MaxElevation = 19

MaxElevation is the number of distinct elevations, numbered 0..MaxElevation.

Variables

View Source
var Terrain = []TerrainType{
	'g': {"g", "Grass"},
	'm': {"m", "Mountain"},
	'w': {"w", "Water"},
	'l': {"l", "Lava"},
	'd': {"d", "Desert"},
	'f': {"f", "Tree"},
	'i': {"i", "Glacier"},
}

Terrain is an array with the canonical terrain representations, indexed by the terrain type's unique character.

View Source
var TileSize = geom.Pt(32, 32)

TileSize is the size of a world tile in pixels.

Functions

This section is empty.

Types

type Loc

type Loc struct {
	// Terrain is the type of this locations terrain.
	Terrain *TerrainType

	// X and Y are the coordinates of this location
	X, Y int

	// Elevation is the elevation of the ground or the
	// surface of a body of water.
	Elevation int

	// Depth is the depth of water at this location.
	Depth int
}

A Loc is a cell in the grid that represents the world

func (Loc) Height

func (l Loc) Height() int

Height returns the elevation of the location minus its depth. This is effectively the elevation of the ground or the elevation of the floor of a body of water.

func (Loc) Point

func (l Loc) Point() geom.Point

Point returns the point representing the upper-left corner of this location.

type TerrainType

type TerrainType struct {
	// Char is the character representing this terrain type.
	Char string

	// Name is a human readable name of the terrain type.
	Name string
}

TerrainType holds information on a given type of terrain.

type World

type World struct {
	// Pixels is a Torus in the dimension of the world in pixels.
	Pixels geom.Torus

	// W and H are the width and height of the world's
	// location grid.
	W, H int

	// X0 and Y0 are the start location.
	X0, Y0 int
	// contains filtered or unexported fields
}

World is the main container for the world representation of minima.

func New

func New(w, h int) *World

New returns a world of the given dimensions.

func Read

func Read(in *bufio.Reader) (*World, error)

Read reads a world. If an error is encountered then the error is returned.

func (*World) At

func (w *World) At(x, y int) *Loc

At returns the location at the given world coordinate.

func (*World) LocsWithType

func (w *World) LocsWithType(types string) []*Loc

LocsWithType returns a slice of pointers to all of the locations with any of the given types.

func (*World) Tile

func (w *World) Tile(p geom.Point) (int, int)

func (*World) Wrap

func (w *World) Wrap(x, y int) (int, int)

Wrap returns an x,y within the ranges 0–width-1 and 0–height-1. This effectively maps world coordinates to a normalized point on a grid, making the world a torus shape.

func (*World) Write

func (w *World) Write(out io.Writer) error

Write writes a world. If the writer is not buffered then it is wrapped in a buffered writer, so the caller does not need to worry about buffering writes.

Jump to

Keyboard shortcuts

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