ebiten/example/blocks/input.go

34 lines
512 B
Go
Raw Normal View History

2013-12-18 19:21:25 +01:00
package blocks
import (
2014-12-07 14:10:04 +01:00
"github.com/hajimehoshi/ebiten/input"
2013-12-18 19:21:25 +01:00
)
type Input struct {
2014-12-07 14:10:04 +01:00
states map[input.Key]int
2013-12-18 19:21:25 +01:00
}
func NewInput() *Input {
2014-12-07 14:10:04 +01:00
states := map[input.Key]int{}
for key := input.Key(0); key < input.KeyMax; key++ {
2013-12-18 19:21:25 +01:00
states[key] = 0
}
return &Input{
states: states,
}
}
2014-12-07 14:10:04 +01:00
func (i *Input) StateForKey(key input.Key) int {
2013-12-18 19:21:25 +01:00
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-07 14:10:04 +01:00
if !input.IsKeyPressed(key) {
2013-12-18 19:21:25 +01:00
i.states[key] = 0
continue
}
i.states[key] += 1
}
}