mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48: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 {
|
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 {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user