Files
symph/game/action.go
T
2026-07-15 01:28:56 -04:00

55 lines
1.1 KiB
Go

package game
import (
"time"
)
// Action is a platform-neutral semantic input action, dispatched to the
// engine independent of the originating input device (keyboard, touch, etc)
type Action uint8
const (
ActionNone Action = iota
ActionMoveLeft // grid: dx=-1
ActionMoveUp // grid: dy=-1
ActionMoveDown // grid: dy=+1
ActionMoveRight // grid: dx=+1
// Reserved, behavior defined later
ActionStubSemicolon
ActionStubA
ActionStubS
ActionStubD
ActionStubF
ActionSpace
ActionConfirm
)
// Dispatch applies a single Action to the game state, gated by phase.
// Requires current time to timestamp temporal state shifts
func (gs *GameState) Dispatch(a Action, now time.Time) {
if gs.Paused {
return
}
switch gs.Phase {
case PhaseGameOver:
if a == ActionConfirm {
gs.restart(now)
}
return
case PhaseLevelClear:
return // input inert during transition
}
switch a {
case ActionMoveLeft:
gs.MovePlayer(0, -1, now)
case ActionMoveUp:
gs.MovePlayer(-1, 0, now)
case ActionMoveDown:
gs.MovePlayer(1, 0, now)
case ActionMoveRight:
gs.MovePlayer(0, 1, now)
}
}