-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gamepad.fluid
59 lines (43 loc) · 2.05 KB
/
gamepad.fluid
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
--[[
Gamepad demonstration
--]]
require 'gui/window'
glSelf = obj.find('self')
glPath = glSelf.workingPath
local win = gui.window({ title='Gamepad Demo', insideWidth=600, insideHeight=400, center=true, enableControllers=true })
local viewport = win:clientViewport({ aspectRatio = ARF_MEET })
local text = viewport.new('vectortext', {
x=win.margins.left, y=20, string='Use a gamepad to control the football.', face='Noto Sans', fontSize=20, fill='rgb(0,0,0)'
})
local txtLeftStick = viewport.new('vectortext', {
x=win.margins.left, y=50, string='Left Stick:', face='Noto Sans', fontSize=20, fill='rgb(0,0,0)'
})
local txtRightStick = viewport.new('vectortext', {
x=win.margins.left, y=80, string='Right Stick:', face='Noto Sans', fontSize=20, fill='rgb(0,0,0)'
})
local txtButtons = viewport.new('vectortext', {
x=win.margins.left, y=110, string='Buttons:', face='Noto Sans', fontSize=20, fill='rgb(0,0,0)'
})
local ballVP = viewport.new('VectorViewport', {
x = 260, y = 260, width = 60, height = 60
})
local svg = obj.new('svg', { target=ballVP, path=glPath .. 'data/football.svg' })
local MAX_SPEED = 3
local ctrl = obj.new('controller', { port=0 })
local err, controllerTimer = mSys.SubscribeTimer(1/60, function(Subscriber, Elapsed, CurrentTime)
ctrl.acQuery()
txtLeftStick.string = 'Left Stick: ' .. string.format('%.2f %.2f', ctrl.leftStickX, ctrl.leftStickY)
txtRightStick.string = 'Right Stick: ' .. string.format('%.2f %.2f', ctrl.rightStickX, ctrl.rightStickY)
txtButtons.string = 'Buttons: ' .. string.format('%.8x', ctrl.buttons)
local speed = MAX_SPEED
if bit.band(ctrl.buttons, CON_GAMEPAD_S) != 0 then
speed = speed * 2
end
ballVP.x = ballVP.x + (ctrl.leftStickX * speed)
ballVP.y = ballVP.y - (ctrl.leftStickY * speed)
ballVP.width = ballVP.width + ctrl.rightStickY
ballVP.height = ballVP.height + ctrl.rightStickY
viewport.scene.surface.mtScheduleRedraw()
end)
win:show()
processing.sleep()