tile

package
v0.0.0-...-ef5f187 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ManhattanDistance

func ManhattanDistance(a, b Position) int

func PackedBlobmapNumber

func PackedBlobmapNumber(t, b, l, r, tl, tr, bl, br bool) uint8

Follows the tile numbering that godot uses. Numbered in reading order, starting at 0. Godot: https://docs.godotengine.org/en/stable/tutorials/2d/using_tilemaps.html

func PackedPipemapNumber

func PackedPipemapNumber(t, b, l, r bool) uint8

Same thing as blobmap but only includes the edge neighbors (and not corners)

func PackedRawEightNumber

func PackedRawEightNumber(t, b, l, r, tl, tr, bl, br bool) uint8

func WangBlobmapNumber

func WangBlobmapNumber(t, b, l, r, tl, tr, bl, br bool) uint8

This function computes the wang tilenumber of a tile based on the tiles around it

Types

type Chunk

type Chunk[T any] struct {
	TileSize [2]int // In pixels

	Offset     phy2.Vec2 // In world space positioning
	TileOffset Position
	// contains filtered or unexported fields
}

func NewChunk

func NewChunk[T any](tiles [][]T, tileSize [2]int, math FlatRectMath) *Chunk[T]

func (*Chunk[T]) BoundsAt

func (t *Chunk[T]) BoundsAt(pos TilePosition) (float64, float64, float64, float64)

TODO - this might not work for pointy-top tilemaps

func (*Chunk[T]) Get

func (t *Chunk[T]) Get(pos TilePosition) (T, bool)

func (*Chunk[T]) GetEdgeNeighbors

func (t *Chunk[T]) GetEdgeNeighbors(x, y int) []TilePosition

func (*Chunk[T]) GetOverlappingTiles

func (t *Chunk[T]) GetOverlappingTiles(x, y float64, collider *phy2.CircleCollider) []TilePosition

Returns a list of tiles that are overlapping the collider at a position

func (*Chunk[T]) Height

func (t *Chunk[T]) Height() int

func (*Chunk[T]) PositionToTile

func (t *Chunk[T]) PositionToTile(x, y float64) TilePosition

func (*Chunk[T]) Set

func (t *Chunk[T]) Set(pos TilePosition, tile T) bool

func (*Chunk[T]) TileToPosition

func (t *Chunk[T]) TileToPosition(tilePos TilePosition) (float64, float64)

func (*Chunk[T]) Tiles

func (t *Chunk[T]) Tiles() [][]T

This returns the underlying array, not a copy TODO - should I just make tiles public?

func (*Chunk[T]) Width

func (t *Chunk[T]) Width() int

type ChunkMath

type ChunkMath struct {
	// contains filtered or unexported fields
}

func NewChunkmath

func NewChunkmath(chunkSize int, tileSize int) ChunkMath

func (*ChunkMath) ChunkToTile

func (c *ChunkMath) ChunkToTile(chunkPos ChunkPosition) TilePosition

Returns the center tile of a chunk

func (*ChunkMath) GetChunkEdgeNeighbors

func (c *ChunkMath) GetChunkEdgeNeighbors(pos ChunkPosition) []ChunkPosition

func (*ChunkMath) GetChunkTileRect

func (c *ChunkMath) GetChunkTileRect(chunkPos ChunkPosition) Rect

func (*ChunkMath) GetEdgeNeighbors

func (c *ChunkMath) GetEdgeNeighbors(x, y int) []TilePosition

func (*ChunkMath) GetNeighbors

func (c *ChunkMath) GetNeighbors(pos TilePosition) []TilePosition

func (*ChunkMath) GetOverlappingTiles

func (t *ChunkMath) GetOverlappingTiles(x, y float64, collider *phy2.CircleCollider) []TilePosition

Returns a list of tiles that are overlapping the collider at a position

func (*ChunkMath) GetOverlappingTiles2

func (t *ChunkMath) GetOverlappingTiles2(ret []TilePosition, x, y float64, radius float64) []TilePosition

func (*ChunkMath) PositionToChunk

func (c *ChunkMath) PositionToChunk(x, y float64) ChunkPosition

func (*ChunkMath) PositionToTile

func (c *ChunkMath) PositionToTile(x, y float64) TilePosition

func (*ChunkMath) PositionToTile2

func (c *ChunkMath) PositionToTile2(pos phy2.Vec) TilePosition

func (*ChunkMath) RectToWorldRect

func (c *ChunkMath) RectToWorldRect(r Rect) phy2.Rect

Returns a rect including all of the tiles. Centered on edge tiles

func (*ChunkMath) TileToChunk

func (c *ChunkMath) TileToChunk(tilePos TilePosition) ChunkPosition

func (*ChunkMath) TileToChunkLocalPosition

func (c *ChunkMath) TileToChunkLocalPosition(tilePos Position) phy2.Vec

Note: untested

func (*ChunkMath) TileToPosition

func (c *ChunkMath) TileToPosition(tilePos TilePosition) phy2.Vec

func (*ChunkMath) ToPosition

func (c *ChunkMath) ToPosition(chunkPos ChunkPosition) phy2.Vec

Returns the worldspace position of a chunk

type ChunkPosition

type ChunkPosition struct {
	X, Y int16
}

type Chunkmap

type Chunkmap[T any] struct {
	ChunkMath
	// contains filtered or unexported fields
}

func NewChunkmap

func NewChunkmap[T any](math ChunkMath) *Chunkmap[T]

func (*Chunkmap[T]) AddChunk

func (c *Chunkmap[T]) AddChunk(chunkPos ChunkPosition, tiles [][]T) *Chunk[T]

func (*Chunkmap[T]) AddTile

func (c *Chunkmap[T]) AddTile(pos TilePosition, tile T)

Adds a tile at the position, if the chunk doesnt exist, then it will be created

func (*Chunkmap[T]) Bounds

func (c *Chunkmap[T]) Bounds() Rect

func (*Chunkmap[T]) BreadthFirstSearch

func (c *Chunkmap[T]) BreadthFirstSearch(tilePos TilePosition, valid func(t T) bool) []TilePosition

func (*Chunkmap[T]) CalculateBlobmapVariant

func (c *Chunkmap[T]) CalculateBlobmapVariant(pos TilePosition, same func(a T, b T) bool) uint8

func (*Chunkmap[T]) CalculatePipemapVariant

func (c *Chunkmap[T]) CalculatePipemapVariant(pos TilePosition, same func(a T, b T) bool) uint8

func (*Chunkmap[T]) CalculateRawEightVariant

func (c *Chunkmap[T]) CalculateRawEightVariant(pos TilePosition, same func(a T, b T) bool) uint8

func (*Chunkmap[T]) GenerateChunk

func (c *Chunkmap[T]) GenerateChunk(chunkPos ChunkPosition, expansionLambda func(x, y int) T) *Chunk[T]

This generates a chunk based on the passed in expansionLambda

func (*Chunkmap[T]) GetAllChunkPositions

func (c *Chunkmap[T]) GetAllChunkPositions() []ChunkPosition

func (*Chunkmap[T]) GetAllChunks

func (c *Chunkmap[T]) GetAllChunks() []*Chunk[T]

TODO - It might be cool to have a function which returns a rectangle of chunks as a list (To automatically cull out sections we don't want)

func (*Chunkmap[T]) GetChunk

func (c *Chunkmap[T]) GetChunk(chunkPos ChunkPosition) (*Chunk[T], bool)

func (*Chunkmap[T]) GetEightNeighbors

func (c *Chunkmap[T]) GetEightNeighbors(pos TilePosition) (T, T, T, T, T, T, T, T)

func (*Chunkmap[T]) GetNeighborsAtDistance

func (c *Chunkmap[T]) GetNeighborsAtDistance(tilePos TilePosition, dist int) []TilePosition

func (*Chunkmap[T]) GetPerimeter

func (c *Chunkmap[T]) GetPerimeter() map[ChunkPosition]bool

func (*Chunkmap[T]) GetTile

func (c *Chunkmap[T]) GetTile(pos TilePosition) (T, bool)

func (*Chunkmap[T]) NumChunks

func (c *Chunkmap[T]) NumChunks() int

func (*Chunkmap[T]) SetTile

func (c *Chunkmap[T]) SetTile(pos TilePosition, tile T) bool

Tries to set the tile, returns false if the chunk does not exist

type FlatRectMath

type FlatRectMath struct {
	// contains filtered or unexported fields
}

func NewFlatRectMath

func NewFlatRectMath(size [2]int) FlatRectMath

func (FlatRectMath) Position

func (m FlatRectMath) Position(x, y int) (float64, float64)

func (FlatRectMath) PositionToTile

func (m FlatRectMath) PositionToTile(x, y float64) (int, int)

type Math

type Math interface {
	Position(x, y int, size [2]int) (float64, float64)
	PositionToTile(x, y float64, size [2]int) (int, int)
}

type PointyRectMath

type PointyRectMath struct{}

func (PointyRectMath) Position

func (t PointyRectMath) Position(x, y int, size [2]int) (float64, float64)

func (PointyRectMath) PositionToTile

func (t PointyRectMath) PositionToTile(x, y float64, size [2]int) (int, int)

type Position

type Position struct {
	X, Y int
}

func (Position) Add

func (t Position) Add(v Position) Position

func (Position) Div

func (t Position) Div(val int) Position

func (Position) Manhattan

func (t Position) Manhattan() int

func (Position) Maximum

func (t Position) Maximum() int

func (Position) Sub

func (t Position) Sub(v Position) Position

type Rect

type Rect struct {
	Min, Max Position
}

func R

func R(minX, minY, maxX, maxY int) Rect

func (Rect) Area

func (r Rect) Area() int

func (Rect) Center

func (r Rect) Center() Position

func (Rect) Contains

func (r Rect) Contains(pos Position) bool

func (Rect) H

func (r Rect) H() int

func (Rect) Intersects

func (r Rect) Intersects(r2 Rect) bool

func (Rect) Iter

func (r Rect) Iter() []Position

TODO! - Replace with actual iterator pattern

func (Rect) Moved

func (r Rect) Moved(v Position) Rect

func (Rect) Norm

func (r Rect) Norm() Rect

func (Rect) PadAll

func (r Rect) PadAll(pad int) Rect

func (Rect) Union

func (r Rect) Union(s Rect) Rect

func (Rect) UnpadAll

func (r Rect) UnpadAll(pad int) Rect

func (Rect) W

func (r Rect) W() int

func (Rect) WithCenter

func (r Rect) WithCenter(v Position) Rect

type TilePosition

type TilePosition = Position

type Tilemap

type Tilemap[T any] struct {
	TileSize [2]int // In pixels

	Offset phy2.Vec2 // In world space positioning
	// contains filtered or unexported fields
}

func New

func New[T any](tiles [][]T, tileSize [2]int, math Math) *Tilemap[T]

func (*Tilemap[T]) BoundsAt

func (t *Tilemap[T]) BoundsAt(pos Position) (float64, float64, float64, float64)

TODO - this might not work for pointy-top tilemaps

func (*Tilemap[T]) GetEdgeNeighbors

func (t *Tilemap[T]) GetEdgeNeighbors(x, y int) []Position

func (*Tilemap[T]) GetOverlappingTiles

func (t *Tilemap[T]) GetOverlappingTiles(x, y float64, collider *phy2.CircleCollider) []Position

Returns a list of tiles that are overlapping the collider at a position

func (*Tilemap[T]) GetTile

func (t *Tilemap[T]) GetTile(pos Position) (T, bool)

func (*Tilemap[T]) Height

func (t *Tilemap[T]) Height() int

func (*Tilemap[T]) PositionToTile

func (t *Tilemap[T]) PositionToTile(x, y float64) Position

func (*Tilemap[T]) SetTile

func (t *Tilemap[T]) SetTile(pos Position, tile T) bool

func (*Tilemap[T]) TileToPosition

func (t *Tilemap[T]) TileToPosition(tilePos Position) (float64, float64)

func (*Tilemap[T]) Tiles

func (t *Tilemap[T]) Tiles() [][]T

This returns the underlying array, not a copy TODO - should I just make tiles public?

func (*Tilemap[T]) Width

func (t *Tilemap[T]) Width() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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