everything I got

This commit is contained in:
MrDonuts
2023-11-19 20:53:35 -05:00
commit a875a4ed57
45 changed files with 903 additions and 0 deletions

54
states/statemachine.go Normal file
View File

@@ -0,0 +1,54 @@
package states
import (
"github.com/hajimehoshi/ebiten/v2"
)
var SM StateMachine
var StateMap map[string]State
type State interface {
Enter()
Exit()
Update()
Draw(screen *ebiten.Image)
}
type StateMachine struct {
CurrentState State
}
func NewStateMachine(initialState State) *StateMachine {
sm := &StateMachine{CurrentState: initialState}
sm.CurrentState.Enter()
return sm
}
func (sm *StateMachine) Transition(newState string) {
sm.CurrentState.Exit()
sm.CurrentState = StateMap[newState]
sm.CurrentState.Enter()
}
func (sm *StateMachine) Update() {
sm.CurrentState.Update()
}
func (sm *StateMachine) Draw(screen *ebiten.Image) {
sm.CurrentState.Draw(screen)
}
func SetupStateMachine() {
loadState := &LoadLevelState{}
playState := &PlayLevelState{}
gameOverState := &GameOverState{}
StateMap = make(map[string]State)
StateMap["load"] = loadState
StateMap["play"] = playState
StateMap["game over"] = gameOverState
SM = *NewStateMachine(loadState)
}