ebiten/example/blocks/input.go

34 lines
507 B
Go
Raw Normal View History

2013-12-18 19:21:25 +01:00
package blocks
import (
"github.com/hajimehoshi/go-ebiten/ui"
)
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) {
2013-12-18 19:21:25 +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
}
}