v0.1.0 initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user