Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/DropRock.txt
1319 views
1
//-----------------Sonic CD Drop Rock Script------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.XVelocity
7
#alias Object.Value1 : Object.YVelocity
8
#alias Object.Value2 : Object.OriginsPosY
9
10
#alias 0 : DROPROCK_IDLE
11
#alias 1 : DROPROCK_FALLING
12
#alias 2 : DROPROCK_WAITFORRESPAWN
13
#alias 3 : DROPROCK_FRAGMENT
14
15
// Global SFX
16
#alias 22 : SFX_G_EXPLOSION
17
18
// Collision Sides
19
#alias 0 : CSIDE_FLOOR
20
21
// Box Collision
22
#alias 4 : PLAYER_COL_ROOF
23
24
// Priority
25
#alias 0 : PRIORITY_BOUNDS
26
#alias 1 : PRIORITY_ACTIVE
27
28
// Property Values
29
#alias 1 : ROCK_DEBRIS_1
30
#alias 2 : ROCK_DEBRIS_2
31
#alias 3 : ROCK_DEBRIS_3
32
#alias 4 : ROCK_DEBRIS_4
33
34
35
36
sub ObjectMain
37
38
switch Object.State
39
40
// state DROPROCK_IDLE doesn't have anything
41
// It's handled over in ObjectPlayerInteraction instead
42
43
case DROPROCK_FALLING
44
45
// If not yet falling at a speed of 8 px/frame, accelerate a rate of 0.25 per frame
46
if Object.YVelocity < 0x80000
47
Object.YVelocity += 0x4000
48
end if
49
50
Object.YPos += Object.YVelocity
51
52
// Only check for Collision if the Object is falling at a rate faster than 2px per frame
53
if Object.YVelocity > 0x20000
54
ObjectTileCollision(CSIDE_FLOOR, 0, 12, 0)
55
if CheckResult == true
56
PlaySfx(SFX_G_EXPLOSION, 0)
57
58
// Make the Rock invisible and make it wait for respawning
59
Object.State = DROPROCK_WAITFORRESPAWN
60
61
// Create all the Rock Fragments now
62
// The appropriate info for each Fragment is listed as needed, in the format of
63
// X: X offset from the Rock's base position
64
// Y: Y offset from the Rock's base position
65
// XVel: Starting X Velocity of the Fragment
66
// YVel: Starting Y Velocity of the Fragment
67
68
// Top left Fragment!
69
// - X: 8 pixels left
70
// - Y: 8 pixels up
71
// - XVel: 1 pixel per frame left
72
// - YVel: 4 pixels per frame up
73
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_1, Object.XPos, Object.YPos)
74
Object[TempObjectPos].State = DROPROCK_FRAGMENT
75
Object[TempObjectPos].XPos -= 0x80000
76
Object[TempObjectPos].YPos -= 0x80000
77
Object[TempObjectPos].XVelocity = -0x10000
78
Object[TempObjectPos].YVelocity = -0x40000
79
Object[TempObjectPos].DrawOrder = 5
80
81
// Top right Fragment:
82
// - X: 8 pixels right
83
// - Y: 8 pixels up
84
// - XVel: 1 pixel per frame right
85
// - YVel: 4 pixels per frame up
86
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_2, Object.XPos, Object.YPos)
87
Object[TempObjectPos].State = DROPROCK_FRAGMENT
88
Object[TempObjectPos].XPos += 0x80000
89
Object[TempObjectPos].YPos -= 0x80000
90
Object[TempObjectPos].XVelocity = 0x10000
91
Object[TempObjectPos].YVelocity = -0x40000
92
Object[TempObjectPos].DrawOrder = 5
93
94
// Bottom left Fragment:
95
// - X: 8 pixels right
96
// - Y: 8 pixels up
97
// - XVel: 2 pixels per frame left
98
// - YVel: 2 pixels per frame up
99
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_3, Object.XPos, Object.YPos)
100
Object[TempObjectPos].State = DROPROCK_FRAGMENT
101
Object[TempObjectPos].XPos -= 0x80000
102
Object[TempObjectPos].YPos += 0x80000
103
Object[TempObjectPos].XVelocity = -0x20000
104
Object[TempObjectPos].YVelocity = -0x20000
105
Object[TempObjectPos].DrawOrder = 5
106
107
// Bottom right Fragment:
108
// - X: 8 pixels right
109
// - Y: 8 pixels down
110
// - XVel: 2 pixels per frame right
111
// - YVel: 2 pixels per frame up
112
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_4, Object.XPos, Object.YPos)
113
Object[TempObjectPos].State = DROPROCK_FRAGMENT
114
Object[TempObjectPos].XPos += 0x80000
115
Object[TempObjectPos].YPos += 0x80000
116
Object[TempObjectPos].XVelocity = 0x20000
117
Object[TempObjectPos].YVelocity = -0x20000
118
Object[TempObjectPos].DrawOrder = 5
119
120
// And then carrying on from the Explosion SFX from a while ago, create an Explosion effect too now
121
CreateTempObject(TypeName[Explosion], 0, Object.XPos, Object.YPos)
122
Object[TempObjectPos].DrawOrder = 5
123
124
end if
125
end if
126
break
127
128
case DROPROCK_WAITFORRESPAWN
129
// This state is given to the Rock after it explodes,
130
// in order to make sure it doesn't warp back to its
131
// starting position right in front of the Player
132
133
if Object.OutOfBounds == true
134
Object.YPos = Object.OriginsPosY
135
Object.Priority = PRIORITY_BOUNDS
136
Object.State = DROPROCK_IDLE
137
end if
138
break
139
140
case DROPROCK_FRAGMENT
141
142
// Update horizontal movements
143
Object.XPos += Object.XVelocity
144
145
// Make the Fragment accelerate vertically at a rate of 0.25px/frame
146
Object.YVelocity += 0x4000
147
148
// And then update vertical movements
149
Object.YPos += Object.YVelocity
150
151
if Object.OutOfBounds == true
152
// Unload when no longer needed
153
Object.Type = TypeName[Blank Object]
154
end if
155
break
156
157
end switch
158
159
end sub
160
161
162
sub ObjectPlayerInteraction
163
164
switch Object.State
165
case DROPROCK_IDLE
166
// First, act as a Box for the Player
167
PlayerObjectCollision(C_BOX, -16, -16, 16, 16)
168
169
// Then, see if the Player has walked below the Rock
170
PlayerObjectCollision(C_TOUCH, -4, 0, 4, 96)
171
172
if CheckResult == true
173
// If they have, then start Falling
174
175
Object.OriginsPosY = Object.YPos
176
Object.Priority = PRIORITY_ACTIVE
177
Object.YVelocity = 0
178
Object.State = DROPROCK_FALLING
179
end if
180
181
// [Fallthrough, to check if the Player has actually touched the rock]
182
183
case DROPROCK_FALLING
184
185
// Check Collision with Player
186
PlayerObjectCollision(C_BOX, -16, -16, 12, 16)
187
188
// Did the Player hit their head on the bottom of this rock?
189
if CheckResult == PLAYER_COL_ROOF
190
// Explode!
191
192
PlaySfx(SFX_G_EXPLOSION, 0)
193
194
Object.State = DROPROCK_WAITFORRESPAWN
195
196
CallFunction(Player_Hit)
197
198
// Create all the Rock Fragments, since the Rock's been exploded
199
200
// The initial info for each Fragment is listed as needed, in the following format:
201
// X: X offset from the Rock's base position
202
// Y: Y offset from the Rock's base position
203
// XVel: Starting X Velocity of the Fragment
204
// YVel: Starting Y Velocity of the Fragment
205
206
// Top left Fragment:
207
// - X: 8 pixels left
208
// - Y: 8 pixels up
209
// - XVel: 1 pixel per frame right
210
// - YVel: 4 pixels per frame up
211
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_1, Object.XPos, Object.YPos)
212
Object[TempObjectPos].State = DROPROCK_FRAGMENT
213
Object[TempObjectPos].XPos -= 0x80000
214
Object[TempObjectPos].YPos -= 0x80000
215
Object[TempObjectPos].XVelocity = -0x10000
216
Object[TempObjectPos].YVelocity = -0x40000
217
Object[TempObjectPos].DrawOrder = 5
218
219
// Top right Fragment:
220
// - X: 8 pixels right
221
// - Y: 8 pixels up
222
// - XVel: 1 pixel per frame right
223
// - YVel: 4 pixels per frame up
224
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_2, Object.XPos, Object.YPos)
225
Object[TempObjectPos].State = DROPROCK_FRAGMENT
226
Object[TempObjectPos].XPos += 0x80000
227
Object[TempObjectPos].YPos -= 0x80000
228
Object[TempObjectPos].XVelocity = 0x10000
229
Object[TempObjectPos].YVelocity = -0x40000
230
Object[TempObjectPos].DrawOrder = 5
231
232
// Bottom left Fragment:
233
// - X: 8 pixels left
234
// - Y: 8 pixels down
235
// - XVel: 2 pixels per frame left
236
// - YVel: 3 pixels per frame up
237
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_3, Object.XPos, Object.YPos)
238
Object[TempObjectPos].State = DROPROCK_FRAGMENT
239
Object[TempObjectPos].XPos -= 0x80000
240
Object[TempObjectPos].YPos += 0x80000
241
Object[TempObjectPos].XVelocity = -0x20000
242
Object[TempObjectPos].YVelocity = -0x30000
243
Object[TempObjectPos].DrawOrder = 5
244
245
// Bottom right Fragment:
246
// - X: 8 pixels right
247
// - Y: 8 pixels down
248
// - XVel: 2 pixels per frame right
249
// - YVel: 3 pixels per frame up
250
CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_4, Object.XPos, Object.YPos)
251
Object[TempObjectPos].State = DROPROCK_FRAGMENT
252
Object[TempObjectPos].XPos += 0x80000
253
Object[TempObjectPos].YPos += 0x80000
254
Object[TempObjectPos].XVelocity = 0x20000
255
Object[TempObjectPos].YVelocity = -0x30000
256
Object[TempObjectPos].DrawOrder = 5
257
CreateTempObject(TypeName[Explosion], 0, Object.XPos, Object.YPos)
258
Object[TempObjectPos].DrawOrder = 5
259
end if
260
break
261
262
end switch
263
264
end sub
265
266
267
sub ObjectDraw
268
269
switch Object.State
270
case DROPROCK_IDLE
271
case DROPROCK_FALLING
272
// Draw the Rock Sprite
273
DrawSprite(0)
274
break
275
276
// DROPROCK_WAITFORRESPAWN shouldn't draw anything,
277
// the Rock's meant to be invisible at that point
278
279
case DROPROCK_FRAGMENT
280
// Draw the Fragment's given Frame
281
DrawSprite(Object.PropertyValue)
282
break
283
284
end switch
285
286
end sub
287
288
289
sub ObjectStartup
290
291
LoadSpriteSheet("R5/Objects.gif")
292
293
// Main Rock Frame
294
SpriteFrame(-16, -16, 32, 32, 92, 18)
295
296
// The rest here are Rock Fragment Frames
297
298
// Top Left Frame
299
SpriteFrame(-8, -8, 16, 16, 92, 18)
300
301
// Top Right Frame
302
SpriteFrame(-8, -8, 16, 16, 108, 18)
303
304
// Bottom Left Frame
305
SpriteFrame(-8, -8, 16, 16, 92, 34)
306
307
// Bottom Right Frame
308
SpriteFrame(-8, -8, 16, 16, 108, 34)
309
310
end sub
311
312
313
// ========================
314
// Editor Subs
315
// ========================
316
317
sub RSDKDraw
318
if Editor.ShowGizmos == true
319
// Draw a downwards arrow to show that this Rock is of the falling variety
320
321
TempValue0 = Object.YPos
322
TempValue0 += 0x300000
323
324
Editor.DrawingOverlay = true
325
326
DrawArrow(Object.XPos, Object.YPos, Object.XPos, TempValue0, 255, 255, 255)
327
328
Editor.DrawingOverlay = false
329
end if
330
331
DrawSprite(0)
332
end sub
333
334
335
sub RSDKLoad
336
LoadSpriteSheet("R5/Objects.gif")
337
SpriteFrame(-16, -16, 32, 32, 92, 18)
338
339
// Although used by the Object, it's not to be set from the Editor
340
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
341
end sub
342
343