examples/blocks/blocks: Support standard gamepad axes

This commit is contained in:
Hajime Hoshi 2021-09-24 23:35:01 +09:00
parent a7b5db6f65
commit 0d673a68ab

View File

@ -196,7 +196,20 @@ func (c *gamepadConfig) IsButtonPressed(b virtualGamepadButton) bool {
} }
if ebiten.IsStandardGamepadLayoutAvailable(c.gamepadID) { if ebiten.IsStandardGamepadLayoutAvailable(c.gamepadID) {
return ebiten.IsStandardGamepadButtonPressed(c.gamepadID, b.StandardGamepadButton()) if ebiten.IsStandardGamepadButtonPressed(c.gamepadID, b.StandardGamepadButton()) {
return true
}
const threshold = 0.7
switch b {
case virtualGamepadButtonLeft:
return ebiten.StandardGamepadAxisValue(c.gamepadID, ebiten.StandardGamepadAxisLeftStickHorizontal) < -threshold
case virtualGamepadButtonRight:
return ebiten.StandardGamepadAxisValue(c.gamepadID, ebiten.StandardGamepadAxisLeftStickHorizontal) > threshold
case virtualGamepadButtonDown:
return ebiten.StandardGamepadAxisValue(c.gamepadID, ebiten.StandardGamepadAxisLeftStickVertical) > threshold
}
return false
} }
c.initializeIfNeeded() c.initializeIfNeeded()