-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamepad.go
89 lines (67 loc) · 2.45 KB
/
gamepad.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
// "github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/glfw/v3.3/glfw"
// "github.com/go-gl/mathgl/mgl32"
// "math"
// "github.com/mki1967/go-mki3d/mki3d"
// "github.com/mki1967/go-mki3d/glmki3d"
// "time"
)
func (g *Mki3dGame) CheckGamepad() {
if glfw.Joystick1.Present() && glfw.Joystick1.IsGamepad() {
// fmt.Println("Joystick1.Present && Joystick1.IsGamepad") /// test
gamepadStatePtr := glfw.Joystick1.GetGamepadState()
// fmt.Println("*gamepadStatePtr = %v", *gamepadStatePtr) /// test
var nextAction ActionIndex = ActionNIL
switch {
case gamepadStatePtr.Axes[glfw.AxisRightX] < -0.5:
nextAction = ActionRL
case gamepadStatePtr.Axes[glfw.AxisRightX] > 0.5:
nextAction = ActionRR
case gamepadStatePtr.Axes[glfw.AxisRightY] < -0.5:
nextAction = ActionRD
case gamepadStatePtr.Axes[glfw.AxisRightY] > 0.5:
nextAction = ActionRU
case gamepadStatePtr.Axes[glfw.AxisLeftY] < -0.5:
nextAction = ActionMF
case gamepadStatePtr.Axes[glfw.AxisLeftY] > 0.5:
nextAction = ActionMB
case gamepadStatePtr.Axes[glfw.AxisLeftX] < -0.5:
nextAction = ActionML
case gamepadStatePtr.Axes[glfw.AxisLeftX] > 0.5:
nextAction = ActionMR
case gamepadStatePtr.Axes[glfw.AxisRightTrigger] > -0.95:
nextAction = ActionMF
case gamepadStatePtr.Axes[glfw.AxisLeftTrigger] > -0.95:
nextAction = ActionMB
case gamepadStatePtr.Buttons[glfw.ButtonDpadUp] == glfw.Press:
nextAction = ActionMU
case gamepadStatePtr.Buttons[glfw.ButtonDpadDown] == glfw.Press:
nextAction = ActionMD
case gamepadStatePtr.Buttons[glfw.ButtonDpadLeft] == glfw.Press:
nextAction = ActionML
case gamepadStatePtr.Buttons[glfw.ButtonDpadRight] == glfw.Press:
nextAction = ActionMR
case gamepadStatePtr.Buttons[glfw.ButtonA] == glfw.Press:
nextAction = ActionLV
case gamepadStatePtr.Buttons[glfw.ButtonStart] == glfw.Press:
fmt.Println("RELOADING RANDOM STAGE ...")
ZenityInfo("NEXT RANDOM STAGE ...", "1")
g.NextStage()
}
if nextAction != ActionNIL {
g.Paused = false // new version for single-thread version
g.LastActivityTime = glfw.GetTime()
}
if nextAction == g.LastGamepadAction {
return // continuation of the same action or noaction
}
if nextAction != g.LastGamepadAction {
g.CancelAction() // the action is changed -- reset speed
}
g.LastGamepadAction = nextAction // record as the last gamepad action
g.SetAction(g.ActionArray[nextAction]) // set current action
}
}