ebiten/example/blocks/input.go

34 lines
501 B
Go
Raw Normal View History

2013-12-18 19:21:25 +01:00
package blocks
import (
2014-12-05 14:16:58 +01:00
"github.com/hajimehoshi/ebiten/ui"
2013-12-18 19:21:25 +01:00
)
type Input struct {
2014-05-11 14:24:37 +02:00
states map[ui.Key]int
2013-12-18 19:21:25 +01:00
}
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]
}
2014-05-11 19:16:23 +02:00
func (i *Input) Update(keys ui.Keys) {
2014-12-06 14:56:57 +01:00
for key := range i.states {
2014-05-11 19:16:23 +02:00
if !keys.Includes(key) {
2013-12-18 19:21:25 +01:00
i.states[key] = 0
continue
}
i.states[key] += 1
}
}