Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R8/SpikePuzzle.txt
1319 views
1
//---------------Sonic CD Spike Puzzle 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
#alias Object.Value1 : Object.YVelocity
8
#alias Object.Value2 : Object.PieceType // 0 is not an actual piece
9
#alias Object.Value3 : Object.YOffset
10
#alias Object.Value4 : Object.PuzzlePiece
11
12
// States
13
#alias 0 : SPIKEPUZZLE_SETUP
14
#alias 1 : SPIKEPUZZLE_CHECK_BOUNDS
15
#alias 2 : SPIKEPUZZLE_CREATE_PIECE
16
17
// Priority
18
#alias 0 : PRIORITY_BOUNDS
19
#alias 1 : PRIORITY_ACTIVE
20
21
// Collision
22
#alias 0 : CSIDE_FLOOR
23
24
#alias 1 : PLAYER_COL_FLOOR
25
#alias 4 : PLAYER_COL_ROOF
26
27
// Gravity
28
#alias 0 : GRAVITY_GROUND
29
30
// Property Values
31
#alias 0 : PUZZLE_A
32
#alias 1 : PUZZLE_B
33
34
// Function declarations
35
#function SpikePuzzle_Reset
36
37
function SpikePuzzle_Reset
38
39
Object.Timer = 0
40
Object.PuzzlePiece = 1
41
42
Object[+1].Type = TypeName[Spike Puzzle]
43
Object[+1].XPos = Object.XPos
44
Object[+1].YPos = Object.YPos
45
Object[+1].YVelocity = 0
46
Object[+1].YOffset = 16
47
48
Object[+2].Type = TypeName[Blank Object]
49
Object[+2].YVelocity = 0
50
Object[+2].YOffset = 40
51
52
Object[+3].Type = TypeName[Blank Object]
53
Object[+3].YVelocity = 0
54
Object[+3].YOffset = 64
55
56
Object[+4].Type = TypeName[Blank Object]
57
Object[+4].YVelocity = 0
58
Object[+4].YOffset = 88
59
60
Object[+5].Type = TypeName[Blank Object]
61
Object[+5].YVelocity = 0
62
Object[+5].YOffset = 112
63
64
if Object.PropertyValue == PUZZLE_A
65
Object[+1].PieceType = 1
66
Object[+2].PieceType = 2
67
Object[+3].PieceType = 1
68
Object[+4].PieceType = 3
69
Object[+5].PieceType = 1
70
else
71
Object[+1].PieceType = 1
72
Object[+2].PieceType = 3
73
Object[+3].PieceType = 1
74
Object[+4].PieceType = 2
75
Object[+5].PieceType = 1
76
end if
77
end function
78
79
80
sub ObjectMain
81
if Object.PieceType == 0
82
if Object.OutOfBounds == true
83
CallFunction(SpikePuzzle_Reset)
84
Object.State = SPIKEPUZZLE_CHECK_BOUNDS
85
Object.Priority = PRIORITY_BOUNDS
86
end if
87
88
switch Object.State
89
case SPIKEPUZZLE_SETUP
90
CallFunction(SpikePuzzle_Reset)
91
Object.State++
92
break
93
94
case SPIKEPUZZLE_CHECK_BOUNDS
95
PlayerObjectCollision(C_TOUCH, -80, -8, 80, 224)
96
if CheckResult == true
97
Object.Priority = PRIORITY_ACTIVE
98
Object.State++
99
Object[+1].YVelocity = 0x8000
100
end if
101
break
102
103
case SPIKEPUZZLE_CREATE_PIECE
104
if Object.Timer < 284
105
Object.Timer++
106
else
107
TempValue0 = Object.YPos
108
TempValue0 += 0x400000
109
if Player.YPos > TempValue0
110
Object.Timer = 0
111
Object.PuzzlePiece++
112
if Object.PuzzlePiece < 6
113
ArrayPos0 = Object.EntityNo
114
ArrayPos0 += Object.PuzzlePiece
115
116
Object[ArrayPos0].Type = TypeName[Spike Puzzle]
117
Object[ArrayPos0].XPos = Object.XPos
118
119
Object[ArrayPos0].YPos = Object.YPos
120
Object[ArrayPos0].YPos -= 0x200000
121
122
Object[ArrayPos0].YVelocity = 0x8000
123
else
124
Object.State++
125
end if
126
end if
127
end if
128
break
129
130
end switch
131
else
132
Object.YPos += Object.YVelocity
133
ObjectTileCollision(CSIDE_FLOOR, 0, Object.YOffset, 0)
134
if CheckResult == true
135
Object.YVelocity = 0
136
end if
137
end if
138
end sub
139
140
141
sub ObjectPlayerInteraction
142
switch Object.PieceType
143
case 1
144
PlayerObjectCollision(C_BOX, -80, -9, -24, 16)
145
TempValue0 = CheckResult
146
PlayerObjectCollision(C_BOX, 24, -9, 80, 16)
147
TempValue0 += CheckResult
148
if TempValue0 == PLAYER_COL_FLOOR
149
Player.YPos += 0x10000
150
end if
151
if TempValue0 == PLAYER_COL_ROOF
152
if Player.Gravity == GRAVITY_GROUND
153
CallFunction(Player_Kill)
154
else
155
CallFunction(Player_Hit)
156
end if
157
end if
158
break
159
160
case 2
161
PlayerObjectCollision(C_BOX, -80, -9, -56, 16)
162
TempValue0 = CheckResult
163
PlayerObjectCollision(C_BOX, -8, -9, 80, 16)
164
TempValue0 += CheckResult
165
if TempValue0 == PLAYER_COL_FLOOR
166
Player.YPos += 0x10000
167
end if
168
if TempValue0 == PLAYER_COL_ROOF
169
if Player.Gravity == GRAVITY_GROUND
170
CallFunction(Player_Kill)
171
else
172
CallFunction(Player_Hit)
173
end if
174
end if
175
break
176
177
case 3
178
PlayerObjectCollision(C_BOX, -80, -9, 8, 16)
179
TempValue0 = CheckResult
180
PlayerObjectCollision(C_BOX, 56, -9, 80, 16)
181
TempValue0 += CheckResult
182
if TempValue0 == PLAYER_COL_FLOOR
183
Player.YPos += 0x10000
184
end if
185
if TempValue0 == PLAYER_COL_ROOF
186
if Player.Gravity == GRAVITY_GROUND
187
CallFunction(Player_Kill)
188
else
189
CallFunction(Player_Hit)
190
end if
191
end if
192
break
193
end switch
194
end sub
195
196
197
sub ObjectDraw
198
switch Object.PieceType
199
case 1
200
DrawSprite(0)
201
DrawSprite(1)
202
DrawSprite(2)
203
DrawSprite(3)
204
DrawSprite(4)
205
DrawSprite(5)
206
break
207
case 2
208
DrawSprite(6)
209
DrawSprite(7)
210
DrawSprite(8)
211
DrawSprite(9)
212
DrawSprite(10)
213
DrawSprite(11)
214
break
215
case 3
216
DrawSprite(12)
217
DrawSprite(13)
218
DrawSprite(14)
219
DrawSprite(15)
220
DrawSprite(16)
221
DrawSprite(17)
222
break
223
end switch
224
end sub
225
226
227
sub ObjectStartup
228
LoadSpriteSheet("R8/Objects2.gif")
229
230
// First Piece
231
SpriteFrame(-80, -8, 24, 24, 133, 1) // #0 - Spike Small Chunk
232
SpriteFrame(-56, -8, 32, 24, 100, 1) // #1 - Spike Medium Chunk
233
SpriteFrame(-24, -8, 24, 16, 158, 1) // #2 - Spike BG Chunk
234
SpriteFrame(0, -8, 24, 16, 158, 1) // #3 - Spike BG Chunk
235
SpriteFrame(24, -8, 32, 24, 100, 1) // #4 - Spike Medium Chunk
236
SpriteFrame(56, -8, 24, 24, 133, 1) // #5 - Spike Small Chunk
237
238
// Second Piece
239
SpriteFrame(-80, -8, 24, 24, 133, 1) // #6 - Spike Small Chunk
240
SpriteFrame(-56, -8, 24, 16, 158, 1) // #7 - Spike BG Chunk
241
SpriteFrame(-32, -8, 24, 16, 158, 1) // #8 - Spike BG Chunk
242
SpriteFrame(-8, -8, 32, 24, 100, 1) // #9 - Spike Medium Chunk
243
SpriteFrame(24, -8, 32, 24, 100, 1) // #10 - Spike Medium Chunk
244
SpriteFrame(56, -8, 24, 24, 133, 1) // #11 - Spike Small Chunk
245
246
// Third Piece
247
SpriteFrame(-80, -8, 32, 24, 100, 1) // #12 - Spike Medium Chunk
248
SpriteFrame(-48, -8, 32, 24, 100, 1) // #13 - Spike Medium Chunk
249
SpriteFrame(-16, -8, 24, 24, 133, 1) // #14 - Spike Small Chunk
250
SpriteFrame(8, -8, 24, 16, 158, 1) // #15 - Spike BG Chunk
251
SpriteFrame(32, -8, 24, 16, 158, 1) // #16 - Spike BG Chunk
252
SpriteFrame(56, -8, 24, 24, 133, 1) // #17 - Spike Small Chunk
253
254
end sub
255
256
257
// ========================
258
// Editor Subs
259
// ========================
260
261
sub RSDKEdit
262
if Editor.ReturnVariable == true
263
switch Editor.VariableID
264
case EDIT_VAR_PROPVAL // Property Value
265
CheckResult = Object.PropertyValue
266
CheckResult &= 1
267
break
268
case 0 // type
269
CheckResult = Object.PropertyValue
270
CheckResult &= 1
271
break
272
end switch
273
else
274
switch Editor.VariableID
275
case EDIT_VAR_PROPVAL // Property Value
276
Object.PropertyValue = Editor.VariableValue
277
Object.PropertyValue &= 1
278
break
279
case 0 // type
280
Object.PropertyValue = Editor.VariableValue
281
Object.PropertyValue &= 1
282
break
283
end switch
284
end if
285
end sub
286
287
288
sub RSDKDraw
289
TempValue1 = 0
290
TempValue2 = TempValue1
291
TempValue2 += 6
292
while TempValue1 < TempValue2
293
DrawSprite(TempValue1)
294
TempValue1++
295
loop
296
297
if Editor.ShowGizmos == true
298
Editor.DrawingOverlay = true
299
TempValue0 = Object.YPos
300
TempValue0 += 0x600000
301
Object.InkEffect = 1
302
ArrayPos0 = 5
303
while ArrayPos0 > 1
304
switch ArrayPos0
305
case 5
306
case 3
307
case 1
308
TempValue1 = 0
309
break
310
case 2
311
if Object.PropertyValue == PUZZLE_A
312
TempValue1 = 6
313
else
314
TempValue1 = 12
315
end if
316
break
317
case 4
318
if Object.PropertyValue == PUZZLE_A
319
TempValue1 = 12
320
else
321
TempValue1 = 6
322
end if
323
break
324
end switch
325
TempValue2 = TempValue1
326
TempValue2 += 6
327
while TempValue1 < TempValue2
328
DrawSpriteFX(TempValue1, FX_INK, Object.XPos, TempValue0)
329
TempValue1++
330
loop
331
TempValue0 -= 0x180000
332
ArrayPos0 --
333
loop
334
ArrayPos0 = Object.EntityNo
335
ArrayPos1 = ArrayPos0
336
ArrayPos1 += 5
337
while ArrayPos0 <= ArrayPos1
338
if Object[ArrayPos0].Type == TypeName[Blank Object]
339
DrawLine(Object.XPos, Object.YPos, Object[ArrayPos0].XPos, Object[ArrayPos0].YPos, 255, 255, 0)
340
end if
341
ArrayPos0++
342
loop
343
Editor.DrawingOverlay = false
344
end if
345
end sub
346
347
348
sub RSDKLoad
349
LoadSpriteSheet("R8/Objects2.gif")
350
351
// First Piece
352
SpriteFrame(-80, -8, 24, 24, 133, 1) // #0 - Spike Small Chunk
353
SpriteFrame(-56, -8, 32, 24, 100, 1) // #1 - Spike Medium Chunk
354
SpriteFrame(-24, -8, 24, 16, 158, 1) // #2 - Spike BG Chunk
355
SpriteFrame(0, -8, 24, 16, 158, 1) // #3 - Spike BG Chunk
356
SpriteFrame(24, -8, 32, 24, 100, 1) // #4 - Spike Medium Chunk
357
SpriteFrame(56, -8, 24, 24, 133, 1) // #5 - Spike Small Chunk
358
359
// Second Piece
360
SpriteFrame(-80, -8, 24, 24, 133, 1) // #6 - Spike Small Chunk
361
SpriteFrame(-56, -8, 24, 16, 158, 1) // #7 - Spike BG Chunk
362
SpriteFrame(-32, -8, 24, 16, 158, 1) // #8 - Spike BG Chunk
363
SpriteFrame(-8, -8, 32, 24, 100, 1) // #9 - Spike Medium Chunk
364
SpriteFrame(24, -8, 32, 24, 100, 1) // #10 - Spike Medium Chunk
365
SpriteFrame(56, -8, 24, 24, 133, 1) // #11 - Spike Small Chunk
366
367
// Third Piece
368
SpriteFrame(-80, -8, 32, 24, 100, 1) // #12 - Spike Medium Chunk
369
SpriteFrame(-48, -8, 32, 24, 100, 1) // #13 - Spike Medium Chunk
370
SpriteFrame(-16, -8, 24, 24, 133, 1) // #14 - Spike Small Chunk
371
SpriteFrame(8, -8, 24, 16, 158, 1) // #15 - Spike BG Chunk
372
SpriteFrame(32, -8, 24, 16, 158, 1) // #16 - Spike BG Chunk
373
SpriteFrame(56, -8, 24, 24, 133, 1) // #17 - Spike Small Chunk
374
375
AddEditorVariable("puzzle")
376
SetActiveVariable("puzzle")
377
AddEnumVariable("Puzzle A", PUZZLE_A)
378
AddEnumVariable("Puzzle B", PUZZLE_B)
379
end sub
380
381