scene

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package scene stores definitions for interacting with game loop scenes

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fade

func Fade(rate float32, frames int) func(*image.RGBA, int) bool

Fade is a scene transition that fades to black at a given rate for a total of 'frames' frames

func Zoom

func Zoom(xPerc, yPerc float64, frames int, zoomRate float64) func(*image.RGBA, int) bool

Zoom transitions by performing a simplistic zoom each frame towards some percentange-based part of the screen.

Types

type End

type End func() (string, *Result)

End is a function returning the next scene and a SceneResult of input settings for the next scene.

func GoTo

func GoTo(nextScene string) End

GoTo returns an End function that, without any other customization possible, will change to the input next scene.

func GoToPtr

func GoToPtr(nextScene *string) End

GoToPtr returns an End function that, without any other customization possible, will change to the input next scene. It takes a pointer so the scene can be changed after this function is called.

type Loop

type Loop func() bool

Loop is a function that returns whether or not the current scene should continue to loop.

func BooleanLoop

func BooleanLoop(b *bool) Loop

BooleanLoop returns a Loop function that will end a scene as soon as the input boolean is false, resetting it to true in the process for the next scene

type Map

type Map struct {
	CurrentScene string
	// contains filtered or unexported fields
}

A Map lets scenes be accessed via associated names.

func NewMap

func NewMap() *Map

NewMap creates a scene map

func (*Map) Add

func (m *Map) Add(name string, start Start, loop Loop, end End) error

Add adds a scene with the given name and functions to the scene map. It serves as a helper for not constructing a scene directly.

func (*Map) AddScene

func (m *Map) AddScene(name string, s Scene) error

AddScene takes a scene struct, checks that its assigned name does not conflict with an existing name in the map, and then adds it to the map. If a conflict occurs, the scene will not be overwritten. Checks if the Scene's start is nil, sets to noop if so. Checks if the Scene's loop is nil, sets to infinite if so. Checks if the Scene's end is nil, sets to loop to this scene if so. Todo: this could change, with a function argument specifying whether or not the scene should overwrite.

func (*Map) Get

func (m *Map) Get(name string) (Scene, bool)

Get returns the scene associated with the given name, if it exists. If it does not exist, it returns a zero value and false.

func (*Map) GetCurrent

func (m *Map) GetCurrent() (Scene, bool)

GetCurrent returns the current scene, as defined by map.CurrentScene

Example
package main

import (
	"fmt"

	"github.com/oakmound/oak/v2/scene"
)

func main() {
	m := scene.NewMap()
	sc := scene.Scene{
		Start: func(prevScene string, data interface{}) {
			fmt.Println("Starting screen one")
		},
	}
	m.AddScene("screen1", sc)
	m.CurrentScene = "screen2"
	_, ok := m.GetCurrent()
	if !ok {
		fmt.Println("Screen two did not exist")
	}
	m.CurrentScene = "screen1"
	sc, ok = m.GetCurrent()
	if !ok {
		fmt.Println("Screen one did not exist")
	} else {
		sc.Start("screen0", nil)
	}
}
Output:

Screen two did not exist
Starting screen one

type Result

type Result struct {
	NextSceneInput interface{}
	Transition
}

A Result is a set of options for what should be passed into the next scene and how the next scene should be transitioned to.

type Scene

type Scene struct {
	Start
	Loop
	End
}

A Scene is a set of functions defining what needs to happen when a scene starts, loops, and ends.

type Start

type Start func(prevScene string, data interface{})

Start is a function taking in a previous scene and a payload of data from the previous scene's end.

type Transition

type Transition func(*image.RGBA, int) bool

Transition functions can be set to occur at the end of a scene.

Jump to

Keyboard shortcuts

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