-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRace the Sun.myo
195 lines (166 loc) · 4.46 KB
/
Race the Sun.myo
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
scriptId = 'com.thalmic.examples.racethesun'
description = [[
Race the Sun
From the Steam description: You are a solar craft. The sun is your death timer. Hurtle towards the sunset at breakneck speed in a futile race against time. Delay the inevitable by catching energy boosts which reverse the setting sun - if only for a moment.
Problems? Talk to Paul (@PBernhardt)
Demo here: http://www.kongregate.com/games/flippfly/race-the-sun ]]
link = [[http://store.steampowered.com/app/253030/]]
controls = [[
Controls:
- Hold thumb to pinky to enable/disable mouse control
- Wave in/out to click
- Fist to center your yaw/roll, and then yaw left/right to fly left/right
- Wave up/down to jump if you get a jump pickup
- Fingers spread to hit escape and pause or back up in the menus
]]
knownIssues = [[
- None
]]
centreYaw = 0
centreRoll = 0
deltaRoll = 0
YAW_DEADZONE = .1
ROLL_DEADZONE = .2
MOUSE_CONTROL_TOGGLE_DURATION = 2000
PI = 3.1416
TWOPI = PI * 2
flyingLeft = false
flyingRight = false
togglingMouseControl = 0
mouseEnabled = true
printCount = 0
function onForegroundWindowChange(app, title)
--myo.debug("onForegroundWindowChange: " .. app .. ", " .. title)
local titleMatch = string.match(title, "Race The Sun") ~= nil or string.match(title, "RaceTheSun") ~= nil
--myo.debug("Race the Sun: " .. tostring(titleMatch))
myo.controlMouse(titleMatch and mouseEnabled);
return titleMatch;
end
function onPoseEdge(pose, edge)
--myo.debug("onPoseEdge: " .. pose .. ", " .. edge)
if (edge == "on") then
if (pose == "fist") then
centre()
if (mouseEnabled) then
toggleMouseControl()
end
elseif (pose == "fingersSpread") then
escape()
elseif (pose == "waveIn" or pose == "waveOut") then
if (mouseEnabled) then
leftClick()
elseif (math.abs(deltaRoll) > ROLL_DEADZONE) then
jump()
end
elseif (pose == "thumbToPinky") then
togglingMouseControl = myo.getTimeMilliseconds()
end
else
togglingMouseControl = 0
end
end
function activeAppName()
return "Race The Sun"
end
function centre()
--myo.debug("Centred")
centreYaw = myo.getYaw()
centreRoll = myo.getRoll()
myo.vibrate("short")
myo.keyboard("enter", "press")
end
function onPeriodic()
if (togglingMouseControl > 0 and myo.getTimeMilliseconds() > (togglingMouseControl + MOUSE_CONTROL_TOGGLE_DURATION)) then
togglingMouseControl = 0
toggleMouseControl()
end
if (centreYaw == 0) then
return
end
local currentYaw = myo.getYaw()
local currentRoll = myo.getRoll()
local deltaYaw = calculateDeltaRadians(currentYaw, centreYaw)
deltaRoll = calculateDeltaRadians(currentRoll, centreRoll);
printCount = printCount + 1
if printCount >= 200 then
--myo.debug("deltaYaw = " .. deltaYaw .. ", centreYaw = " .. centreYaw .. ", currentYaw = " .. currentYaw)
--myo.debug("deltaRoll = " .. deltaRoll .. " currentRoll = " .. currentRoll)
printCount = 0
end
if (deltaYaw > YAW_DEADZONE) then
flyLeft()
elseif (deltaYaw < -YAW_DEADZONE) then
flyRight()
else
flyNeutral()
end
end
function flyLeft()
if (flyingRight) then
--myo.debug("Not flying right");
myo.keyboard("right_arrow","up")
flyingRight = false
end
if (not flyingLeft) then
--myo.debug("Flying left");
myo.keyboard("left_arrow","down")
flyingLeft = true;
end
end
function flyRight()
if (flyingLeft) then
--myo.debug("Not flying left");
myo.keyboard("left_arrow","up")
flyingLeft = false
end
if (not flyingRight) then
--myo.debug("Flying right");
myo.keyboard("right_arrow","down")
flyingRight = true
end
end
function jump()
--myo.debug("Jump!")
myo.keyboard("space","press")
end
function flyNeutral()
if (flyingLeft) then
--myo.debug("Not flying left");
myo.keyboard("left_arrow","up")
flyingLeft = false
end
if (flyingRight) then
--myo.debug("Not flying right");
myo.keyboard("right_arrow","up")
flyingRight = false
end
end
function calculateDeltaRadians(currentYaw, centreYaw)
local deltaYaw = currentYaw - centreYaw
if (deltaYaw > PI) then
deltaYaw = deltaYaw - TWOPI
elseif(deltaYaw < -PI) then
deltaYaw = deltaYaw + TWOPI
end
return deltaYaw
end
function toggleMouseControl()
mouseEnabled = not mouseEnabled
myo.vibrate("medium")
if (mouseEnabled) then
--myo.debug("Mouse control enabled")
centreYaw = 0
flyNeutral()
else
--myo.debug("Mouse control disabled")
end
myo.controlMouse(mouseEnabled);
end
function leftClick()
--myo.debug("Left click!")
myo.mouse("left", "click")
end
function escape()
--myo.debug("Escape!")
myo.keyboard("escape","press")
end