Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Special/TouchControls.txt
1319 views
1
//---------------Sonic CD Touch Controls Script---------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias 8: TYPE_TOUCHCONTROLS
7
8
#alias Object.Value0 : Object.MainAlpha
9
#alias Object.Value1 : Object.PauseAlpha
10
#alias Object.Value2 : Object.PausePos
11
#alias Object.Value3 : Object.JumpButtonPos
12
#alias Object.Value4 : Object.DPadPos
13
14
// Not used in this Script, but the Sonic Object uses it to store if the Jump button was held last frame
15
#alias Object.Value7 : TouchControls.TouchJump
16
17
// The primary alpha for the input display to use
18
#alias 160: TOUCHCONTROLS_TARGETALPHA
19
20
// Sonic Aliases
21
#alias Player.ControlMode : SSSonic.ControlMode
22
23
// ControlMode Aliases
24
#alias -1 : CONTROLMODE_NONE
25
#alias 0 : CONTROLMODE_NORMAL
26
27
// Ink Effects
28
#alias 2 : INK_ALPHA
29
30
// Priority
31
#alias 1 : PRIORITY_ACTIVE
32
33
34
sub ObjectDraw
35
#platform: Mobile
36
if Options.TouchControls == false
37
TempValue0 = CONTROLMODE_NONE
38
else
39
TempValue0 = Player.ControlMode
40
end if
41
42
if TempValue0 == CONTROLMODE_NORMAL
43
// The Player's up and ready to control, so let's show their inputs!
44
45
// Wait for the stage to be active too, before doing anything
46
if Stage.State != STAGE_PAUSED
47
48
// Fade the controls in, if they're not already yet
49
if Object.MainAlpha < TOUCHCONTROLS_TARGETALPHA
50
Object.MainAlpha += 4
51
52
// Make Pause Alpha double of the Main Alpha
53
Object.PauseAlpha = Object.MainAlpha
54
Object.PauseAlpha <<= 1
55
end if
56
57
// For here, we're drawing all the main features - DPad, and the Jump button - so let's pull from the main alpha for now
58
Object.Alpha = Object.MainAlpha
59
60
// First, draw the base DPad frame
61
DrawSpriteScreenFX(0, FX_INK, Object.DPadPos, 160)
62
63
// Now, all the directions
64
65
if Player.Left == true
66
Object.Alpha = TOUCHCONTROLS_TARGETALPHA
67
DrawSpriteScreenFX(7, FX_INK, Object.DPadPos, 160)
68
else
69
Object.Alpha = Object.MainAlpha
70
DrawSpriteScreenFX(3, FX_INK, Object.DPadPos, 160)
71
end if
72
73
if Player.Down == true
74
Object.Alpha = TOUCHCONTROLS_TARGETALPHA
75
DrawSpriteScreenFX(6, FX_INK, Object.DPadPos, 160)
76
else
77
Object.Alpha = Object.MainAlpha
78
DrawSpriteScreenFX(2, FX_INK, Object.DPadPos, 160)
79
end if
80
81
if Player.Right == true
82
Object.Alpha = TOUCHCONTROLS_TARGETALPHA
83
DrawSpriteScreenFX(8, FX_INK, Object.DPadPos, 160)
84
else
85
Object.Alpha = Object.MainAlpha
86
DrawSpriteScreenFX(4, FX_INK, Object.DPadPos, 160)
87
end if
88
89
if Player.Up == true
90
Object.Alpha = TOUCHCONTROLS_TARGETALPHA
91
DrawSpriteScreenFX(5, FX_INK, Object.DPadPos, 160)
92
else
93
Object.Alpha = Object.MainAlpha
94
DrawSpriteScreenFX(1, FX_INK, Object.DPadPos, 160)
95
end if
96
97
// After the directions comes the Jump Button, same song and dance here
98
if Player.JumpHold == true
99
Object.Alpha = TOUCHCONTROLS_TARGETALPHA
100
DrawSpriteScreenFX(10, FX_INK, Object.JumpButtonPos, 176)
101
else
102
Object.Alpha = Object.MainAlpha
103
DrawSpriteScreenFX(9, FX_INK, Object.JumpButtonPos, 176)
104
end if
105
106
else
107
Object.MainAlpha = 0 // Not yet, hold 'till needed...
108
end if
109
110
// Draw the Pause Button, enforcing a maximum alpha of 255
111
// -> Even if the Pause Button is seemingly drawn regardless of the stage's current state,
112
// do note that its alpha very well could be 0 when the stage is paused, effectively drawing nothing
113
if Object.PauseAlpha < 256
114
Object.Alpha = Object.PauseAlpha
115
DrawSpriteScreenFX(11, FX_INK, Object.PausePos, 8)
116
else
117
DrawSpriteScreenXY(11, Object.PausePos, 8)
118
end if
119
120
else
121
122
// The Player's not able to control anything yet, let's fade out controls
123
if Object.MainAlpha > 0
124
Object.MainAlpha -= 4
125
126
// Since Pause Alpha is always double Main Alpha, decrease it by twice as much here too
127
Object.PauseAlpha -= 8
128
end if
129
130
// Draw the unpressed versions of everything
131
Object.Alpha = Object.MainAlpha
132
if Object.Alpha > 0
133
DrawSpriteScreenFX(0, FX_INK, Object.DPadPos, 160)
134
DrawSpriteScreenFX(1, FX_INK, Object.DPadPos, 160)
135
DrawSpriteScreenFX(4, FX_INK, Object.DPadPos, 160)
136
DrawSpriteScreenFX(2, FX_INK, Object.DPadPos, 160)
137
DrawSpriteScreenFX(3, FX_INK, Object.DPadPos, 160)
138
139
DrawSpriteScreenFX(9, FX_INK, Object.JumpButtonPos, 176)
140
end if
141
142
// Keep a minimum of zero, Alpha shouldn't go into the negatives
143
if Object.PauseAlpha < 0
144
Object.Alpha = 0
145
else
146
Object.Alpha = Object.PauseAlpha
147
end if
148
149
// Similarly, keep a maximum alpha of 255, which is full opacity
150
if Object.PauseAlpha < 256
151
Object.Alpha = Object.PauseAlpha
152
DrawSpriteScreenFX(11, FX_INK, Object.PausePos, 8)
153
else
154
DrawSpriteScreenXY(11, Object.PausePos, 8)
155
end if
156
end if
157
#endplatform
158
end sub
159
160
161
sub ObjectStartup
162
#platform: Mobile
163
if Options.AttractMode == false
164
// All the Touch Control sprites are (rather lazily) already on the main SS Objects sheet, so let's load that
165
LoadSpriteSheet("Special/Objects.gif")
166
167
// Place a Touch Controls Object into the scene
168
Object[25].Type = TypeName[Touch Controls]
169
170
// Make sure it's always active, and give it a high draw order since it should be above everything else
171
Object[25].Priority = PRIORITY_ACTIVE
172
Object[25].DrawOrder = 6
173
174
// The Controls are to fade in, so set up use of Alpha
175
Object[25].InkEffect = INK_ALPHA
176
Object[25].MainAlpha = 0
177
Object[25].PauseAlpha = 0
178
179
// The Pause button should be at the top right corner of the screen
180
Object[25].PausePos = Screen.XSize
181
Object[25].PausePos -= 68
182
183
// First, fetch the base Jump Button Position, and then handling differs between platforms...
184
Object[25].JumpButtonPos = Screen.XSize
185
186
// On the Windows Phone, move everything over a bit
187
if Engine.PlatformID == RETRO_WP7
188
Object[25].JumpButtonPos -= 69
189
Object[25].DPadPos = 24
190
191
Options.DPadX = 56
192
else
193
Object[25].JumpButtonPos -= 61
194
Object[25].DPadPos = 16
195
196
Options.DPadX = 48
197
end if
198
199
// While not used here, Options.DPadX is used for actual understanding of the inputs, over in the Sonic Object
200
201
// So there's this check for being in a Special Stage... but this script is only ever used in Special Stages anyway so it always returns true
202
// It's worth noting, this check is in the standard TouchControls script too,
203
// where it's the opposite situation and it always returns false
204
205
if Stage.ActiveList == SPECIAL_STAGE
206
Object[25].PausePos += 42
207
end if
208
209
// 0 - Main DPad Frame
210
SpriteFrame(0, 0, 64, 64, 128, 192)
211
212
// 1 - Up, Unpressed
213
SpriteFrame(26, 0, 12, 25, 154, 128)
214
215
// 2 - Down, Unpressed
216
SpriteFrame(26, 38, 12, 26, 154, 166)
217
218
// 3 - Left, Unpressed
219
SpriteFrame(0, 25, 26, 13, 128, 153)
220
221
// 4 - Right, Unpressed
222
SpriteFrame(38, 25, 26, 13, 166, 153)
223
224
// 5 - Up, Pressed
225
SpriteFrame(26, 0, 12, 25, 244, 192)
226
227
// 6- Down, Pressed
228
SpriteFrame(26, 38, 12, 26, 244, 230)
229
230
// 7 - Left, Pressed
231
SpriteFrame(0, 25, 26, 13, 217, 229)
232
233
// 8 - Right, Pressed
234
SpriteFrame(38, 25, 26, 13, 217, 243)
235
236
// 9 - Jump, Unpressed
237
SpriteFrame(0, 0, 48, 48, 193, 128)
238
239
// 10 - Jump, Pressed
240
SpriteFrame(0, 0, 48, 48, 193, 177)
241
242
// 11 - Pause Button, offset differently if on the Windows Phone
243
if Engine.PlatformID == RETRO_WP7
244
SpriteFrame(-20, 0, 16, 16, 200, 239)
245
else
246
SpriteFrame(0, 0, 16, 16, 200, 239)
247
end if
248
end if
249
#endplatform
250
251
// On Standard Platforms, this event is just empty
252
end sub
253
254
255
// ========================
256
// Editor Subs
257
// ========================
258
259
sub RSDKDraw
260
DrawSprite(0)
261
end sub
262
263
264
sub RSDKLoad
265
LoadSpriteSheet("Global/Display.gif")
266
SpriteFrame(-16, -16, 32, 32, 1, 143) // #0 - "Script" Icon
267
268
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
269
end sub
270
271