Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/SpikeBallLauncher.txt
1319 views
1
//---------------Sonic CD Spike Launcher Script---------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Timer
7
8
// Position is an offset relative to the base Spike Launcher Object, in world-space
9
#alias Object.Value1 : Object.SpikeBallPosition
10
#alias Object.Value2 : Object.SpikeBallVelocity
11
12
#alias 0 : SPIKELAUNCHER_INIT
13
#alias 1 : SPIKELAUNCHER_RAISING
14
#alias 2 : SPIKELAUNCHER_PAUSE
15
#alias 3 : SPIKELAUNCHER_THROWN
16
#alias 4 : SPIKELAUNCHER_CATCHING
17
18
// Priority
19
#alias 0 : PRIORITY_BOUNDS
20
#alias 1 : PRIORITY_ACTIVE
21
22
// Property Values
23
#alias 0 : LAUNCH_DIR_UP
24
#alias 1 : LAUNCH_DIR_DOWN
25
#alias 2 : LAUNCH_DIR_LEFT
26
#alias 3 : LAUNCH_DIR_RIGHT
27
28
29
sub ObjectMain
30
31
switch Object.State
32
case SPIKELAUNCHER_INIT
33
// Set the object to always be active
34
Object.Priority = PRIORITY_ACTIVE
35
36
// Give it a bit of time before starting the object's main routine proper
37
if Object.Timer < 150
38
Object.Timer++
39
else
40
Object.Timer = 0
41
Object.SpikeBallPosition = 0
42
Object.State++
43
end if
44
break
45
46
case SPIKELAUNCHER_RAISING
47
// Start by poking the Spike Ball out of the Launcher's face, half a pixel per frame at a time
48
if Object.Timer < 32
49
Object.Timer++
50
Object.SpikeBallPosition -= 0x8000
51
else
52
Object.Timer = 0
53
Object.State++
54
end if
55
break
56
57
case SPIKELAUNCHER_PAUSE
58
// Now, pause for a moment before shooting the Spike Ball away
59
if Object.Timer < 30
60
Object.Timer++
61
else
62
Object.Timer = 0
63
64
// Initial velocity of 6 pixels per frame
65
Object.SpikeBallVelocity = -0x60000
66
67
Object.State++
68
end if
69
break
70
71
case SPIKELAUNCHER_THROWN
72
if Object.SpikeBallPosition < 0
73
// Apply a gravity of 0.25 pixels to the Spike Ball every frame
74
Object.SpikeBallVelocity += 0x4000
75
76
// And then actually add the Velocity to the Spike Ball's position
77
Object.SpikeBallPosition += Object.SpikeBallVelocity
78
else
79
Object.State++
80
end if
81
break
82
83
case SPIKELAUNCHER_CATCHING
84
if Object.Timer < 40
85
Object.Timer++
86
else
87
Object.Timer = 0
88
Object.SpikeBallPosition = 0
89
Object.State = SPIKELAUNCHER_RAISING
90
end if
91
break
92
93
end switch
94
95
if Object.OutOfBounds == true
96
97
// Reset the object and give it normal priority
98
99
Object.State = SPIKELAUNCHER_INIT
100
Object.Timer = 0
101
Object.Priority = PRIORITY_BOUNDS
102
103
end if
104
105
end sub
106
107
108
sub ObjectPlayerInteraction
109
110
// Only check for Spike Ball collisions if it's a state where the Spike ball is actually visible
111
switch Object.State
112
case SPIKELAUNCHER_RAISING
113
case SPIKELAUNCHER_PAUSE
114
case SPIKELAUNCHER_THROWN
115
116
// First, backup the base object's position
117
TempValue0 = Object.XPos
118
TempValue1 = Object.YPos
119
120
// Then, add the corresponding offset based on the Spike Ball's position
121
switch Object.PropertyValue
122
case LAUNCH_DIR_UP
123
// Upwards
124
Object.YPos += Object.SpikeBallPosition
125
break
126
127
case LAUNCH_DIR_DOWN
128
// Downwards
129
Object.YPos -= Object.SpikeBallPosition
130
break
131
132
case LAUNCH_DIR_LEFT
133
// Left
134
Object.XPos += Object.SpikeBallPosition
135
break
136
137
case LAUNCH_DIR_RIGHT
138
// Right
139
Object.XPos -= Object.SpikeBallPosition
140
break
141
142
end switch
143
144
// Check collision with the player & hurt them if needed
145
PlayerObjectCollision(C_TOUCH, -12, -12, 12, 12)
146
if CheckResult == true
147
CallFunction(Player_Hit)
148
end if
149
150
// Restore the object's base position
151
Object.XPos = TempValue0
152
Object.YPos = TempValue1
153
154
// No break is used here, although it doesn't matter too much anyway since there's nothing afterwards
155
156
end switch
157
158
end sub
159
160
161
162
sub ObjectDraw
163
164
if Object.DrawOrder == 3
165
// Drawing the Spike Ball...
166
167
switch Object.State
168
case SPIKELAUNCHER_RAISING
169
case SPIKELAUNCHER_PAUSE
170
case SPIKELAUNCHER_THROWN
171
switch Object.PropertyValue
172
case LAUNCH_DIR_UP
173
// Upwards
174
TempValue0 = Object.YPos
175
TempValue0 += Object.SpikeBallPosition
176
DrawSpriteXY(4, Object.XPos, TempValue0)
177
break
178
179
case LAUNCH_DIR_DOWN
180
// Downwards
181
TempValue0 = Object.YPos
182
TempValue0 -= Object.SpikeBallPosition
183
DrawSpriteXY(4, Object.XPos, TempValue0)
184
break
185
186
case LAUNCH_DIR_LEFT
187
// Facing left
188
TempValue0 = Object.XPos
189
TempValue0 += Object.SpikeBallPosition
190
DrawSpriteXY(4, TempValue0, Object.YPos)
191
break
192
193
case LAUNCH_DIR_RIGHT
194
// Facing right
195
TempValue0 = Object.XPos
196
TempValue0 -= Object.SpikeBallPosition
197
DrawSpriteXY(4, TempValue0, Object.YPos)
198
break
199
200
end switch // Object.PropertyValue
201
202
// No break is used here, as it's not needed
203
204
end switch // Object.State
205
206
// Add the Object to Draw List 4 so that its other half can draw above the Spike Ball
207
SetDrawListEntityRef(Object.EntityNo, 4, Screen.DrawListSize[4])
208
Screen.DrawListSize[4]++
209
Object.DrawOrder = 4
210
211
else
212
// Drawing the Spike Ball Launcher itself...
213
214
// The object's direction is stored in its Property Value, which also happens to align with the correct Sprite Frames
215
DrawSprite(Object.PropertyValue)
216
217
// Reset the object's Draw Order back to 3 so that this whole process can be done again next frame
218
Object.DrawOrder = 3
219
end if
220
221
end sub
222
223
224
225
sub ObjectStartup
226
227
LoadSpriteSheet("R7/Objects.gif")
228
229
// Upwards Launcher Frame
230
SpriteFrame(-16, -16, 32, 16, 133, 1)
231
232
// Downwards Launcher Frame
233
SpriteFrame(-16, 0, 32, 16, 166, 1)
234
235
// Left-facing Launcher Frame
236
SpriteFrame(-16, -16, 16, 32, 1, 166)
237
238
// Right-facing Launcher Frame
239
SpriteFrame(0, -16, 16, 32, 17, 166)
240
241
// Spike Ball Frame
242
SpriteFrame(-16, -16, 32, 32, 1, 199)
243
244
end sub
245
246
247
// ========================
248
// Editor Subs
249
// ========================
250
251
sub RSDKEdit
252
if Editor.ReturnVariable == true
253
switch Editor.VariableID
254
case EDIT_VAR_PROPVAL // Property Value
255
CheckResult = Object.PropertyValue
256
break
257
case 0 // Direction
258
CheckResult = Object.PropertyValue
259
break
260
end switch
261
else
262
switch Editor.VariableID
263
case EDIT_VAR_PROPVAL // Property Value
264
Object.PropertyValue = Editor.VariableValue
265
break
266
case 0 // Direction
267
Object.PropertyValue = Editor.VariableValue
268
break
269
end switch
270
end if
271
end sub
272
273
274
sub RSDKDraw
275
DrawSprite(4)
276
DrawSprite(Object.PropertyValue)
277
278
if Editor.ShowGizmos == true
279
Editor.DrawingOverlay = true
280
281
TempValue0 = Object.XPos
282
TempValue1 = Object.YPos
283
284
switch Object.PropertyValue
285
case 0
286
default
287
TempValue1 -= 0x300000; break;
288
case 1
289
TempValue1 += 0x300000; break;
290
case 2
291
TempValue0 -= 0x300000; break;
292
case 3
293
TempValue0 += 0x300000; break;
294
end switch
295
296
DrawArrow(Object.XPos, Object.YPos, TempValue0, TempValue1, 255, 255, 255)
297
298
Editor.DrawingOverlay = false
299
end if
300
end sub
301
302
303
sub RSDKLoad
304
LoadSpriteSheet("R7/Objects.gif")
305
SpriteFrame(-16, -16, 32, 16, 133, 1)
306
SpriteFrame(-16, 0, 32, 16, 166, 1)
307
SpriteFrame(-16, -16, 16, 32, 1, 166)
308
SpriteFrame(0, -16, 16, 32, 17, 166)
309
SpriteFrame(-16, -16, 32, 32, 1, 199)
310
311
AddEditorVariable("Direction")
312
SetActiveVariable("Direction")
313
AddEnumVariable("Up", 0)
314
AddEnumVariable("Down", 1)
315
AddEnumVariable("Left", 2)
316
AddEnumVariable("Right", 3)
317
end sub
318
319