Skip to content

Commit

Permalink
Use Button type in button constants
Browse files Browse the repository at this point in the history
Code editors will better suggest parameters accepted by pi.Btn and pi.Btnp functions.
  • Loading branch information
elgopher committed Mar 24, 2023
1 parent d684f84 commit 60273fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type Button int
// First connected gamepad controller is player 0, second player 1 and so on.
// On XBox controller [O] is A and Y, [X] is B and X.
const (
Left = 0
Right = 1
Up = 2
Down = 3
O = 4 // O is a first fire button
X = 5 // X is a second fire button
Left Button = 0
Right Button = 1
Up Button = 2
Down Button = 3
O Button = 4 // O is a first fire button
X Button = 5 // X is a second fire button
)

var Controllers [8]Controller // 0th element is for Player 0, 1st for Player 1 etc.
Expand Down Expand Up @@ -104,7 +104,7 @@ func isPressed(duration uint) bool {
func buttonBits(player int, isSet func(uint) bool) int {
c := Controllers[player]
var b int
for i := 0; i <= X; i++ {
for i := 0; i <= int(X); i++ {
if isSet(c.BtnDuration[i]) {
b += 1 << i
}
Expand Down
2 changes: 1 addition & 1 deletion ebitengine/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var keyboardMapping = [...][6][]ebiten.Key{
},
}

func isKeyboardPressed(player int, button int) bool {
func isKeyboardPressed(player int, button pi.Button) bool {
if player >= len(keyboardMapping) {
return false
}
Expand Down

0 comments on commit 60273fc

Please sign in to comment.