engine

package
v0.0.0-...-09bd2b9 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Holes      = 5
	Snakes     = 3
	Carrots    = 2
	LawnLength = 7
	LawnArea   = LawnLength * LawnLength
)

constants that set core game values

Variables

This section is empty.

Functions

This section is empty.

Types

type Garden

type Garden struct {
	Lawn *[LawnArea]Grass

	Score int
	Dead  bool
	// contains filtered or unexported fields
}

Garden stores main info for game to be played

func NewGame

func NewGame() *Garden

NewGame initializes a new Garden

func (*Garden) HandleKey

func (ga *Garden) HandleKey(key string) bool

HandleKey handles key press and returns wether key was valid input

func (*Garden) MoveSnakes

func (ga *Garden) MoveSnakes()

MoveSnakes moves all snake positions by one grass

func (*Garden) ScaleOffset

func (ga *Garden) ScaleOffset(len float32)

ScaleOffset rescales offset values when window size changes

func (*Garden) Update

func (ga *Garden) Update() [2]int

Update should be called after every gopher movement and snake movement. Update updates Garden state, for ex: if snake is on same square as gopher, gopher is dead and game is over. Update also returns the 2 Grass inds which need to be updated

type Grass

type Grass struct {
	Off    f32.Point
	Snake  entity
	Player entity
	Carrot bool
	Hole   bool
}

Grass holds all possible info for single grass block

Jump to

Keyboard shortcuts

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