snake

package
v0.0.0-...-3fd9c7e Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UP is the Direction defining travel towards the top of the game area.
	UP = Direction{pixel.V(0, 1)}
	// DOWN is the Direction defining travel towards the bottom of the game area.
	DOWN = Direction{pixel.V(0, -1)}
	// LEFT is the Direction defining travel towards the left of the game area.
	LEFT = Direction{pixel.V(-1, 0)}
	// RIGHT is the Direction defining travel towards the right of the game area.
	RIGHT = Direction{pixel.V(1, 0)}
	// NOCHANGE is a blank Direction, it can be used to not alter the current heading.
	NOCHANGE = Direction{pixel.V(0, 0)}
)

Functions

This section is empty.

Types

type Direction

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

Direction is used to define the direction the snake is heading

type Type

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

Type is a struct which represents a snake in the game

func NewSnake

func NewSnake(gameCFG game.Config) Type

NewSnake returns an initialised snake

func (*Type) CheckIfSnakeHasEaten

func (s *Type) CheckIfSnakeHasEaten(gameCFG *game.Config, berry pixel.Vec) bool

CheckIfSnakeHasEaten is used to check the snake has easten the berry

func (*Type) CheckSnakeOK

func (s *Type) CheckSnakeOK(gameCFG *game.Config) bool

CheckSnakeOK is used to check the snake hasn't exicted the game area and has not hit itself

func (*Type) GetHeadPos

func (s *Type) GetHeadPos() pixel.Vec

GetHeadPos returns the position of the head of the snake in the game area coordinate plane

func (*Type) GetPositionPoints

func (s *Type) GetPositionPoints() []pixel.Vec

GetPositionPoints returns the list of the snakes previous turn positions in the game area coordinate plane

func (*Type) GetSpeed

func (s *Type) GetSpeed() float64

GetSpeed returns the snake speed multiplier

func (*Type) GetTailPos

func (s *Type) GetTailPos() pixel.Vec

GetTailPos returns the position of the tail of the snake in the game area coordinate plane

func (*Type) GetTicker

func (s *Type) GetTicker() <-chan time.Time

GetTicker returns the snake speed ticker

func (*Type) IncreaseSpeed

func (s *Type) IncreaseSpeed()

IncreaseSpeed increase the speed of the snake

func (*Type) StartOfGame

func (s *Type) StartOfGame(dir Direction)

StartOfGame is used to allow the starting of the game with the arrow keys to choose the initial direction of the snake.

func (*Type) Update

func (s *Type) Update(eaten bool, dir Direction)

Update is used to Update the status of snake position and speed.

Jump to

Keyboard shortcuts

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