game

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package game holds the shared code for Termacade games.

Index

Constants

View Source
const (
	// FrameRate is the number of frames per second at which the Termacade runs.
	FrameRate = 60
	// FrameTime is the reciprocal of FrameRate.
	FrameTime = time.Second / FrameRate
)

Variables

View Source
var AIEnabled bool

AIEnabled causes a neural network to play the game rather than the player.

View Source
var DrawButtons bool

DrawButtons causes buttons pressed in a game to be displayed on the screen.

View Source
var SuperSpeed bool

SuperSpeed causes the game to run as many ticks as possible per rendered frame.

Functions

func Lerp

func Lerp(x, y, blend float64) float64

Lerp linearly interpolates between x and y.

func Lerp32

func Lerp32(x, y, blend float32) float32

Lerp32 linearly interpolates between x and y.

Types

type AIConfig

type AIConfig struct {
	NumInput         int
	Press, Toggle    []WeightedButton
	PositionOverride []int
	InputDesc        []AIInputDesc
}

AIConfig is the configuration for the AI.

type AIInputDesc

type AIInputDesc struct {
	Name string
	Min  float64
	Max  float64
	Enum map[float64]color.RGBA
}

AIInputDesc describes an input to the AI.

type CreateFunc

type CreateFunc func(*State) Interface

CreateFunc allocates structures for game-specific logic.

type Interface

type Interface interface {
	Type() arcade.Game
	Rules() arcade.GameRules
	HighScore() float64

	Init(context.Context) error
	Generate(context.Context, func(percent int)) error
	StartGameplay(context.Context) error
	Logic(context.Context) error
	Render()
	Cleanup(context.Context) error

	RenderAttract(progress int, fadeIn, fadeOut bool)
	StartPressed()
	StartMusic()

	InitAI() *AIConfig
	AIInput() (input []float64, reward float64)

	SaveState() interface{}
	LoadState(interface{})
}

Interface is the set of methods implemented by each Termacade game.

type SavedState

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

SavedState is a snapshot of State.

type State

type State struct {
	TickCount uint64
	Score     float64
	Seed      string

	RNG       *rng.RNG
	Interface Interface
	Input     *input.Context
	Camera    gfx.Camera
	CRT       crt.CRT

	Playback      *arcade.Recording
	PlaybackInput *input.Context

	Exit bool
	// contains filtered or unexported fields
}

State holds the state of a Termacade game.

func PlayRecording

func PlayRecording(ctx context.Context, create CreateFunc, rec *arcade.Recording) (*State, error)

PlayRecording replays a recorded playthrough of a game.

func RunGame

func RunGame(ctx context.Context, create CreateFunc, seed string) (*State, error)

RunGame presents a game to the player.

func (*State) AIClearButtons

func (s *State) AIClearButtons()

AIClearButtons returns control of the input to the AI.

func (*State) AIForceButtons

func (s *State) AIForceButtons(buttons ...input.Button)

AIForceButtons forces the AI to hold a set of buttons.

func (*State) AISpamButton

func (s *State) AISpamButton(btn input.Button)

AISpamButton forces the AI to press a button every other frame.

func (*State) ComputeWait

func (s *State) ComputeWait(seconds float64) uint64

ComputeWait determines the number of ticks to wait.

func (*State) DrawButtons

func (s *State) DrawButtons(tb *sprites.Batch, x, y, z, scale float32)

DrawButtons displays the currently-held buttons on the screen.

func (*State) Fade

func (s *State) Fade(target, amount float64)

Fade sets the fade target (usually 0 or 1) and the fade rate per frame.

func (*State) FadeTo

func (s *State) FadeTo(target float64)

FadeTo sets the fade target (usually 0 or 1).

func (*State) FinalizeRecording

func (s *State) FinalizeRecording()

FinalizeRecording does bookkeeping to finish the game recording.

func (*State) Load

func (s *State) Load(saved *SavedState)

Load replaces State with a recorded snapshot.

func (*State) Save

func (s *State) Save() *SavedState

Save records a snapshot of State.

type WeightedButton

type WeightedButton struct {
	Button input.Button
	Weight float64
}

WeightedButton is a button with a weight (1 is normal).

Jump to

Keyboard shortcuts

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