Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/SpikeBall.txt
1319 views
1
//-----------------Sonic CD Spike Ball Script-----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
7
// Can be either X or Y-based, depending on the Object's Property Value
8
#alias Object.Value2 : Object.Velocity
9
10
// Value3 is unused...
11
12
// Timers
13
// (These count towards the "Time" values, at which point states switch)
14
#alias Object.Value0 : Object.PauseTimer
15
#alias Object.Value1 : Object.MoveTimer
16
17
// Durations
18
// (How long, in frames, the SpikeBall will do the action for)
19
#alias Object.Value4 : Object.ShootTime
20
#alias Object.Value5 : Object.RetractTime
21
#alias Object.Value6 : Object.PauseTime
22
23
// HUD Alias
24
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
25
26
// States
27
#alias 0 : SPIKEBALL_H_MOVERIGHT
28
#alias 1 : SPIKEBALL_H_PAUSERIGHT
29
#alias 2 : SPIKEBALL_H_MOVELEFT
30
#alias 3 : SPIKEBALL_H_PAUSELEFT
31
32
#alias 4 : SPIKEBALL_V_MOVEDOWN
33
#alias 5 : SPIKEBALL_V_PAUSEDOWN
34
#alias 6 : SPIKEBALL_V_MOVEUP
35
#alias 7 : SPIKEBALL_V_PAUSEUP
36
37
// Time Periods
38
#alias 0 : TIME_PRESENT
39
#alias 1 : TIME_PAST
40
#alias 2 : TIME_GOOD_FUTURE
41
#alias 3 : TIME_BAD_FUTURE
42
43
// Property Values
44
#alias 0 : SPIKEBALL_TYPE_H
45
#alias 1 : SPIKEBALL_TYPE_V
46
47
48
sub ObjectMain
49
50
switch Object.State
51
52
// Horizontal Spike Ball States
53
case SPIKEBALL_H_MOVERIGHT
54
if Object.MoveTimer < Object.ShootTime
55
Object.MoveTimer++
56
Object.XPos += Object.Velocity
57
else
58
Object.State++
59
end if
60
break
61
62
case SPIKEBALL_H_PAUSERIGHT
63
if Object.PauseTimer < Object.PauseTime
64
Object.PauseTimer++
65
else
66
Object.PauseTimer = 0
67
Object.State++
68
end if
69
break
70
71
case SPIKEBALL_H_MOVELEFT
72
if Object.MoveTimer > Object.RetractTime
73
Object.MoveTimer--
74
Object.XPos -= Object.Velocity
75
else
76
Object.State++
77
end if
78
break
79
80
case SPIKEBALL_H_PAUSELEFT
81
if Object.PauseTimer < Object.PauseTime
82
Object.PauseTimer++
83
else
84
Object.PauseTimer = 0
85
Object.State = SPIKEBALL_H_MOVERIGHT
86
end if
87
break
88
89
90
// Vertical Spike Ball States
91
case SPIKEBALL_V_MOVEDOWN
92
if Object.MoveTimer < Object.ShootTime
93
Object.MoveTimer++
94
Object.YPos += Object.Velocity
95
else
96
Object.State++
97
end if
98
break
99
100
case SPIKEBALL_V_PAUSEDOWN
101
if Object.PauseTimer < Object.PauseTime
102
Object.PauseTimer++
103
else
104
Object.PauseTimer = 0
105
Object.State++
106
end if
107
break
108
109
case SPIKEBALL_V_MOVEUP
110
if Object.MoveTimer > Object.RetractTime
111
Object.MoveTimer--
112
Object.YPos -= Object.Velocity
113
else
114
Object.State++
115
end if
116
break
117
118
case SPIKEBALL_V_PAUSEUP
119
if Object.PauseTimer < Object.PauseTime
120
Object.PauseTimer++
121
else
122
Object.PauseTimer = 0
123
Object.State = SPIKEBALL_V_MOVEDOWN
124
end if
125
break
126
127
end switch
128
129
end sub
130
131
132
sub ObjectPlayerInteraction
133
134
PlayerObjectCollision(C_TOUCH, -12, -12, 12, 12)
135
136
if CheckResult == true
137
CallFunction(Player_Hit)
138
end if
139
140
end sub
141
142
143
sub ObjectDraw
144
DrawSprite(0)
145
end sub
146
147
148
sub ObjectStartup
149
LoadSpriteSheet("R7/Objects.gif")
150
151
// Spike Ball Frame
152
SpriteFrame(-16, -16, 32, 32, 1, 199)
153
154
ArrayPos0 = 32
155
while ArrayPos0 < 1056
156
if Object[ArrayPos0].Type == TypeName[Spike Ball]
157
158
if Object[ArrayPos0].PropertyValue == SPIKEBALL_TYPE_V
159
Object[ArrayPos0].State = SPIKEBALL_V_MOVEDOWN
160
161
switch HUD.CurrentTimePeriod
162
case TIME_PRESENT
163
Object[ArrayPos0].Velocity = 0x20000
164
Object[ArrayPos0].ShootTime = 16
165
Object[ArrayPos0].RetractTime = -16
166
Object[ArrayPos0].PauseTime = 40
167
break
168
169
case TIME_PAST
170
Object[ArrayPos0].Velocity = 0x40000
171
Object[ArrayPos0].ShootTime = 8
172
Object[ArrayPos0].RetractTime = -8
173
Object[ArrayPos0].PauseTime = 60
174
break
175
176
case TIME_GOOD_FUTURE
177
case TIME_BAD_FUTURE
178
Object[ArrayPos0].Velocity = 0x10000
179
Object[ArrayPos0].ShootTime = 32
180
Object[ArrayPos0].RetractTime = -32
181
Object[ArrayPos0].PauseTime = 20
182
break
183
184
end switch
185
else
186
switch HUD.CurrentTimePeriod
187
case TIME_PRESENT
188
Object[ArrayPos0].Velocity = 0x20000
189
Object[ArrayPos0].ShootTime = 24
190
Object[ArrayPos0].RetractTime = -24
191
Object[ArrayPos0].PauseTime = 40
192
break
193
194
case TIME_PAST
195
Object[ArrayPos0].Velocity = 0x40000
196
Object[ArrayPos0].ShootTime = 12
197
Object[ArrayPos0].RetractTime = -12
198
Object[ArrayPos0].PauseTime = 60
199
break
200
201
case TIME_GOOD_FUTURE
202
case TIME_BAD_FUTURE
203
Object[ArrayPos0].Velocity = 0x10000
204
Object[ArrayPos0].ShootTime = 48
205
Object[ArrayPos0].RetractTime = -48
206
Object[ArrayPos0].PauseTime = 20
207
break
208
209
end switch
210
end if
211
212
end if
213
214
ArrayPos0++
215
loop
216
217
end sub
218
219
220
// ========================
221
// Editor Subs
222
// ========================
223
224
sub RSDKEdit
225
if Editor.ReturnVariable == true
226
switch Editor.VariableID
227
case EDIT_VAR_PROPVAL // Property Value
228
case 0 // Type
229
CheckResult = Object.PropertyValue
230
break
231
end switch
232
else
233
switch Editor.VariableID
234
case EDIT_VAR_PROPVAL // Property Value
235
case 0 // Type
236
Object.PropertyValue = Editor.VariableValue
237
break
238
end switch
239
end if
240
end sub
241
242
243
sub RSDKDraw
244
DrawSprite(0)
245
246
// TODO: it would be cool to see the path of the spike ball via an arrow
247
// however, spike movement is dependant on time period, so that complicates things...
248
// update: woahhh we live in post-Origns CheckCurrentStageFolder era now, i think that may be possible
249
// the following (as well as the time period func) are incredibly scuffed, bring them up to snuff eventually
250
251
if Editor.ShowGizmos == true
252
Editor.DrawingOverlay = true
253
254
CallFunction(EditorHelpers_FindTimePeriod)
255
256
Object.InkEffect = 1
257
258
if Object.PropertyValue == SPIKEBALL_TYPE_V
259
switch CheckResult
260
case TIME_PRESENT
261
Object.Velocity = 0x20000
262
Object.ShootTime = 16
263
Object.RetractTime = -16
264
Object.PauseTime = 40
265
break
266
267
case TIME_PAST
268
Object.Velocity = 0x40000
269
Object.ShootTime = 8
270
Object.RetractTime = -8
271
Object.PauseTime = 60
272
break
273
274
case TIME_GOOD_FUTURE
275
case TIME_BAD_FUTURE
276
Object.Velocity = 0x10000
277
Object.ShootTime = 32
278
Object.RetractTime = -32
279
Object.PauseTime = 20
280
break
281
282
end switch
283
284
TempValue0 = Object.Velocity
285
TempValue0 *= Object.ShootTime
286
287
TempValue1 = Object.Velocity
288
TempValue1 *= Object.RetractTime
289
290
TempValue0 += Object.YPos
291
TempValue1 += Object.YPos
292
293
DrawSpriteFX(0, FX_INK, Object.XPos, TempValue0)
294
DrawSpriteFX(0, FX_INK, Object.XPos, TempValue1)
295
296
DrawLine(Object.XPos, TempValue0, Object.XPos, TempValue1, 255, 255, 255)
297
298
else
299
switch CheckResult
300
case TIME_PRESENT
301
Object.Velocity = 0x20000
302
Object.ShootTime = 24
303
Object.RetractTime = -24
304
Object.PauseTime = 40
305
break
306
307
case TIME_PAST
308
Object.Velocity = 0x40000
309
Object.ShootTime = 12
310
Object.RetractTime = -12
311
Object.PauseTime = 60
312
break
313
314
case TIME_GOOD_FUTURE
315
case TIME_BAD_FUTURE
316
Object.Velocity = 0x10000
317
Object.ShootTime = 48
318
Object.RetractTime = -48
319
Object.PauseTime = 20
320
break
321
322
end switch
323
324
TempValue0 = Object.Velocity
325
TempValue0 *= Object.ShootTime
326
327
TempValue1 = Object.Velocity
328
TempValue1 *= Object.RetractTime
329
330
TempValue0 += Object.XPos
331
TempValue1 += Object.XPos
332
333
DrawSpriteFX(0, FX_INK, TempValue0, Object.YPos)
334
DrawSpriteFX(0, FX_INK, TempValue1, Object.YPos)
335
336
DrawLine(TempValue0, Object.YPos, TempValue1, Object.YPos, 255, 255, 255)
337
338
end if
339
340
Editor.DrawingOverlay = false
341
end if
342
end sub
343
344
345
sub RSDKLoad
346
LoadSpriteSheet("R7/Objects.gif")
347
SpriteFrame(-16, -16, 32, 32, 1, 199)
348
349
AddEditorVariable("Type")
350
SetActiveVariable("Type")
351
AddEnumVariable("Horizontal", SPIKEBALL_TYPE_H)
352
AddEnumVariable("Vertical", SPIKEBALL_TYPE_V)
353
end sub
354
355