example/blocks: Remove Input.gamepadButtonStates

This commit is contained in:
Hajime Hoshi 2018-01-22 20:55:57 +09:00
parent 8a7687687f
commit 4e432ca816
2 changed files with 8 additions and 24 deletions

View File

@ -22,7 +22,7 @@ import (
type Input struct { type Input struct {
keyStates map[ebiten.Key]int keyStates map[ebiten.Key]int
gamepadButtonStates map[ebiten.GamepadButton]int anyGamepadButtonPressed bool
virtualGamepadButtonStates map[virtualGamepadButton]int virtualGamepadButtonStates map[virtualGamepadButton]int
gamepadConfig gamepadConfig gamepadConfig gamepadConfig
} }
@ -34,11 +34,8 @@ func (i *Input) StateForKey(key ebiten.Key) int {
return i.keyStates[key] return i.keyStates[key]
} }
func (i *Input) StateForGamepadButton(b ebiten.GamepadButton) int { func (i *Input) IsAnyGamepadButtonPressed() bool {
if i.gamepadButtonStates == nil { return i.anyGamepadButtonPressed
return 0
}
return i.gamepadButtonStates[b]
} }
func (i *Input) stateForVirtualGamepadButton(b virtualGamepadButton) int { func (i *Input) stateForVirtualGamepadButton(b virtualGamepadButton) int {
@ -61,15 +58,12 @@ func (i *Input) Update() {
} }
const gamepadID = 0 const gamepadID = 0
if i.gamepadButtonStates == nil { i.anyGamepadButtonPressed = false
i.gamepadButtonStates = map[ebiten.GamepadButton]int{}
}
for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ { for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ {
if !ebiten.IsGamepadButtonPressed(gamepadID, b) { if ebiten.IsGamepadButtonPressed(gamepadID, b) {
i.gamepadButtonStates[b] = 0 i.anyGamepadButtonPressed = true
continue break
} }
i.gamepadButtonStates[b]++
} }
if i.virtualGamepadButtonStates == nil { if i.virtualGamepadButtonStates == nil {

View File

@ -47,16 +47,6 @@ func anyGamepadAbstractButtonPressed(i *Input) bool {
return false return false
} }
func anyGamepadButtonPressed(i *Input) bool {
bn := ebiten.GamepadButton(ebiten.GamepadButtonNum(0))
for b := ebiten.GamepadButton(0); b < bn; b++ {
if i.StateForGamepadButton(b) == 1 {
return true
}
}
return false
}
func (s *TitleScene) Update(state *GameState) error { func (s *TitleScene) Update(state *GameState) error {
s.count++ s.count++
if state.Input.StateForKey(ebiten.KeySpace) == 1 { if state.Input.StateForKey(ebiten.KeySpace) == 1 {
@ -70,7 +60,7 @@ func (s *TitleScene) Update(state *GameState) error {
// If 'abstract' gamepad buttons are not set and any gamepad buttons are pressed, // If 'abstract' gamepad buttons are not set and any gamepad buttons are pressed,
// go to the gamepad configuration scene. // go to the gamepad configuration scene.
if anyGamepadButtonPressed(state.Input) { if state.Input.IsAnyGamepadButtonPressed() {
state.SceneManager.GoTo(&GamepadScene{}) state.SceneManager.GoTo(&GamepadScene{})
return nil return nil
} }