core

package
v0.0.0-...-a5929b7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DARKER_SHADER = "DARKER_SHADER"
View Source
const GRAYSCALE_SHADER = "DARKER_SHADER"
View Source
const INVERT_SHADER = "INVERT_SHADER"
View Source
const PALETTESWAPBRG_SHADER = "BRG_SHADER"
View Source
const SEPIA_SHADER = "SEPIA_SHADER"

Variables

View Source
var DarkerShader []byte
View Source
var (
	// the default font used for many things. Overwrite this var
	// to use different font
	DefaultFont font.Face
)
View Source
var GrayscaleShader []byte
View Source
var InvertShader []byte
View Source
var PaletteSwapBrgShader []byte
View Source
var SepiaShader []byte
View Source
var ShaderNotFoundError = errors.New("Shader Not Found")

Functions

This section is empty.

Types

type AnimatedImage

type AnimatedImage struct {
	*MovableImage
	SubImageStartX int
	SubImageStartY int

	SubImageWidth  int
	SubImageHeight int

	FrameCount int

	// Move to next frame everytime counter reach this number
	Modulo int

	Done func()
	// contains filtered or unexported fields
}

for image that do animation with frame

func (*AnimatedImage) Draw

func (e *AnimatedImage) Draw(screen *ebiten.Image)

func (*AnimatedImage) Update

func (a *AnimatedImage) Update()

type BGChangeEvent

type BGChangeEvent struct {

	// start position
	Sx float64
	Sy float64

	// target position
	Tx     float64
	Ty     float64
	Speed  float64
	Shader *ebiten.Shader
	// contains filtered or unexported fields
}

this event change background of the scene and animate it a bit

func (*BGChangeEvent) Execute

func (b *BGChangeEvent) Execute(scene *Scene)

type BranchingDialogueEvent

type BranchingDialogueEvent struct {
	Name            string
	SceneDataKey    string
	BranchingStruct map[string]string
}

create branching dialogue based on SceneDataKey. this code assume the value of SceneData is string if no matching string data is found it will show empty string

func (*BranchingDialogueEvent) Execute

func (b *BranchingDialogueEvent) Execute(scene *Scene)

type BranchingJumpEvent

type BranchingJumpEvent struct {
	SceneDataKey  string
	BranchingJump map[string]int
}

jump

func (*BranchingJumpEvent) Execute

func (c *BranchingJumpEvent) Execute(scene *Scene)

type Character

type Character struct {
	Name string
	Img  *MovableImage
}

func NewCharacter

func NewCharacter(name, imgpath string, loader ImageLoader) *Character

func (*Character) AddAnimation

func (c *Character) AddAnimation(ma *MoveAnimation)

func (*Character) CheckName

func (c *Character) CheckName(name string) bool

type CharacterAddShaderEvent

type CharacterAddShaderEvent struct {
	Name   string
	Shader *ebiten.Shader
}

func (*CharacterAddShaderEvent) Execute

func (s *CharacterAddShaderEvent) Execute(Scene *Scene)

type CharacterMoveEvent

type CharacterMoveEvent struct {
	Name string
	MoveParam
}

func (*CharacterMoveEvent) Execute

func (s *CharacterMoveEvent) Execute(scene *Scene)

type CharacterRemoveEvent

type CharacterRemoveEvent struct {
	Name string
}

func (*CharacterRemoveEvent) Execute

func (s *CharacterRemoveEvent) Execute(Scene *Scene)

type CharacterViewEvent

type CharacterViewEvent struct {
	Name       string
	MoveParam  *MoveParam
	ScaleParam *ScaleParam
}

func (*CharacterViewEvent) Execute

func (s *CharacterViewEvent) Execute(Scene *Scene)

type ComplexEvent

type ComplexEvent struct {
	Events []Event
}

complex event is event that is complex, we use it if we want to do several things in single click like change bg and show dialoge at the same time

func (*ComplexEvent) Execute

func (c *ComplexEvent) Execute(scene *Scene)

type DialogueEvent

type DialogueEvent struct {
	Name     string
	Dialogue string
	FontFace font.Face
}

event that shows dialogue/monologue. The location of the Name and text will follow Layouter on the scene.

Name is character name who tells the Dialogue. It does not need to be registered on AvailableCharacter on Scene. it can be made empty string

Dialogue is the text shown.

func (*DialogueEvent) Execute

func (b *DialogueEvent) Execute(scene *Scene)

type Event

type Event interface {
	// do something on the screen
	Execute(scene *Scene)
}

This is something that must happened in a scene, whether they are dialogue. moving image, some fancy stuff

func NewBGChangeEventFromPath

func NewBGChangeEventFromPath(imagepath string, moveParam MoveParam, imageloader ImageLoader, shader *ShaderParam) Event

func NewBranchingDialogueEvent

func NewBranchingDialogueEvent(name, sceneKey string, options map[string]string) Event

func NewBranchingJumpEvent

func NewBranchingJumpEvent(SceneDataKey string, BranchingJump map[string]int) Event

func NewCharacterAddEvent

func NewCharacterAddEvent(name string, moveParam *MoveParam, scaleParam *ScaleParam) Event

even to add character to the scene. name is character name that's already registered on characters field on scene moveParam determine how the character should get into scene scaleParam determine how

func NewCharacterAddShaderEvent

func NewCharacterAddShaderEvent(name string, shaderParam *ShaderParam) Event

add shader to a character, set shaderparam to nil if you want to remove any shader

func NewCharacterMoveEvent

func NewCharacterMoveEvent(name string, moveParam MoveParam) Event

func NewCharacterRemoveEvent

func NewCharacterRemoveEvent(name string) Event

func NewDialogueEvent

func NewDialogueEvent(name, dialogue string, fontface font.Face) Event

func NewOptionSelectEvent

func NewOptionSelectEvent(question string, options ...string) Event

create OptionSelectEvent

type GetLayouter

type GetLayouter interface {
	// return width and height of the scene
	GetLayout() (width, height int)
	// return the starting text position where the box containing name of the character appear on the scene
	// return negative number if no such box needed
	GetNamePosition() (x, y int)
	// get the starting position of the text
	GetTextPosition() (x, y int)
}

type ImageLoader

type ImageLoader interface {
	GetImage(key string) (*ebiten.Image, error)
}

type MovableImage

type MovableImage struct {
	ScaleParam *ScaleParam

	// animation stuff
	CurrMove       *MoveAnimation
	AnimationQueue []*MoveAnimation
	Shader         *ebiten.Shader
	// contains filtered or unexported fields
}

an image that you can move

func NewMovableImage

func NewMovableImage(image *ebiten.Image, param *MovableImageParams) *MovableImage

func (*MovableImage) AddAnimation

func (e *MovableImage) AddAnimation(animation ...*MoveAnimation)

func (*MovableImage) Draw

func (e *MovableImage) Draw(screen *ebiten.Image)

func (*MovableImage) GetPos

func (e *MovableImage) GetPos() (float64, float64)

func (*MovableImage) GetSize

func (e *MovableImage) GetSize() (float64, float64)

func (*MovableImage) ReplaceCurrentAnim

func (e *MovableImage) ReplaceCurrentAnim(animation *MoveAnimation)

replace current animation with new one

func (*MovableImage) SetPos

func (e *MovableImage) SetPos(x, y float64)

this function is to immediately move the image to pos x,y

func (*MovableImage) Update

func (e *MovableImage) Update()

type MovableImageParams

type MovableImageParams struct {
	MoveParam     MoveParam
	ScaleParam    *ScaleParam
	ShaderOptions *ShaderParam
}

func NewMovableImageParams

func NewMovableImageParams() *MovableImageParams

func (*MovableImageParams) WithMoveParam

func (p *MovableImageParams) WithMoveParam(param MoveParam) *MovableImageParams

func (*MovableImageParams) WithScale

func (p *MovableImageParams) WithScale(param *ScaleParam) *MovableImageParams

func (*MovableImageParams) WithShader

func (p *MovableImageParams) WithShader(param *ShaderParam) *MovableImageParams

type MoveAnimation

type MoveAnimation struct {
	Speed     float64
	SleepPre  time.Duration
	SleepPost time.Duration
	DoneFunc  func()
	// contains filtered or unexported fields
}

struct to represent movement of an image

type MoveParam

type MoveParam struct {
	Sx float64
	Sy float64
	Tx float64
	Ty float64

	Speed float64
}

type OptionPickerState

type OptionPickerState struct {
	Scene         *Scene
	Question      string
	Options       []string
	OptionsYStart []int
}

func (*OptionPickerState) Draw

func (s *OptionPickerState) Draw(screen *ebiten.Image)

func (*OptionPickerState) InitYStart

func (s *OptionPickerState) InitYStart()

init the y location of option buttons

func (*OptionPickerState) Update

func (s *OptionPickerState) Update()

type OptionSelectEvent

type OptionSelectEvent struct {
	Question string
	Options  []string
	Selected string
}

Event that SHOWS you selection option substate, by default using OptionPickerState

func (*OptionSelectEvent) Execute

func (b *OptionSelectEvent) Execute(scene *Scene)

type ScaleParam

type ScaleParam struct {
	Sx float64
	Sy float64
}

type Scene

type Scene struct {
	EventIndex int
	Events     []Event
	CurrentBg  *MovableImage

	// text stuff
	TxtBg       *ebiten.Image
	CurCharName string
	CurDialog   string
	FontFace    font.Face

	SceneData map[string]any

	//characters/sprite stuff
	// Characters used in the scene
	Characters []*Character
	// Characters viewable in the scene
	// Any character that needs to be shown will be moved here
	ViewableCharacters []*Character

	//substates and its management
	CurrentSubState     SubState
	OptionPikerSubstate SubState
	// this function is executed after the scene complete
	Done func()
	// contains filtered or unexported fields
}

Scene is whatever happened on the screen. It has several Event that is loaded in order It implement Draw(*ebiten.Image) and Update() so it should be simple to be splashed into default ebitengine projects.

use some statemanagement framework like github.com/joelschutz/stagehand to manage state/scene better

func NewScene

func NewScene() *Scene

func (*Scene) AddViewableCharacters

func (g *Scene) AddViewableCharacters(name string, moveParam *MoveParam, scaleParam *ScaleParam)

copy Character from Character to ViewableCharacter

func (*Scene) Draw

func (g *Scene) Draw(screen *ebiten.Image)

func (*Scene) GetSceneData

func (g *Scene) GetSceneData(key string) any

func (*Scene) RemoveVieableCharacter

func (g *Scene) RemoveVieableCharacter(characterName string)

remove character from ViewableCharacter

func (*Scene) SetLayouter

func (g *Scene) SetLayouter(getLayouter GetLayouter)

func (*Scene) SetSceneData

func (g *Scene) SetSceneData(key string, value any)

func (*Scene) Update

func (g *Scene) Update() error

type ShaderParam

type ShaderParam struct {
	Shader     *ebiten.Shader
	ShaderName string
}

parameter to use shader. You can fill Shader or Shadername and the function that takes it will determine wheter to assign shader directly or uses shader already registered on shaderpool

type ShaderPool

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

pool that store compiled shader. It is a singleton register new shader here so you can use it alongside ShaderParam

func GetShaderPool

func GetShaderPool() *ShaderPool

the default way to get shaderPool object

func (*ShaderPool) GetShader

func (s *ShaderPool) GetShader(name string) (*ebiten.Shader, error)

func (*ShaderPool) RegisterShader

func (s *ShaderPool) RegisterShader(name string, shader *ebiten.Shader)

type SubState

type SubState interface {
	Draw(screen *ebiten.Image)
	Update()
}

type TxtBgGetter

type TxtBgGetter interface {
	GetTxtBg() *ebiten.Image
}

Jump to

Keyboard shortcuts

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