trisnake

package
v0.0.0-...-d2a2cfa Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColorObject = "Snake"
View Source
var Difficulty = "Normal"

Game options

Functions

func CheckSelectedColor

func CheckSelectedColor(c int) tl.Attr

func Gameover

func Gameover()

func RandomFood

func RandomFood() rune

RandomFood will use the ASCII-charset to pick a random rune from the slice and print it out as food.

func RandomInsideArena

func RandomInsideArena(iMax int, iMin int) int

RandomInsideArena will the minimal, which is just inside the border and the maximal, being the arena width or height.

func RestartGame

func RestartGame()

RestartGame will restart the game and reset the position of the food and the snake to prevent collision issues.

func SaveHighScore

func SaveHighScore(score int, speed float64, difficulty string)

func SetDiffiultyFPS

func SetDiffiultyFPS()

func StartGame

func StartGame()

StartGame will start the game with the tilescreen.

func UpdateFPS

func UpdateFPS()

UpdateFPS updates the fps text.

func UpdateScore

func UpdateScore(amount int)

UpdateScore updates the score with the given amount of points.

Types

type Arena

type Arena struct {
	*tl.Entity
	Width       int
	Height      int
	ArenaBorder map[Coordinates]int
}

func NewArena

func NewArena(w, h int) *Arena

NewArena will create a new arena with the arena with and arena height given when this function was called in game.go This function will create a arena using the arena struct that can be found in the types.go file.

func (*Arena) Contains

func (arena *Arena) Contains(c Coordinates) bool

Contains checks if the arenaborder map contains the coordinates of the snake, if so this will return true.

func (*Arena) Draw

func (arena *Arena) Draw(screen *tl.Screen)

Draw is a termloop function that will draw out the arena border, this is called when the game has started.

type Coordinates

type Coordinates struct {
	X int
	Y int
}

type Food

type Food struct {
	*tl.Entity
	Foodposition Coordinates
	Emoji        rune
}

func NewFood

func NewFood() *Food

NewFood will create a new piece of food, this will only happen once when the game has started.

func (*Food) Contains

func (food *Food) Contains(c Coordinates) bool

Contains checks if food contains the coordinates, if so this will return a bool.

func (*Food) Draw

func (food *Food) Draw(screen *tl.Screen)

Draw will print out the food on the screen.

func (*Food) MoveFood

func (food *Food) MoveFood()

MoveFood moves the food into a new random position.

type Gameoptionsscreen

type Gameoptionsscreen struct {
	tl.Level
	StartText *tl.Text

	CurrentColorObjectText *tl.Text
	ObjectBackground       *tl.Rectangle
	ColorObjectOptions     []*tl.Text

	CurrentDifficultyText *tl.Text
	DifficultyBackground  *tl.Rectangle
	DifficultyOptions     []*tl.Text

	ColorPanelBackground *tl.Rectangle
	ColorPanelOptions    []string
	ColorSelectedIcon    *tl.Text
}

func NewOptionsscreen

func NewOptionsscreen() *Gameoptionsscreen

func (*Gameoptionsscreen) Tick

func (g *Gameoptionsscreen) Tick(event tl.Event)

Tick will listen for a keypress to initiate the game.

type Gameoverscreen

type Gameoverscreen struct {
	tl.Level
	Finalstats        []*tl.Text
	OptionsBackground *tl.Rectangle
	OptionsText       []*tl.Text
}

func (*Gameoverscreen) Tick

func (gos *Gameoverscreen) Tick(event tl.Event)

Tick is a method for the gameoverscreen which listens for either a restart or a quit input from the user.

type Gamescreen

type Gamescreen struct {
	tl.Level
	FPS             float64
	Score           int
	SnakeEntity     *Snake
	FoodEntity      *Food
	ArenaEntity     *Arena
	SidepanelObject *Sidepanel
}

func NewGamescreen

func NewGamescreen() *Gamescreen

type Sidepanel

type Sidepanel struct {
	Background     *tl.Rectangle
	Instructions   []string
	ScoreText      *tl.Text
	SpeedText      *tl.Text
	DifficultyText *tl.Text
}

func NewSidepanel

func NewSidepanel() *Sidepanel

NewSidepanel will create a new sidepanel given the arena height and width.

type Snake

type Snake struct {
	*tl.Entity
	Direction  direction
	Length     int
	Bodylength []Coordinates
	Speed      int
}

func NewSnake

func NewSnake() *Snake

NewSnake will create a new snake and is called when the game is initialized.

func (*Snake) BorderCollision

func (snake *Snake) BorderCollision() bool

BorderCollision checks if the arena border contains the snakes head, if so it will return true.

func (*Snake) Contains

func (snake *Snake) Contains() bool

Contains checks if the snake contains the head of the snake, if so it will return true.

func (*Snake) Draw

func (snake *Snake) Draw(screen *tl.Screen)

Draw will check every tick and draw the snake on the screen, it also checks if the snake has any collisions using the funtions above.

func (*Snake) FoodCollision

func (snake *Snake) FoodCollision() bool

FoodCollision checks if the food contains the snakes head, if so it will return true.

func (*Snake) Head

func (snake *Snake) Head() *Coordinates

Head is the snake head which is used to move the snake around. The head is also the hitbox for food, border and the snake itself.

func (*Snake) SnakeCollision

func (snake *Snake) SnakeCollision() bool

SnakeCollision checks if the snakes body contains its head, if so it will return true.

func (*Snake) Tick

func (snake *Snake) Tick(event tl.Event)

Tick listens for a keypress and then returns a direction for the snake.

type Titlescreen

type Titlescreen struct {
	tl.Level
	GameDifficulty difficulty
	OptionsText    []*tl.Text
}

func NewTitleScreen

func NewTitleScreen() *Titlescreen

NewTitleScreen will create a new titlescreen and return it.

func (*Titlescreen) Tick

func (ts *Titlescreen) Tick(event tl.Event)

Tick will listen for a keypress to initiate the game.

Jump to

Keyboard shortcuts

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