ebiten/example/blocks/input.go
2014-12-07 02:27:08 +09:00

34 lines
523 B
Go

package blocks
import (
"github.com/hajimehoshi/ebiten/ui"
)
type Input struct {
states map[ui.Key]int
}
func NewInput() *Input {
states := map[ui.Key]int{}
for key := ui.Key(0); key < ui.KeyMax; key++ {
states[key] = 0
}
return &Input{
states: states,
}
}
func (i *Input) StateForKey(key ui.Key) int {
return i.states[key]
}
func (i *Input) Update(inputState ui.InputState) {
for key := range i.states {
if !inputState.IsPressedKey(key) {
i.states[key] = 0
continue
}
i.states[key] += 1
}
}