game

package
v0.0.0-...-93e07d4 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearPixels

func ClearPixels(pixels []byte)

ClearPixels resets/clears the pixel buffer

func Init

func Init(windowWidth, windowHeight int)

Init initializes the game library with the given window width and height

func InitState

func InitState()

InitState is a helper to initialize the game state to the start state

func Lerp

func Lerp(a, b, percent float32) float32

Lerp is the linear interpolation between point a and b

func Scores

func Scores() [][]byte

Scores returns a slice of byte slice(scores represented as bits)

func SetState

func SetState(newState State)

SetState updates the current game state with the newState

func SetupControllers

func SetupControllers() []*sdl.GameController

SetupControllers setups game controllers/joysticks and returns the list of game controllers attached

Types

type Ball

type Ball struct {
	Pos
	// contains filtered or unexported fields
}

Ball represents the ball in the pong game

func NewBall

func NewBall(pos Pos, radius, xVelocity, yVelocity float32, color Color) *Ball

NewBall creates an instance of a Ball

func (*Ball) Draw

func (b *Ball) Draw(pixels []byte)

Draw renders the ball in the pixels buffer

func (*Ball) Update

func (b *Ball) Update(leftPaddle, rightPaddle *Paddle, elapsedTime float32)

Update updates the position of the ball based on collision with paddles

type Color

type Color struct {
	R, G, B byte
}

Color is the RGB color of a pixel

type Object

type Object interface {
	Draw()
}

Object is an interface to game objects like paddle, ball, score etc

type Paddle

type Paddle struct {
	Pos
	// contains filtered or unexported fields
}

Paddle represents the paddle in the pong game

func NewPaddle

func NewPaddle(pos Pos, w, h, speed float32, score Score, color Color) *Paddle

NewPaddle creates an instance of a Paddle

func (*Paddle) AIUpdate

func (p *Paddle) AIUpdate(ball *Ball, elapsedTime float32)

AIUpdate updates the position of the paddle based on the AI move

func (*Paddle) Draw

func (p *Paddle) Draw(pixels []byte)

Draw renders the paddle in the pixels buffer

func (*Paddle) GetScore

func (p *Paddle) GetScore() Score

GetScore returns the current score of this player/paddle

func (*Paddle) ResetScore

func (p *Paddle) ResetScore()

ResetScore resets the paddle/player score to zero

func (*Paddle) Update

func (p *Paddle) Update(keyboardStates []uint8, controllerAxis int16, elapsedTime float32)

Update updates the position of the paddle based on input(up/down) from the keyboard

type Pos

type Pos struct {
	X, Y float32
}

Pos represents an object position in a 2D space

func GetCenter

func GetCenter() Pos

GetCenter returns the center position of the window

type Score

type Score int

Score represents a player score

func (Score) Draw

func (s Score) Draw(pos Pos, color Color, size int, pixels []byte)

Draw renders the score in the pixels buffer

type State

type State uint

State is an unsigned integer that represents the various game states

const (
	// Unknown is the uninitialized game state
	Unknown State = iota
	// StateStart game state
	StateStart
	// StatePlay game state
	StatePlay
)

func GetState

func GetState() State

GetState returns the current game state. It returns the Unknown state if the game state has not been initialized

Jump to

Keyboard shortcuts

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