mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
example/blocks: Remove Input.gamepadButtonStates
This commit is contained in:
parent
8a7687687f
commit
4e432ca816
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user