game

package
Version: v0.0.0-...-de2d1a5 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2018 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package game provides the cat-o-licious game.

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	FPS:         30,
	Width:       800,
	Height:      600,
	PlayerSpeed: 20,
}

DefaultConfig is the game's default configuration.

View Source
var DefaultPlayerHitSquare = struct{ X, Y, W, H, FlipOffset float32 }{
	X:          .4,
	Y:          .8,
	W:          .3,
	H:          .15,
	FlipOffset: .1,
}

DefaultPlayerHitSquare defines the hit square within the player image, in percentages.

View Source
var DefaultPlayerSide = Right

DefaultPlayerSide configures the default facing side of the player.

View Source
var Version = "tip"

Version is the version of the game engine.

Functions

func Run

func Run(c *Config) error

Run runs the game with the given config, which is optional. The nil config uses DefaultConfig.

Types

type Config

type Config struct {
	// FPS is the rendering rate of the game. It cannot be changed.
	FPS int

	// Width is the initial width for the game window.
	Width int

	// Height is the initial height of the game window.
	Height int

	// PlayerSpeed is the speed of the player's lateral movement.
	PlayerSpeed int
}

Config is the game configuration.

type Direction

type Direction int

Direction is the player's lateral movement direction.

const (
	Center Direction = iota
	Left
	Right
)

Player's lateral movement.

type Drop

type Drop interface {
	// Pos returns the position of the drop in the viewport.
	Pos() sdl.Rect

	// Points returns delta points for the drop. Good drops
	// return positive numbers while bad drops return negative.
	Points() int64
}

Drop is a single drop of rain.

type Engine

type Engine interface {
	// Run runs the engine. Blocks until Q is pressed.
	Run()
}

Engine is the game engine.

func NewEngine

func NewEngine(c *Config) (Engine, error)

NewEngine creates and initializes a new game engine.

type Image

type Image interface {
	// Size returns the image size.
	Size() (w, h int32)

	// Texture returns the SDL image texture.
	Texture() *sdl.Texture
}

Image is a wrapper for SDL images.

func NewImageFromFile

func NewImageFromFile(r *sdl.Renderer, file string) (Image, error)

NewImageFromFile loads an image from file.

func NewImageSetFromFiles

func NewImageSetFromFiles(r *sdl.Renderer, prefix string) ([]Image, error)

NewImageSetFromFiles loads a sequence of images with the same prefix. The format is {prefix}{n}.png where N starts from 1. At least one image must exist otherwise an error is returned.

type Player

type Player interface {
	// Move moves the player.
	Move(d Direction, steps int32)

	// Hit returns true when the given drop's area intersects
	// with the player's hit area. This is when you make points.
	Hit(d Drop) bool

	// Draw draws the player.
	Draw(viewport *sdl.Rect)
}

Player is a game player.

func NewPlayer

func NewPlayer(r *sdl.Renderer) (Player, error)

NewPlayer creates and initializes a new player.

type Rain

type Rain interface {
	// SetRate sets the rate of drops per second.
	SetRate(n int)

	// Drops returns all raindrops from the rain.
	Drops() []Drop

	// Draw draws the rain.
	Draw(now time.Time, viewport *sdl.Rect)
}

Rain makes objects (raindrops) fall from the top of the viewport all the way to the bottom.

func NewRain

func NewRain(r *sdl.Renderer) (Rain, error)

NewRain creates and initializes a Rain object.

type Scene

type Scene interface {
	// Player returns the game player so callers can control
	// its lateral movement.
	Player() Player

	// Draw draws the scene.
	Draw(now time.Time, viewport *sdl.Rect)
}

Scene is the game scene. It contains the background image, scoreboard, player, rain, and sound.

func NewScene

func NewScene(r *sdl.Renderer) (Scene, error)

NewScene creates and initializes the game scene.

type Scoreboard

type Scoreboard interface {
	// Add adds the given delta to the player's score.
	Add(delta int64)

	// Points returns the current player's points.
	Points() int64

	// Draw draws the scoreboard.
	Draw(viewport *sdl.Rect)
}

Scoreboard tracks the player's score and draws the scoreboard.

func NewScoreboard

func NewScoreboard(r *sdl.Renderer) (Scoreboard, error)

NewScoreboard creates and initializes a new scoreboard.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto