Skip to content

Commit

Permalink
input: Add GamepadButtonMax
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Sep 3, 2016
1 parent 623fa5c commit d62a90d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
12 changes: 9 additions & 3 deletions examples/blocks/blocks/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var gamepadAbstractButtons = []abstractButton{

type Input struct {
keyStates [256]int
gamepadButtonStates [256]int
gamepadButtonStates map[ebiten.GamepadButton]int
gamepadAbstractButtonStates map[abstractButton]int
gamepadConfig gamepadConfig
}
Expand All @@ -38,6 +38,9 @@ func (i *Input) StateForKey(key ebiten.Key) int {
}

func (i *Input) StateForGamepadButton(b ebiten.GamepadButton) int {
if i.gamepadButtonStates == nil {
return 0
}
return i.gamepadButtonStates[b]
}

Expand All @@ -58,8 +61,11 @@ func (i *Input) Update() {
}

const gamepadID = 0
for b := range i.gamepadButtonStates {
if !ebiten.IsGamepadButtonPressed(gamepadID, ebiten.GamepadButton(b)) {
if i.gamepadButtonStates == nil {
i.gamepadButtonStates = map[ebiten.GamepadButton]int{}
}
for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ {
if !ebiten.IsGamepadButtonPressed(gamepadID, b) {
i.gamepadButtonStates[b] = 0
continue
}
Expand Down
33 changes: 17 additions & 16 deletions gamepad.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ type GamepadButton int

// GamepadButtons
const (
GamepadButton0 = GamepadButton(ui.GamepadButton0)
GamepadButton1 = GamepadButton(ui.GamepadButton1)
GamepadButton2 = GamepadButton(ui.GamepadButton2)
GamepadButton3 = GamepadButton(ui.GamepadButton3)
GamepadButton4 = GamepadButton(ui.GamepadButton4)
GamepadButton5 = GamepadButton(ui.GamepadButton5)
GamepadButton6 = GamepadButton(ui.GamepadButton6)
GamepadButton7 = GamepadButton(ui.GamepadButton7)
GamepadButton8 = GamepadButton(ui.GamepadButton8)
GamepadButton9 = GamepadButton(ui.GamepadButton9)
GamepadButton10 = GamepadButton(ui.GamepadButton10)
GamepadButton11 = GamepadButton(ui.GamepadButton11)
GamepadButton12 = GamepadButton(ui.GamepadButton12)
GamepadButton13 = GamepadButton(ui.GamepadButton13)
GamepadButton14 = GamepadButton(ui.GamepadButton14)
GamepadButton15 = GamepadButton(ui.GamepadButton15)
GamepadButton0 = GamepadButton(ui.GamepadButton0)
GamepadButton1 = GamepadButton(ui.GamepadButton1)
GamepadButton2 = GamepadButton(ui.GamepadButton2)
GamepadButton3 = GamepadButton(ui.GamepadButton3)
GamepadButton4 = GamepadButton(ui.GamepadButton4)
GamepadButton5 = GamepadButton(ui.GamepadButton5)
GamepadButton6 = GamepadButton(ui.GamepadButton6)
GamepadButton7 = GamepadButton(ui.GamepadButton7)
GamepadButton8 = GamepadButton(ui.GamepadButton8)
GamepadButton9 = GamepadButton(ui.GamepadButton9)
GamepadButton10 = GamepadButton(ui.GamepadButton10)
GamepadButton11 = GamepadButton(ui.GamepadButton11)
GamepadButton12 = GamepadButton(ui.GamepadButton12)
GamepadButton13 = GamepadButton(ui.GamepadButton13)
GamepadButton14 = GamepadButton(ui.GamepadButton14)
GamepadButton15 = GamepadButton(ui.GamepadButton15)
GamepadButtonMax = GamepadButton15
)

0 comments on commit d62a90d

Please sign in to comment.