+72
-40
Diff
round #1
gamepad/eg_6x10.fff
gamepad/eg_6x10.fff
This is a binary file and will not be displayed.
+3
gamepad/firefly.toml
+3
gamepad/firefly.toml
+69
-40
gamepad/main.go
+69
-40
gamepad/main.go
···
1
1
package main
2
2
3
-
import ff "github.com/firefly-zero/firefly-go/firefly"
3
+
import (
4
+
ff "github.com/firefly-zero/firefly-go/firefly"
5
+
)
4
6
5
7
var (
8
+
font ff.Font
9
+
6
10
point *ff.Point
7
11
center ff.Point
8
12
···
13
17
)
14
18
15
19
const (
16
-
radius = 26
20
+
radius = 24
17
21
third = ff.Width / 3
18
22
19
23
touchYcenter = third
···
23
27
)
24
28
25
29
func init() {
30
+
ff.Boot = boot
26
31
ff.Render = render
27
32
ff.Update = update
33
+
ff.Render = render
34
+
}
35
+
36
+
func boot() {
37
+
font = ff.LoadFile("font", nil).Font()
28
38
}
29
39
30
40
func update() {
···
53
63
}
54
64
55
65
// Touchpad
56
-
center = ff.Point{
57
-
X: touchXcenter,
58
-
Y: touchYcenter,
59
-
// X: ff.Width/2 - 45,
60
-
// Y: ff.Height / 2,
61
-
}
66
+
center = ff.Point{X: touchXcenter, Y: touchYcenter}
62
67
63
68
input, pressed := ff.ReadPad(ff.Combined)
64
69
if pressed {
65
70
point = &ff.Point{
66
-
X: center.X + input.X/20 - radius,
67
-
Y: center.Y - input.Y/20 - radius,
71
+
X: center.X + input.X/30 - radius/2 + 7,
72
+
Y: center.Y - input.Y/30 - radius/2 + 7,
68
73
}
69
74
} else {
70
75
point = nil
71
76
}
72
77
}
73
78
79
+
func circleCenter(p ff.Point) ff.Point {
80
+
return ff.Point{X: p.X + (radius / 2.4), Y: p.Y + (radius / 1.6)}
81
+
}
82
+
74
83
func render() {
75
84
ff.ClearScreen(ff.ColorWhite)
76
85
77
-
// ff.DrawCircle(ff.Point{X: buttonYcenter - radius, Y: buttonXcenter - radius}, radius*3, ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1})
78
-
// ff.DrawCircle(ff.Point{X: touchYcenter - radius*2, Y: touchXcenter - radius}, radius*3, ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1})
79
-
ff.DrawLine(ff.Point{buttonYcenter, 0}, ff.Point{buttonYcenter, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
80
-
ff.DrawLine(ff.Point{touchYcenter, 0}, ff.Point{touchYcenter, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
81
-
ff.DrawLine(ff.Point{0, ff.Height / 2}, ff.Point{ff.Width, ff.Height / 2}, ff.LineStyle{ff.ColorGray, 1})
86
+
paintButtons()
87
+
paintTouchpad()
82
88
89
+
// drawHelpers()
90
+
}
91
+
92
+
func paintButtons() {
83
93
// Buttons
84
94
// B
85
95
styleE := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
86
96
if buttonE {
87
-
styleE = ff.Style{FillColor: ff.ColorRed, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
97
+
styleE.FillColor = ff.ColorRed
88
98
}
89
-
ff.DrawCircle(ff.Point{X: buttonYcenter + radius, Y: buttonXcenter}, radius, styleE)
99
+
bButton := ff.Point{X: buttonYcenter + radius, Y: buttonXcenter}
100
+
ff.DrawCircle(bButton, radius, styleE)
101
+
ff.DrawText(
102
+
"B",
103
+
font, (circleCenter(bButton)), ff.ColorLightGray,
104
+
)
90
105
91
106
// A
92
107
styleS := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
93
108
if buttonS {
94
-
styleS = ff.Style{FillColor: ff.ColorGreen, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
109
+
styleS.FillColor = ff.ColorGreen
95
110
}
96
-
ff.DrawCircle(ff.Point{X: buttonYcenter, Y: buttonXcenter + radius}, radius, styleS)
111
+
aButton := ff.Point{X: buttonYcenter, Y: buttonXcenter + radius}
112
+
ff.DrawCircle(aButton, radius, styleS)
113
+
ff.DrawText(
114
+
"A",
115
+
font, (circleCenter(aButton)), ff.ColorLightGray,
116
+
)
97
117
98
118
// Y
99
119
styleN := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
100
120
if buttonN {
101
-
styleN = ff.Style{FillColor: ff.ColorYellow, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
121
+
styleN.FillColor = ff.ColorYellow
102
122
}
103
-
ff.DrawCircle(ff.Point{X: buttonYcenter, Y: buttonXcenter - radius}, radius, styleN)
123
+
yButton := ff.Point{X: buttonYcenter, Y: buttonXcenter - radius}
124
+
ff.DrawCircle(yButton, radius, styleN)
125
+
ff.DrawText(
126
+
"Y",
127
+
font, (circleCenter(yButton)), ff.ColorLightGray,
128
+
)
104
129
105
130
// X
106
131
styleW := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
107
132
if buttonW {
108
-
styleW = ff.Style{FillColor: ff.ColorBlue, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
109
-
}
110
-
ff.DrawCircle(ff.Point{X: buttonYcenter - radius, Y: buttonXcenter}, radius, styleW)
111
-
112
-
// Touchpad
113
-
style := ff.Style{
114
-
FillColor: ff.ColorWhite,
115
-
StrokeColor: ff.ColorDarkBlue,
116
-
StrokeWidth: 1,
133
+
styleW.FillColor = ff.ColorBlue
117
134
}
135
+
xButton := ff.Point{X: buttonYcenter - radius, Y: buttonXcenter}
136
+
ff.DrawCircle(xButton, radius, styleW)
137
+
ff.DrawText(
138
+
"X",
139
+
font, (circleCenter(xButton)), ff.ColorLightGray,
140
+
)
141
+
}
118
142
119
-
ff.DrawCircle(ff.Point{
120
-
X: touchYcenter - radius*2,
121
-
Y: touchXcenter - radius,
122
-
}, radius*3, style)
143
+
func paintTouchpad() {
144
+
style := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
145
+
ff.DrawCircle(ff.Point{X: touchYcenter - radius*2, Y: touchXcenter - radius}, radius*3, style)
123
146
124
-
style = ff.Style{
125
-
FillColor: ff.ColorBlue,
126
-
StrokeColor: ff.ColorDarkBlue,
127
-
StrokeWidth: 1,
128
-
}
129
147
if point != nil {
130
-
ff.DrawCircle(*point, radius, style)
148
+
style = ff.Style{FillColor: ff.ColorBlue, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
149
+
ff.DrawCircle(*point, 10, style)
150
+
// ff.DrawLine(ff.Point{X: touchXcenter, Y: touchYcenter}, *point, ff.LineStyle{Color: ff.ColorDarkBlue, Width: 1})
131
151
}
132
152
}
153
+
154
+
// Helper Lines
155
+
func drawHelpers() {
156
+
ff.DrawLine(ff.Point{buttonYcenter, 0}, ff.Point{buttonYcenter, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
157
+
ff.DrawLine(ff.Point{touchYcenter, 0}, ff.Point{touchYcenter, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
158
+
ff.DrawLine(ff.Point{0, ff.Height / 2}, ff.Point{ff.Width, ff.Height / 2}, ff.LineStyle{ff.ColorGray, 1})
159
+
ff.DrawLine(ff.Point{touchYcenter - radius/2, 0}, ff.Point{touchYcenter - radius/2, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
160
+
ff.DrawLine(ff.Point{buttonYcenter + radius, 0}, ff.Point{buttonYcenter + radius, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
161
+
}
History
2 rounds
0 comments
voigt.tngl.sh
submitted
#1
1 commit
expand
collapse
add touchpad and buttons to gamepad demo
expand 0 comments
pull request successfully merged
voigt.tngl.sh
submitted
#0
1 commit
expand
collapse
add touchpad and buttons to gamepad demo