Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/SLZ/RisingPlatform.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Rising Platform Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
// Platform
13
private alias object.value0 : object.startPos.x
14
private alias object.value1 : object.startPos.y
15
private alias object.value2 : object.collisionOffset.x
16
private alias object.value3 : object.collisionOffset.y
17
private alias object.value4 : object.moveVel
18
private alias object.value5 : object.halfwayDist
19
private alias object.value6 : object.movePos
20
private alias object.value7 : object.reverseDir
21
private alias object.value8 : object.finishedMoving
22
23
// Spawner
24
private alias object.value0 : object.interval
25
private alias object.value1 : object.timer
26
27
private alias 0 : RISINGPLAT_MOVE_UP_IDLE
28
private alias 1 : RISINGPLAT_MOVE_UP
29
private alias 2 : RISINGPLAT_MOVE_DOWN_IDLE
30
private alias 3 : RISINGPLAT_MOVE_DOWN
31
private alias 4 : RISINGPLAT_MOVE_UP_RIGHT_IDLE
32
private alias 5 : RISINGPLAT_MOVE_UP_RIGHT
33
private alias 6 : RISINGPLAT_MOVE_DOWN_LEFT_IDLE
34
private alias 7 : RISINGPLAT_MOVE_DOWN_LEFT
35
private alias 8 : RISINGPLAT_FADEAWAY
36
private alias 9 : RISINGPLAT_SPAWNER
37
private alias 10 : RISINGPLAT_TRYRESET
38
39
// Player Aliases
40
private alias object.xpos : player.xpos
41
private alias object.ypos : player.ypos
42
43
private alias object.value17 : debugMode.currentSelection
44
45
46
// ========================
47
// Function Declarations
48
// ========================
49
50
reserve function RisingPlatform_DebugDraw
51
reserve function RisingPlatform_DebugSpawn
52
reserve function RisingPlatform_HandleMovement
53
reserve function RisingPlatform_HandleMoveFade
54
reserve function RisingPlatform_HandleCollisions
55
reserve function RisingPlatform_CheckOnScreen
56
57
58
// ========================
59
// Static Values
60
// ========================
61
62
private value RisingPlatform_startDebugID = 0
63
64
65
// ========================
66
// Tables
67
// ========================
68
69
private table RisingPlatform_distanceTable
70
0x400000
71
0x800000
72
0xD00000
73
0x400000
74
0x800000
75
0xD00000
76
0x500000
77
0x900000
78
0xB00000
79
0x500000
80
0x900000
81
0xB00000
82
0x800000
83
0x800000
84
0xC00000
85
end table
86
87
private table RisingPlatform_stateTable
88
0 // RISINGPLAT_MOVE_UP_IDLE
89
0 // RISINGPLAT_MOVE_UP_IDLE
90
0 // RISINGPLAT_MOVE_UP_IDLE
91
2 // RISINGPLAT_MOVE_DOWN_IDLE
92
2 // RISINGPLAT_MOVE_DOWN_IDLE
93
2 // RISINGPLAT_MOVE_DOWN_IDLE
94
0 // RISINGPLAT_MOVE_UP_IDLE
95
0 // RISINGPLAT_MOVE_UP_IDLE
96
0 // RISINGPLAT_MOVE_UP_IDLE
97
2 // RISINGPLAT_MOVE_DOWN_IDLE
98
2 // RISINGPLAT_MOVE_DOWN_IDLE
99
2 // RISINGPLAT_MOVE_DOWN_IDLE
100
4 // RISINGPLAT_MOVE_UP_RIGHT_IDLE
101
6 // RISINGPLAT_MOVE_DOWN_LEFT_IDLE
102
8 // RISINGPLAT_FADEAWAY
103
end table
104
105
106
// ========================
107
// Function Definitions
108
// ========================
109
110
private function RisingPlatform_DebugDraw
111
DrawSprite(0)
112
end function
113
114
115
private function RisingPlatform_DebugSpawn
116
temp0 = debugMode[0].currentSelection
117
temp0 -= RisingPlatform_startDebugID
118
119
CreateTempObject(TypeName[Rising Platform], temp0, object.xpos, object.ypos)
120
121
if temp0 < 14
122
object[tempObjectPos].startPos.x = object[tempObjectPos].xpos
123
object[tempObjectPos].startPos.y = object[tempObjectPos].ypos
124
object[tempObjectPos].collisionOffset.x = object[tempObjectPos].xpos
125
object[tempObjectPos].collisionOffset.y = object[tempObjectPos].ypos
126
temp0 = object[tempObjectPos].propertyValue
127
temp0 &= 15
128
GetTableValue(object[tempObjectPos].halfwayDist, temp0, RisingPlatform_distanceTable)
129
GetTableValue(object[tempObjectPos].state, temp0, RisingPlatform_stateTable)
130
object[tempObjectPos].movePos = 0
131
object[tempObjectPos].reverseDir = 0
132
object[tempObjectPos].finishedMoving = false
133
else
134
object[tempObjectPos].interval = 60
135
object[tempObjectPos].timer = 60
136
object[tempObjectPos].state = RISINGPLAT_SPAWNER
137
object[tempObjectPos].priority = PRIORITY_XBOUNDS
138
end if
139
end function
140
141
142
private function RisingPlatform_HandleMovement
143
if object.reverseDir == false
144
if object.moveVel < 0x80000
145
object.moveVel += 0x1000
146
end if
147
else
148
if object.moveVel > 0x4000
149
object.moveVel -= 0x1000
150
end if
151
end if
152
153
if object.movePos > object.halfwayDist
154
object.reverseDir = true
155
end if
156
157
object.movePos += object.moveVel
158
159
temp0 = object.halfwayDist
160
temp0 <<= 1
161
162
if object.movePos >= temp0
163
object.finishedMoving = true
164
object.movePos = temp0
165
end if
166
end function
167
168
169
private function RisingPlatform_HandleMoveFade
170
if object.reverseDir == false
171
if object.moveVel < 0x80000
172
object.moveVel += 0x1000
173
end if
174
else
175
if object.moveVel > 0
176
object.moveVel -= 0x1000
177
end if
178
end if
179
180
if object.movePos > object.halfwayDist
181
object.reverseDir = true
182
end if
183
184
object.movePos += object.moveVel
185
186
if object.moveVel == 0
187
object.finishedMoving = true
188
end if
189
end function
190
191
192
private function RisingPlatform_HandleCollisions
193
temp6 = object.xpos
194
temp6 &= 0xFFFF0000
195
temp0 = object.collisionOffset.x
196
temp0 &= 0xFFFF0000
197
198
temp6 -= temp0
199
temp7 = object.ypos
200
temp7 &= 0xFFFF0000
201
temp0 = object.collisionOffset.y
202
temp0 &= 0xFFFF0000
203
temp7 -= temp0
204
205
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
206
BoxCollisionTest(C_PLATFORM, object.entityPos, -40, -8, 40, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
207
if checkResult == true
208
player[currentPlayer].xpos -= temp6
209
player[currentPlayer].ypos -= temp7
210
end if
211
next
212
213
object.xpos = object.collisionOffset.x
214
object.ypos = object.collisionOffset.y
215
end function
216
217
218
private function RisingPlatform_CheckOnScreen
219
if object.outOfBounds == true
220
object.xpos = object.startPos.x
221
object.ypos = object.startPos.y
222
object.collisionOffset.x = object.xpos
223
object.collisionOffset.y = object.ypos
224
object.movePos = 0
225
object.reverseDir = 0
226
object.finishedMoving = false
227
object.state = RISINGPLAT_TRYRESET
228
end if
229
end function
230
231
232
// ========================
233
// Events
234
// ========================
235
236
event ObjectUpdate
237
switch object.state
238
case RISINGPLAT_MOVE_UP_IDLE
239
case RISINGPLAT_MOVE_DOWN_IDLE
240
case RISINGPLAT_MOVE_UP_RIGHT_IDLE
241
case RISINGPLAT_MOVE_DOWN_LEFT_IDLE
242
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
243
BoxCollisionTest(C_PLATFORM, object.entityPos, -40, -8, 40, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
244
if checkResult == true
245
object.state++
246
object.priority = PRIORITY_ACTIVE
247
end if
248
next
249
break
250
251
case RISINGPLAT_MOVE_UP
252
CallFunction(RisingPlatform_HandleMovement)
253
object.collisionOffset.y = object.movePos
254
FlipSign(object.collisionOffset.y)
255
object.collisionOffset.y += object.startPos.y
256
CallFunction(RisingPlatform_HandleCollisions)
257
CallFunction(RisingPlatform_CheckOnScreen)
258
break
259
260
case RISINGPLAT_MOVE_DOWN
261
CallFunction(RisingPlatform_HandleMovement)
262
object.collisionOffset.y = object.movePos
263
object.collisionOffset.y += object.startPos.y
264
CallFunction(RisingPlatform_HandleCollisions)
265
CallFunction(RisingPlatform_CheckOnScreen)
266
break
267
268
case RISINGPLAT_MOVE_UP_RIGHT
269
CallFunction(RisingPlatform_HandleMovement)
270
object.collisionOffset.y = object.movePos
271
object.collisionOffset.y >>= 1
272
FlipSign(object.collisionOffset.y)
273
object.collisionOffset.y += object.startPos.y
274
275
object.collisionOffset.x = object.movePos
276
object.collisionOffset.x += object.startPos.x
277
CallFunction(RisingPlatform_HandleCollisions)
278
CallFunction(RisingPlatform_CheckOnScreen)
279
break
280
281
case RISINGPLAT_MOVE_DOWN_LEFT
282
CallFunction(RisingPlatform_HandleMovement)
283
object.collisionOffset.y = object.movePos
284
object.collisionOffset.y >>= 1
285
object.collisionOffset.y += object.startPos.y
286
287
object.collisionOffset.x = object.movePos
288
FlipSign(object.collisionOffset.x)
289
object.collisionOffset.x += object.startPos.x
290
CallFunction(RisingPlatform_HandleCollisions)
291
CallFunction(RisingPlatform_CheckOnScreen)
292
break
293
294
case RISINGPLAT_FADEAWAY
295
CallFunction(RisingPlatform_HandleMoveFade)
296
object.collisionOffset.y = object.movePos
297
FlipSign(object.collisionOffset.y)
298
object.collisionOffset.y += object.startPos.y
299
CallFunction(RisingPlatform_HandleCollisions)
300
temp0 = object.moveVel
301
temp0 >>= 8
302
if temp0 > 0x100
303
temp0 = 0x100
304
end if
305
object.alpha = temp0
306
307
if object.finishedMoving == true
308
object.type = TypeName[Blank Object]
309
end if
310
break
311
312
case RISINGPLAT_SPAWNER
313
object.timer--
314
if object.timer <= 0
315
CreateTempObject(TypeName[Rising Platform], 0, object.xpos, object.ypos)
316
object[tempObjectPos].startPos.x = object.xpos
317
object[tempObjectPos].startPos.y = object.ypos
318
object[tempObjectPos].collisionOffset.x = object.xpos
319
object[tempObjectPos].collisionOffset.y = object.ypos
320
temp0 = 14
321
GetTableValue(object[tempObjectPos].halfwayDist, temp0, RisingPlatform_distanceTable)
322
GetTableValue(object[tempObjectPos].state, temp0, RisingPlatform_stateTable)
323
object[tempObjectPos].movePos = 0
324
object[tempObjectPos].reverseDir = false
325
object[tempObjectPos].finishedMoving = false
326
object[tempObjectPos].inkEffect = INK_ALPHA
327
object.timer = object.interval
328
end if
329
break
330
331
case RISINGPLAT_TRYRESET
332
if object.outOfBounds == true
333
temp0 = object.propertyValue
334
temp0 &= 15
335
GetTableValue(object.halfwayDist, temp0, RisingPlatform_distanceTable)
336
GetTableValue(object.state, temp0, RisingPlatform_stateTable)
337
object.priority = PRIORITY_BOUNDS
338
end if
339
break
340
341
end switch
342
end event
343
344
345
event ObjectDraw
346
if object.state == RISINGPLAT_FADEAWAY
347
DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
348
else
349
if object.state < RISINGPLAT_SPAWNER
350
DrawSprite(0)
351
end if
352
end if
353
end event
354
355
356
event ObjectStartup
357
LoadSpriteSheet("SLZ/Objects.gif")
358
SpriteFrame(-40, -8, 80, 32, 84, 188)
359
360
foreach (TypeName[Rising Platform], arrayPos0, ALL_ENTITIES)
361
GetBit(temp0, object[arrayPos0].propertyValue, 7)
362
if temp0 == false
363
object[arrayPos0].startPos.x = object[arrayPos0].xpos
364
object[arrayPos0].startPos.y = object[arrayPos0].ypos
365
object[arrayPos0].collisionOffset.x = object[arrayPos0].xpos
366
object[arrayPos0].collisionOffset.y = object[arrayPos0].ypos
367
temp0 = object[arrayPos0].propertyValue
368
temp0 &= 15
369
GetTableValue(object[arrayPos0].halfwayDist, temp0, RisingPlatform_distanceTable)
370
GetTableValue(object[arrayPos0].state, temp0, RisingPlatform_stateTable)
371
object[arrayPos0].movePos = 0
372
object[arrayPos0].reverseDir = false
373
object[arrayPos0].finishedMoving = false
374
else
375
object[arrayPos0].interval = object[arrayPos0].propertyValue
376
object[arrayPos0].interval &= 0x7F
377
object[arrayPos0].interval *= 6
378
object[arrayPos0].timer = object[arrayPos0].interval
379
object[arrayPos0].state = RISINGPLAT_SPAWNER
380
object[arrayPos0].priority = PRIORITY_XBOUNDS
381
end if
382
next
383
384
temp0 = 0
385
RisingPlatform_startDebugID = DebugMode_ObjCount
386
while temp0 < 15
387
SetTableValue(TypeName[Rising Platform], DebugMode_ObjCount, DebugMode_TypesTable)
388
SetTableValue(RisingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
389
SetTableValue(RisingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
390
DebugMode_ObjCount++
391
temp0++
392
loop
393
end event
394
395
396
// ========================
397
// Editor Events
398
// ========================
399
400
event RSDKEdit
401
if editor.returnVariable == true
402
switch editor.variableID
403
case EDIT_VAR_PROPVAL // property value
404
checkResult = object.propertyValue
405
break
406
407
case 0 // type
408
GetBit(temp0, object.propertyValue, 7)
409
if temp0 == 0
410
checkResult = object.propertyValue
411
checkResult &= 0x0F
412
else
413
checkResult = 0
414
end if
415
break
416
417
case 1 // spawnInterval
418
checkResult = object.propertyValue
419
checkResult &= 0x7F
420
break
421
422
end switch
423
else
424
switch editor.variableID
425
case EDIT_VAR_PROPVAL // property value
426
object.propertyValue = editor.variableValue
427
break
428
429
case 0 // type
430
editor.variableValue &= 0x0F
431
432
object.propertyValue = editor.variableValue
433
break
434
435
case 1 // spawnInterval
436
if editor.variableValue > 0 // it is "possible" to do 0 interval, but that would prolly just kill the game so actually no its not :]
437
editor.variableValue &= 0x7F
438
439
object.propertyValue = editor.variableValue
440
object.propertyValue |= 0x80
441
else
442
object.propertyValue = 0
443
end if
444
break
445
446
end switch
447
end if
448
end event
449
450
451
event RSDKDraw
452
DrawSprite(0)
453
end event
454
455
456
event RSDKLoad
457
LoadSpriteSheet("SLZ/Objects.gif")
458
SpriteFrame(-40, -8, 80, 32, 84, 188)
459
460
AddEditorVariable("type")
461
SetActiveVariable("type")
462
AddEnumVariable("Up (Slow)", 0)
463
AddEnumVariable("Up (Med)", 1)
464
AddEnumVariable("Up (Fast)", 2)
465
AddEnumVariable("Down (Slow)", 3)
466
AddEnumVariable("Down (Med)", 4)
467
AddEnumVariable("Down (Fast)", 5)
468
AddEnumVariable("Up (Slow, Faster)", 6)
469
AddEnumVariable("Up (Med, Faster)", 7)
470
AddEnumVariable("Up (Fast, Faster)", 8)
471
AddEnumVariable("Down (Slow, Faster)", 9)
472
AddEnumVariable("Down (Med, Faster)", 10)
473
AddEnumVariable("Down (Fast, Faster)", 11)
474
AddEnumVariable("Up-Right", 12)
475
AddEnumVariable("Down-Left", 13)
476
477
// Intervals of 6 (so 6, 12, 18, 24, etc...)
478
AddEditorVariable("spawnInterval")
479
SetActiveVariable("spawnInterval")
480
end event
481
482