input: Add GamepadButtonMax

This commit is contained in:
Hajime Hoshi 2016-09-03 15:18:55 +09:00
parent 623fa5cd24
commit d62a90dfca
2 changed files with 26 additions and 19 deletions

View File

@ -28,7 +28,7 @@ var gamepadAbstractButtons = []abstractButton{
type Input struct {
keyStates [256]int
gamepadButtonStates [256]int
gamepadButtonStates map[ebiten.GamepadButton]int
gamepadAbstractButtonStates map[abstractButton]int
gamepadConfig gamepadConfig
}
@ -38,6 +38,9 @@ func (i *Input) StateForKey(key ebiten.Key) int {
}
func (i *Input) StateForGamepadButton(b ebiten.GamepadButton) int {
if i.gamepadButtonStates == nil {
return 0
}
return i.gamepadButtonStates[b]
}
@ -58,8 +61,11 @@ func (i *Input) Update() {
}
const gamepadID = 0
for b := range i.gamepadButtonStates {
if !ebiten.IsGamepadButtonPressed(gamepadID, ebiten.GamepadButton(b)) {
if i.gamepadButtonStates == nil {
i.gamepadButtonStates = map[ebiten.GamepadButton]int{}
}
for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ {
if !ebiten.IsGamepadButtonPressed(gamepadID, b) {
i.gamepadButtonStates[b] = 0
continue
}

View File

@ -39,4 +39,5 @@ const (
GamepadButton13 = GamepadButton(ui.GamepadButton13)
GamepadButton14 = GamepadButton(ui.GamepadButton14)
GamepadButton15 = GamepadButton(ui.GamepadButton15)
GamepadButtonMax = GamepadButton15
)