grid

package
v0.0.0-...-c712ff3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package grid contains code for modeling a 2D grid, used as a game board in either orthogonal or isometric orientation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell interface {
	GridX() int
	GridY() int

	Dimensions() CellDimensions

	Color() uint32
	SetColor(uint32)
	Texture() *sdl.Texture
	SetTexture(*sdl.Texture)

	Elevation() int
	SetElevation(int)

	Contents() Occupier
	SetContents(Occupier)
	ClearContents()
	IsOccupied() bool
}

Cell is a container at a specific position inside a Grid.

type CellDimensions

type CellDimensions struct {
	X int
	Y int
	W int
	H int
}

CellDimensions stores the visual representation data for a cell. X and Y values are the number of pixels from (0,0). W and H are the pixel dimensions of the cell.

type Grid

type Grid interface {
	Width() int
	Height() int

	CellWidth() int
	CellHeight() int

	Cells() [][]Cell
	Cell(x, y int) Cell

	Checkerboard(color1, color2 uint32)
}

Grid is a two-dimensional array containing a game board which can be represented orthogonally or isometrically.

func NewGrid

func NewGrid(width, height, cellWidth, cellHeight int) Grid

NewGrid initializes and returns a Grid. `width` and `height` specify the dimensions of the grid itself. `cellWidth` and `cellHeight` specify the dimensions of cells within the grid.

type Occupier

type Occupier interface {
	CanOccupy() bool
}

Occupier is the common interface among anything which can occupy a cell within a grid. To place objects in a cell, have your objects satisfy this interface.

Jump to

Keyboard shortcuts

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