pgfsm

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 2 Imported by: 0

README

README of ENGLISH

The Pen Game Programing Finite State Machine

これはGoのゲームライブラリEbiten用のステートマシンライブラリです。

提供する機能

  • ゲームプログラミングのためのスタック型のステートマシン

ドキュメント

採用実績

絶賛募集中です。
このライブラリを採用しているゲームで載せてもいいよという方は是非Issueで教えてください。

Quick start

インストール

go get github.com/PenguinCabinet/pgfsm

Example

package main

import (
	"log"

	"github.com/PenguinCabinet/pgfsm"
	"github.com/hajimehoshi/ebiten/v2"
)

type MyGameState struct {
}

func (sm *MyGameState) Init(
	stackdeep int, /*The index of this state.*/
) {
	//Init
}

func (sm *MyGameState) Update(
	stackdeep int,
) pgfsm.Result {
	//Update
	return pgfsm.Result{
		Code:      pgfsm.CodeNil,
		NextState: nil,
	}
}

func (sm *MyGameState) Draw(screen *ebiten.Image, stackdeep int) {
	//Draw
}

func main() {

	ebiten.SetWindowSize(640, 480)
	ebiten.SetWindowTitle("game title")

	gms := &pgfsm.Machine{}

	gms.LayoutWidth = 640
	gms.LayoutHeight = 480

	mySm := &MyGameState{}

	gms.StateAdd(mySm)

	if err := ebiten.RunGame(gms); err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

This is the state machine library for Ebiten.

これはGoのゲームライブラリEbiten用のステートマシンライブラリです。

This is the state machine library for Ebiten.

これはGoのゲームライブラリEbiten用のステートマシンライブラリのutilityです。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int

The type of values for the type of operations the stack.

If its value is changed, In example,

Do nothing and continue. Change the current running state to NextState. Add NextState on the current running state in the stack...etc.

You can operate the stack.

これは現在実行中のステートから返される、スタックを操作する種類を決めるための変数型です

この値を変えると、例えば、

何もせずそのまま処理実行。 現在実行しているStateとNextStateを入れ替える。 現在スタックに乗っているStateをすべて消去して、NextStateを乗せる。

とスタックを操作することができます。

const (
	/*Do nothing and continue
	何もせずそのまま処理実行*/
	CodeNil Code = iota

	/*Change the current running state to NextState
	現在実行しているStateとNextStateを入れ替える*/
	CodeChange

	/*Add NextState on the current running state in the stack
	現在実行しているStateの上にNextStateを乗せる*/
	CodeAdd

	/*Delete the current running state
	現在実行しているStateを消去する*/
	CodeDelete

	/*Delete all states in the stack and add NextState in the stack.
	現在スタックに乗っているStateをすべて消去して、NextStateを乗せる*/
	CodeAllDeleteAndChange

	/*Insert NextState behiend the current running state
	現在実行しているStateの後ろに、NextStateを挿入する*/
	CodeInsertBack
)

type Machine

type Machine struct {
	StateStack []State

	/*Please set the window size here.
	It is used in the layout function for Ebiten
	Windowのサイズを入れてください。
	Ebiten用のレイアウト関数で使用されます*/
	LayoutWidth, LayoutHeight int
}

The struct of the stack and state machine.

ステートスタックマシーンの構造体です

func (*Machine) DebugLogprint

func (g *Machine) DebugLogprint()

The function for debugging.It displays the all states of the stack on the console.

デバッグ用の関数です。コンソールにスタック内のステートをすべて表示します

func (*Machine) Draw

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

This is the function for drawing that is called in every frames.It is used internally.

これは描写のため毎フレーク呼び出される関数です。内部的にEbitenで使います

func (*Machine) Empty

func (g *Machine) Empty() bool

This returns true if the stack is empty, false otherwise

stackが空ならtrueを返し、それ以外ならfalseを返します

func (*Machine) Init

func (g *Machine) Init()

This is the function for Ebiten.It is used internally. 内部的にEbitenで使います

func (*Machine) Layout

func (g *Machine) Layout(outsideWidth, outsideHeight int) (int, int)

This is the function for Ebiten.It is used internally. 内部的にEbitenで使います

func (*Machine) StateAdd

func (g *Machine) StateAdd(v State)

This add argument v to the stack

stackに引数vを追加します

func (*Machine) StateChange

func (g *Machine) StateChange(v State)

This changes the current running state in the stack to the argument v

実行中のステートを引数vに変更します

func (*Machine) Update

func (g *Machine) Update() error

This is the function for processing that is called in every frames.It is used internally.

これは処理のため毎フレーク呼び出される関数です。内部的にEbitenで使います

type Result

type Result struct {
	Code      Code
	NextState State
}

The type of values for operations the stack. If it is needed,set NextState.

これは現在実行中のステートから返される、スタックを操作するための変数型です 必要ならば、NextStateに値を入れてください

type SelectState added in v0.0.4

type SelectState struct {
	/*
		Coordinates where the first selection is placed.

		一番最初の選択肢がおかれる座標。
	*/
	OrignX int
	OrignY int

	/*
		Spacing between alternatives.
		選択肢と選択肢の間隔。
	*/
	IntervalX int
	IntervalY int

	/*
		Function to process initialization.
		初期化の処理をする関数。
	*/
	InitFunc func()

	/*
		Functions that describes a selection.

		選択肢を描写する関数。
	*/
	DrawFuncs []func(*ebiten.Image, int, int, bool)

	/*
		Function to be executed when a decision is made.

		決定したときに実行される関数。
	*/
	DecisionFunc []func() Result

	/*
		Function to be executed when canceled.

		キャンセルしたときに実行される関数。
	*/
	CancelFunc func() Result

	/*
		Index of the currently selected option.

		現在選択中の選択肢のインデックス。
	*/
	Index int
	/*
		Whether to loop if said before the end of the current selection.

		現在選択肢の端より先に言った場合、ループするかどうか。
	*/
	IsLoop bool

	/*
		Discriminant function to go to the next selection.

		次の選択肢へ行くための判別関数。
	*/
	PressedNextKeyFunc func() bool

	/*
		Discriminant function to go to the previous selection.

		前の選択肢へ行くための判別関数。
	*/
	PressedBackKeyFunc func() bool

	/*
		Discriminant function for decision.

		決定のための判別関数。
	*/
	PressedDecisionKeyFunc func() bool

	/*
		Discriminant function for cancellation.

		キャンセルのための判別関数。
	*/
	PressedCancelKeyFunc func() bool
}

The structure of the state for the selection scene.

選択画面用のステートスタックマシーンの構造体です。

func (*SelectState) Back added in v0.0.4

func (s *SelectState) Back()

Function to return the the current selection.

選択した選択肢を戻る関数。

func (*SelectState) Draw added in v0.0.4

func (s *SelectState) Draw(screen *ebiten.Image, StackIndex int)

func (*SelectState) Init added in v0.0.4

func (s *SelectState) Init(StackIndex int)

func (*SelectState) Next added in v0.0.4

func (s *SelectState) Next()

Function to advance the the current selection.

選択した選択肢を進める関数。

func (*SelectState) Update added in v0.0.4

func (s *SelectState) Update(StackIndex int) Result

type State

type State interface {
	Init(int)
	Update(int) Result
	Draw(*ebiten.Image, int)
}

The interface of state.

ステートのインターフェース

Jump to

Keyboard shortcuts

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