object

package
v0.0.0-...-bbac6e9 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// FontUbuntu filename of ubuntu font in the resources
	FontUbuntu string = "ubuntu.ttf"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Apple

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

Apple is the game object

func NewApple

func NewApple() *Apple

NewApple creates new Apple with default values

func (Apple) Paint

func (a Apple) Paint(d grafio.Drawer) error

Paint paints Apple to the given renderer

func (*Apple) Update

func (a *Apple) Update() GameState

Update check is Apple is eaten and changes the state of Apple coordinates

type DeadScreen

type DeadScreen struct {
	Score  *Score
	Font   ttf.Font
	Screen GameScreen
	// contains filtered or unexported fields
}

DeadScreen object of game which can be painted

func (*DeadScreen) HandleEvent

func (ds *DeadScreen) HandleEvent(event sdl.Event)

HandleEvent handle event from the input devices and manages the state

func (DeadScreen) Paint

func (ds DeadScreen) Paint(d grafio.Drawer) error

Paint paints text and Score to renderer

func (*DeadScreen) Update

func (ds *DeadScreen) Update() GameState

Update update dead screen and gives game state

type GameScreen

type GameScreen struct {
	W, H int32
}

GameScreen have struct of width and height of screen

type GameState

type GameState int

GameState game current action

const (
	// SnakeRunning state when the Snake is running/moving and it's not the end yet
	SnakeRunning GameState = iota

	// DeadSnake state when Snake touches something and dies and need to show dead screen
	DeadSnake

	// MenuScreen state when There's menu shown for setting and entering into game
	MenuScreen
)

type Handleable

type Handleable interface {
	HandleEvent(event sdl.Event)
}

Handleable it can handle input from sdl events

type Paintable

type Paintable interface {
	Paint(d grafio.Drawer) error
}

Paintable paints something to sdl renderer

type Score

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

Score the game object

func NewScore

func NewScore() *Score

NewScore creates Score with default and given values

func (*Score) Increase

func (s *Score) Increase()

Increase increased the amount of Score

func (Score) Paint

func (s Score) Paint(d grafio.Drawer) error

Paint the score number to renderer to the corner

type Snake

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

Snake game object

func NewSnake

func NewSnake(a *Apple, s *Score, scr GameScreen) *Snake

NewSnake create Snake struct with default and given values

func (*Snake) HandleEvent

func (s *Snake) HandleEvent(event sdl.Event)

HandleEvent handles the movement of snake

func (*Snake) Paint

func (s *Snake) Paint(d grafio.Drawer) error

Paint paints snake to renderer

func (*Snake) Update

func (s *Snake) Update() GameState

Update updates the snake ar gives the GameState

type Updateable

type Updateable interface {
	Update() GameState
}

Updateable object data can or should be updated every each frame with certain information in function

type WelcomeText

type WelcomeText struct {
	Screen GameScreen
	Snake  *Snake
	// contains filtered or unexported fields
}

WelcomeText object of showing welcome text

func (*WelcomeText) HandleEvent

func (wt *WelcomeText) HandleEvent(event sdl.Event)

HandleEvent handles events from input devices

func (WelcomeText) Paint

func (wt WelcomeText) Paint(d grafio.Drawer) error

Paint paints text and Score to renderer

func (*WelcomeText) Update

func (wt *WelcomeText) Update() GameState

Update updates snake and chooses game state to return

Jump to

Keyboard shortcuts

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