render

package
v0.0.0-...-e8051b5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASCIIEmpty     = " "
	ASCIIFood      = "*"
	ASCIISnakeHead = "H"
	ASCIISnakeBody = "O"
	ASCIISnakeTail = "T"
	ASCIIHazard    = "."
)
View Source
const (
	GIFFrameDelay        = 8
	GIFLoopDelay         = 200
	GIFMaxColorsPerFrame = 256
)
View Source
const (
	BoardBorder        float64 = 2
	SquareBorderPixels float64 = 1
	ColorEmptySquare           = "#f0f0f0"
	ColorFood                  = "#ff5c75"
	ColorHazard                = "#00000066"
)
View Source
const ColorDeadSnake = "#cdcdcd"

ColorDeadSnake is the default hex colour used for displaying snakes that have died

Variables

View Source
var ErrInvalidAvatarSettings = errors.New("invalid avatar settings")

Functions

func AvatarSVG

func AvatarSVG(settings AvatarSettings) (string, error)

func DrawBoard

func DrawBoard(b *Board, imageWidth, imageHeight int) image.Image

DrawBoard draws the given board data into an image. Width and height values are in pixels. If the image width/height is invalid (<= 0) a valid width/height is calculated using the number of squares in the board.

func GameFrameToASCII

func GameFrameToASCII(w io.Writer, g *engine.Game, gf *engine.GameFrame) error

func GameFrameToGIF

func GameFrameToGIF(w io.Writer, g *engine.Game, gf *engine.GameFrame, width, height int) error

func GameFramesToAnimatedGIF

func GameFramesToAnimatedGIF(w io.Writer, g *engine.Game, gameFrames []*engine.GameFrame, frameDelay, loopDelay, width, height int) error

Types

type AvatarSettings

type AvatarSettings struct {
	Height  int
	Width   int
	HeadSVG string
	TailSVG string
	Color   string
}

func (AvatarSettings) CalculateBodyWidth

func (a AvatarSettings) CalculateBodyWidth() int

func (AvatarSettings) CalculateHeadOffset

func (a AvatarSettings) CalculateHeadOffset() int

func (AvatarSettings) CopyrightNotice

func (a AvatarSettings) CopyrightNotice() string

func (AvatarSettings) Validate

func (a AvatarSettings) Validate() bool

type Board

type Board struct {
	Width  int
	Height int
	// contains filtered or unexported fields
}

Board is the root datastructure that represents a game board

func GameFrameToBoard

func GameFrameToBoard(g *engine.Game, gf *engine.GameFrame) *Board

func NewBoard

func NewBoard(w int, h int) *Board

type BoardSquare

type BoardSquare struct {
	Contents []BoardSquareContent
}

BoardSquare represents a unique location on the game board.

type BoardSquareContent

type BoardSquareContent struct {
	Type      BoardSquareContentType
	Color     color.Color
	SnakeType string
	Direction snakeDirection
	Corner    snakeCorner
}

BoardSquareContent represents a single piece of content in a single square of the game board. Examples of content are food, snake body parts and hazard squares

type BoardSquareContentType

type BoardSquareContentType int

BoardSquareContentType works like an enum. It provides a restricted set of types of content that can be placed in a board square.

const (
	BoardSquareFood BoardSquareContentType = iota
	BoardSquareSnakeBody
	BoardSquareSnakeHead
	BoardSquareSnakeTail
	BoardSquareHazard
)

Directories

Path Synopsis
Package gif implements a GIF image decoder and encoder.
Package gif implements a GIF image decoder and encoder.

Jump to

Keyboard shortcuts

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