game

package
v0.2.66 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 18 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 DisableCRT bool

DisableCRT bypasses the CRT effect.

View Source
var DrawButtons bool

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

View Source
var SuperSpeed bool

SuperSpeed runs the game at the maximum possible frame rate.

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 CRT

type CRT struct {
	NoiseX          float64
	Offset          [2]float64
	RGBNoise        float64
	SineNoiseWidth  float64
	SineNoiseScale  float64
	SineNoiseOffset float64
	ScanLineTail    float64
	ScanLineSpeed   float64
	ScreenSize      float64
	Darkening       float64
	ScanLineDarker  float64
	ScanLineDarker2 float64
	FadeOut         float64
}

CRT is a screen-space graphical filter.

func (*CRT) Draw

func (c *CRT) Draw(render func())

Draw renders a frame.

func (*CRT) SetDefaults

func (c *CRT) SetDefaults()

SetDefaults sets the CRT settings to their default values.

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

	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 ...arcade.Button)

AIForceButtons forces the AI to hold a set of buttons.

func (*State) AISpamButton

func (s *State) AISpamButton(btn arcade.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(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 arcade.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