Documentation ¶
Index ¶
- Variables
- func CheckSelectedColor(c int) tl.Attr
- func Gameover()
- func RandomFood() rune
- func RandomInsideArena(iMax int, iMin int) int
- func RestartGame()
- func SaveHighScore(score int, speed float64, difficulty string)
- func SetDiffiultyFPS()
- func StartGame()
- func UpdateFPS()
- func UpdateScore(amount int)
- type Arena
- type Coordinates
- type Food
- type Gameoptionsscreen
- type Gameoverscreen
- type Gamescreen
- type Sidepanel
- type Snake
- type Titlescreen
Constants ¶
This section is empty.
Variables ¶
var ColorObject = "Snake"
var Difficulty = "Normal"
Game options
Functions ¶
func CheckSelectedColor ¶
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 ¶
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 SetDiffiultyFPS ¶
func SetDiffiultyFPS()
func UpdateScore ¶
func UpdateScore(amount int)
UpdateScore updates the score with the given amount of points.
Types ¶
type Arena ¶
func NewArena ¶
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.
type Coordinates ¶
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.
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 Logo *tl.Entity 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 ¶
BorderCollision checks if the arena border contains the snakes head, if so it will return true.
func (*Snake) Contains ¶
Contains checks if the snake contains the head of the snake, if so it will return true.
func (*Snake) Draw ¶
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 ¶
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 ¶
SnakeCollision checks if the snakes body contains its head, if so it will return true.
type Titlescreen ¶
type Titlescreen struct { tl.Level Logo *tl.Entity 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.