mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
34 lines
507 B
Go
34 lines
507 B
Go
package blocks
|
|
|
|
import (
|
|
"github.com/hajimehoshi/go-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(keys ui.Keys) {
|
|
for key, _ := range i.states {
|
|
if !keys.Includes(key) {
|
|
i.states[key] = 0
|
|
continue
|
|
}
|
|
i.states[key] += 1
|
|
}
|
|
}
|