ebiten/example/blocks/input.go

34 lines
491 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-12-06 19:27:55 +01:00
func (i *Input) Update() {
2014-12-06 14:56:57 +01:00
for key := range i.states {
2014-12-06 19:27:55 +01:00
if !ui.IsKeyPressed(key) {
2013-12-18 19:21:25 +01:00
i.states[key] = 0
continue
}
i.states[key] += 1
}
}