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

View File

@ -47,16 +47,6 @@ func anyGamepadAbstractButtonPressed(i *Input) bool {
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 {
s.count++
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,
// go to the gamepad configuration scene.
if anyGamepadButtonPressed(state.Input) {
if state.Input.IsAnyGamepadButtonPressed() {
state.SceneManager.GoTo(&GamepadScene{})
return nil
}