Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 2/Scripts/CPZ/RotatingStair.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Rotating Stair Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.value0 : object.blockPos1.x
13
private alias object.value1 : object.blockPos1.y
14
private alias object.value2 : object.blockPos2.x
15
private alias object.value3 : object.blockPos2.y
16
private alias object.value4 : object.blockPos3.x
17
private alias object.value5 : object.blockPos3.y
18
private alias object.value6 : object.blockPos4.x
19
private alias object.value7 : object.blockPos4.y
20
21
// Probably unused since this object was likely based off SLZ's RotatingStair
22
private alias object.value8 : object.blockPos5.x
23
private alias object.value9 : object.blockPos5.y
24
private alias object.value10 : object.blockPos6.x
25
private alias object.value11 : object.blockPos6.y
26
private alias object.value12 : object.blockPos7.x
27
private alias object.value13 : object.blockPos7.y
28
private alias object.value14 : object.blockPos8.x
29
private alias object.value15 : object.blockPos8.y
30
31
private alias object.value16 : object.startPos.x
32
private alias object.value17 : object.startPos.y
33
34
private alias object.value20 : object.playerCollisions // Introduced in Origins Plus, stores what side of the stairs each player is touching
35
36
// Player Aliases
37
private alias object.state : player.state
38
private alias object.xpos : player.xpos
39
private alias object.ypos : player.ypos
40
private alias object.gravity : player.gravity
41
private alias object.animation : player.animation
42
43
private alias object.value1 : player.timer
44
private alias object.value17 : debugMode.currentSelection
45
46
// ========================
47
// Function Declarations
48
// ========================
49
50
reserve function RotatingStair_DebugDraw
51
reserve function RotatingStair_DebugSpawn
52
reserve function RotatingStair_ProcessBlock
53
54
55
// ========================
56
// Static Values
57
// ========================
58
59
private value RotatingStair_debugStartID = 0
60
61
// Introduced in Origins Plus
62
private value RotatingStair_playerSideStore = 0
63
private value RotatingStair_playerSideStore2 = 0
64
65
66
// ========================
67
// Function Definitions
68
// ========================
69
70
private function RotatingStair_DebugDraw
71
temp0 = object.xpos
72
temp0 -= 0x300000
73
74
temp1 = object.ypos
75
temp1 -= 0x300000
76
77
temp3 = debugMode[0].currentSelection
78
temp3 -= RotatingStair_debugStartID
79
80
if temp3 < 2
81
temp2 = 0
82
while temp2 < 4
83
DrawSpriteXY(0, temp0, temp1)
84
temp0 += 0x200000
85
temp1 += 0x200000
86
temp2++
87
loop
88
else
89
DrawSpriteXY(0, temp0, temp1)
90
temp0 += 0x600000
91
temp1 += 0x600000
92
DrawSpriteXY(0, temp0, temp1)
93
end if
94
end function
95
96
97
private function RotatingStair_DebugSpawn
98
CreateTempObject(TypeName[Rotating Stair], 0, object.xpos, object.ypos)
99
object[tempObjectPos].startPos.x = object.xpos
100
object[tempObjectPos].startPos.y = object.ypos
101
object[tempObjectPos].propertyValue = debugMode[0].currentSelection
102
object[tempObjectPos].propertyValue -= RotatingStair_debugStartID
103
end function
104
105
106
private function RotatingStair_ProcessBlock
107
temp1 = temp5
108
GetTableValue(temp0, temp3, StageSetup_oscillationTable)
109
temp0 <<= 8
110
if temp3 == 20
111
temp0 >>= 1
112
end if
113
114
switch temp4
115
case 0
116
temp0 -= temp1
117
temp0 += object.startPos.x
118
temp6 = temp0
119
FlipSign(temp1)
120
temp1 += object.startPos.y
121
temp7 = temp1
122
break
123
124
case 1
125
temp0 -= temp1
126
FlipSign(temp0)
127
temp0 += object.startPos.y
128
temp7 = temp0
129
temp1 += object.startPos.x
130
temp6 = temp1
131
break
132
133
case 2
134
temp0 -= temp1
135
FlipSign(temp0)
136
temp0 += object.startPos.x
137
temp6 = temp0
138
temp1 += object.startPos.y
139
temp7 = temp1
140
break
141
142
case 3
143
temp0 -= temp1
144
temp0 += object.startPos.y
145
temp7 = temp0
146
FlipSign(temp1)
147
temp1 += object.startPos.x
148
temp6 = temp1
149
break
150
end switch
151
152
temp6 &= 0xFFFF0000
153
temp7 &= 0xFFFF0000
154
temp0 = temp6
155
temp0 -= object.xpos
156
temp1 = temp7
157
temp1 -= object.ypos
158
159
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
160
BoxCollisionTest(C_SOLID, object.entityPos, -16, -16, 16, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
161
switch checkResult
162
case COL_TOP
163
player[currentPlayer].xpos += temp0
164
player[currentPlayer].ypos += temp1
165
break
166
167
case COL_LEFT
168
case COL_RIGHT
169
#platform: USE_ORIGINS
170
if checkResult == COL_LEFT
171
RotatingStair_playerSideStore = 1
172
RotatingStair_playerSideStore <<= currentPlayer
173
RotatingStair_playerSideStore <<= currentPlayer
174
object.playerCollisions |= RotatingStair_playerSideStore
175
else
176
RotatingStair_playerSideStore = 2
177
RotatingStair_playerSideStore <<= currentPlayer
178
RotatingStair_playerSideStore <<= currentPlayer
179
object.playerCollisions |= RotatingStair_playerSideStore
180
end if
181
#endplatform
182
183
if player[currentPlayer].state == Player_State_Climb
184
player[currentPlayer].timer = 0
185
player[currentPlayer].animation = ANI_GLIDING_DROP
186
player[currentPlayer].state = Player_State_GlideDrop
187
end if
188
break
189
190
case COL_BOTTOM
191
if player[currentPlayer].gravity == GRAVITY_GROUND
192
if temp1 >= 0
193
CallFunction(Player_Kill)
194
end if
195
end if
196
break
197
end switch
198
next
199
end function
200
201
202
// ========================
203
// Events
204
// ========================
205
206
event ObjectUpdate
207
temp4 = CPZSetup_rotatingStairTimer
208
GetBit(temp0, object.propertyValue, 0)
209
if temp0 == true
210
temp4 ^= 1
211
end if
212
213
#platform: USE_ORIGINS
214
object.playerCollisions = 0
215
#endplatform
216
217
GetBit(temp0, object.propertyValue, 1)
218
if temp0 == false
219
temp5 = 0x100000
220
temp3 = 20
221
object.xpos = object.blockPos1.x
222
object.ypos = object.blockpos1.y
223
CallFunction(RotatingStair_ProcessBlock)
224
object.blockPos1.x = temp6
225
object.blockpos1.y = temp7
226
227
temp4 ^= 2
228
object.xpos = object.blockpos2.x
229
object.ypos = object.blockpos2.y
230
CallFunction(RotatingStair_ProcessBlock)
231
object.blockpos2.x = temp6
232
object.blockpos2.y = temp7
233
234
temp4 ^= 2
235
end if
236
237
temp5 = 0x300000
238
temp3 = 22
239
object.xpos = object.blockpos3.x
240
object.ypos = object.blockpos3.y
241
CallFunction(RotatingStair_ProcessBlock)
242
object.blockpos3.x = temp6
243
object.blockpos3.y = temp7
244
245
temp4 ^= 2
246
object.xpos = object.blockpos4.x
247
object.ypos = object.blockpos4.y
248
CallFunction(RotatingStair_ProcessBlock)
249
object.blockpos4.x = temp6
250
object.blockpos4.y = temp7
251
252
temp4 ^= 2
253
temp5 = 0x500000
254
temp3 = 24
255
// (normally in the SLZ script block 5 would be processed right here, but CPZ staris only have 4 blocks, so..)
256
257
object.xpos = object.startPos.x
258
object.ypos = object.startPos.y
259
260
#platform: USE_ORIGINS
261
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
262
RotatingStair_playerSideStore2 = object.playerCollisions
263
RotatingStair_playerSideStore2 >>= currentPlayer
264
RotatingStair_playerSideStore2 >>= currentPlayer
265
266
if RotatingStair_playerSideStore2 > 0
267
temp6 = player[currentPlayer].xpos
268
temp7 = player[currentPlayer].ypos
269
270
ObjectTileCollision(CSIDE_LENTITY, currentPlayer, object.collisionRight, 45)
271
if checkResult == true
272
RotatingStair_playerSideStore2 |= 1
273
end if
274
275
ObjectTileCollision(CSIDE_RENTITY, currentPlayer, object.collisionLeft, 45)
276
if checkResult == true
277
RotatingStair_playerSideStore2 |= 2
278
end if
279
280
if RotatingStair_playerSideStore2 == 3
281
CallFunction(Player_Kill)
282
end if
283
284
player[currentPlayer].xpos = temp6
285
player[currentPlayer].ypos = temp7
286
end if
287
next
288
#endplatform
289
end event
290
291
292
event ObjectDraw
293
GetBit(temp0, object.propertyValue, 1)
294
if temp0 == false
295
DrawSpriteXY(0, object.blockPos1.x, object.blockPos1.y)
296
DrawSpriteXY(0, object.blockpos2.x, object.blockpos2.y)
297
end if
298
299
DrawSpriteXY(0, object.blockpos3.x, object.blockpos3.y)
300
DrawSpriteXY(0, object.blockpos4.x, object.blockpos4.y)
301
end event
302
303
304
event ObjectStartup
305
CheckCurrentStageFolder("Zone02")
306
if checkResult == true
307
LoadSpriteSheet("CPZ/Objects3.gif")
308
SpriteFrame(-16, -16, 32, 32, 1, 62)
309
else
310
LoadSpriteSheet("MBZ/Objects.gif")
311
SpriteFrame(-16, -16, 32, 32, 130, 829)
312
end if
313
314
foreach (TypeName[Rotating Stair], arrayPos0, ALL_ENTITIES)
315
object[arrayPos0].startPos.x = object[arrayPos0].xpos
316
object[arrayPos0].startPos.y = object[arrayPos0].ypos
317
next
318
319
temp0 = 0
320
RotatingStair_debugStartID = DebugMode_ObjCount
321
while temp0 < 4
322
SetTableValue(TypeName[Rotating Stair], DebugMode_ObjCount, DebugMode_TypesTable)
323
SetTableValue(RotatingStair_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
324
SetTableValue(RotatingStair_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
325
DebugMode_ObjCount++
326
temp0++
327
loop
328
end event
329
330
331
// ========================
332
// Editor Events
333
// ========================
334
335
event RSDKEdit
336
if editor.returnVariable == true
337
switch editor.variableID
338
case EDIT_VAR_PROPVAL // property value
339
checkResult = object.propertyValue
340
break
341
342
case 0 // direction
343
GetBit(checkResult, object.propertyValue, 0)
344
break
345
346
case 1 // type
347
GetBit(checkResult, object.propertyValue, 1)
348
break
349
350
end switch
351
else
352
switch editor.variableID
353
case EDIT_VAR_PROPVAL // property value
354
object.propertyValue = editor.variableValue
355
break
356
357
case 0 // direction
358
CheckNotEqual(editor.variableValue, 0)
359
SetBit(object.propertyValue, 0, checkResult)
360
break
361
362
case 1 // type
363
CheckNotEqual(editor.variableValue, 0)
364
SetBit(object.propertyValue, 1, checkResult)
365
break
366
367
end switch
368
end if
369
end event
370
371
372
event RSDKDraw
373
temp0 = object.xpos
374
temp0 -= 0x300000
375
376
temp1 = object.ypos
377
temp1 -= 0x300000
378
379
if object.propertyValue < 2
380
temp2 = 0
381
while temp2 < 4
382
DrawSpriteXY(0, temp0, temp1)
383
temp0 += 0x200000
384
temp1 += 0x200000
385
temp2++
386
loop
387
else
388
DrawSpriteXY(0, temp0, temp1)
389
temp0 += 0x600000
390
temp1 += 0x600000
391
DrawSpriteXY(0, temp0, temp1)
392
end if
393
end event
394
395
396
event RSDKLoad
397
CheckCurrentStageFolder("Zone02")
398
if checkResult == true
399
LoadSpriteSheet("CPZ/Objects3.gif")
400
SpriteFrame(-16, -16, 32, 32, 1, 62)
401
else
402
LoadSpriteSheet("MBZ/Objects.gif")
403
SpriteFrame(-16, -16, 32, 32, 130, 829)
404
end if
405
406
AddEditorVariable("direction")
407
SetActiveVariable("direction")
408
AddEnumVariable("No Flip", 0)
409
AddEnumVariable("Flip X", 1)
410
411
AddEditorVariable("type")
412
SetActiveVariable("type")
413
AddEnumVariable("4 Blocks", 0)
414
AddEnumVariable("2 Blocks", 1)
415
end event
416
417