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/OOZ/SwingPlat.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Swing Platform 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.propertyValue : object.length
13
14
private alias object.value0 : object.swingAngle
15
private alias object.value1 : object.drawPos.x
16
private alias object.value2 : object.drawPos.y
17
private alias object.value3 : object.collisionOffset.x
18
private alias object.value4 : object.collisionOffset.y
19
private alias object.value45 : object.canSnap
20
21
// States
22
private alias 0 : SWINGPLAT_SWING
23
private alias 1 : SWINGPLAT_SNAPPED
24
private alias 2 : SWINGPLAT_FLOATING
25
26
// Player Aliases
27
private alias object.xpos : player.xpos
28
private alias object.ypos : player.ypos
29
30
private alias object.value17 : debugMode.currentSelection
31
32
33
// ========================
34
// Function Declarations
35
// ========================
36
37
reserve function SwingPlatform_DebugDraw
38
reserve function SwingPlatform_DebugSpawn
39
40
41
// ========================
42
// Static Values
43
// ========================
44
45
private value SwingPlatform_startDebugID = 0
46
47
48
// ========================
49
// Function Definitions
50
// ========================
51
52
private function SwingPlatform_DebugDraw
53
temp7 = debugMode[0].currentSelection
54
temp7 -= SwingPlatform_startDebugID
55
56
// Draw the post
57
DrawSprite(0)
58
59
// Draw the chains
60
temp0 = 0
61
temp1 = 16
62
while temp0 < temp7
63
Cos(temp2, 128)
64
temp2 *= temp1
65
temp2 <<= 7
66
temp2 += object.xpos
67
Sin(temp3, 128)
68
69
temp3 *= temp1
70
temp3 <<= 7
71
temp3 += object.ypos
72
73
DrawSpriteXY(1, temp2, temp3)
74
temp0++
75
temp1 += 16
76
loop
77
78
// Draw the platform itself
79
temp1 -= 8
80
Cos(temp2, 128)
81
82
temp2 *= temp1
83
temp2 <<= 7
84
temp2 += object.xpos
85
Sin(temp3, 128)
86
87
temp3 *= temp1
88
temp3 <<= 7
89
temp3 += object.ypos
90
91
DrawSpriteXY(2, temp2, temp3)
92
end function
93
94
95
private function SwingPlatform_DebugSpawn
96
temp0 = debugMode[0].currentSelection
97
temp0 -= SwingPlatform_startDebugID
98
CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)
99
object[tempObjectPos].direction = object.direction
100
end function
101
102
103
// ========================
104
// Events
105
// ========================
106
107
event ObjectUpdate
108
temp2 = object.xpos
109
temp3 = object.ypos
110
111
GetTableValue(object.angle, 12, StageSetup_oscillationTable)
112
object.angle >>= 8
113
if object.direction == FLIP_X
114
object.angle ^= 0xFF
115
object.angle += 0x81
116
end if
117
object.angle <<= 1
118
119
temp1 = object.length
120
temp1++
121
temp1 <<= 4
122
temp1 -= 8
123
object.xpos = object.drawPos.x
124
object.ypos = object.drawPos.y
125
126
switch object.state
127
case SWINGPLAT_SWING
128
Cos(object.xpos, object.angle)
129
object.xpos *= temp1
130
object.xpos <<= 7
131
object.xpos += temp2
132
133
Sin(object.ypos, object.angle)
134
object.ypos *= temp1
135
object.ypos <<= 7
136
object.ypos += temp3
137
break
138
139
case SWINGPLAT_SNAPPED
140
object.ypos += object.yvel
141
object.yvel += 0x3000
142
temp7 = 1824 // Y level of oil in the level
143
temp7 <<= 16
144
if object.ypos >= temp7
145
object.state++
146
end if
147
object.xpos += object.xvel
148
break
149
150
case SWINGPLAT_FLOATING
151
Sin(object.ypos, object.swingAngle)
152
object.swingAngle += 6
153
object.swingAngle &= 0x1FF
154
object.ypos >>= 7
155
object.ypos += 1824
156
object.ypos <<= 16
157
break
158
159
end switch
160
161
object.collisionOffset.x = object.xpos
162
object.collisionOffset.x &= 0xFFFF0000
163
temp4 = object.drawPos.x
164
temp4 &= 0xFFFF0000
165
object.collisionOffset.x -= temp4
166
167
object.collisionOffset.y = object.ypos
168
object.collisionOffset.y &= 0xFFFF0000
169
temp5 = object.drawPos.y
170
temp5 &= 0xFFFF0000
171
object.collisionOffset.y -= temp5
172
173
object.drawPos.x = object.xpos
174
object.drawPos.y = object.ypos
175
176
object.xpos = temp4
177
object.ypos = temp5
178
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
179
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
180
if checkResult == true
181
if object.state == SWINGPLAT_SWING
182
if object.canSnap == true
183
if object.angle == 0x000
184
object.xvel = 0x20000
185
object.priority = PRIORITY_ACTIVE
186
object.state = SWINGPLAT_SNAPPED
187
end if
188
189
if object.angle == 0x100
190
object.xvel = -0x20000
191
object.priority = PRIORITY_ACTIVE
192
object.state = SWINGPLAT_SNAPPED
193
end if
194
end if
195
end if
196
player[currentPlayer].xpos += object.collisionOffset.x
197
player[currentPlayer].ypos += object.collisionOffset.y
198
end if
199
next
200
201
if object.state > 0
202
if object.outOfBounds == true
203
object.xpos = temp2
204
object.ypos = temp3
205
if object.outOfBounds == true
206
object.state = SWINGPLAT_SWING
207
object.priority = PRIORITY_BOUNDS
208
object.xvel = 0
209
object.yvel = 0
210
end if
211
end if
212
end if
213
object.xpos = temp2
214
object.ypos = temp3
215
end event
216
217
218
event ObjectDraw
219
temp0 = 0
220
temp1 = 16
221
while temp0 < object.length
222
Cos(temp2, object.angle)
223
temp2 *= temp1
224
temp2 <<= 7
225
temp2 += object.xpos
226
227
Sin(temp3, object.angle)
228
temp3 *= temp1
229
temp3 <<= 7
230
temp3 += object.ypos
231
232
DrawSpriteXY(1, temp2, temp3)
233
temp0++
234
temp1 += 16
235
loop
236
temp1 -= 8
237
238
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
239
DrawSprite(0)
240
end event
241
242
243
event ObjectStartup
244
LoadSpriteSheet("OOZ/Objects.gif")
245
SpriteFrame(-8, -8, 16, 16, 51, 75)
246
SpriteFrame(-8, -8, 16, 16, 51, 75)
247
SpriteFrame(-32, -8, 64, 32, 68, 75)
248
249
foreach (TypeName[Swing Platform], arrayPos0, ALL_ENTITIES)
250
GetBit(object[arrayPos0].canSnap, object[arrayPos0].propertyValue, 7)
251
object[arrayPos0].length &= 0x7F
252
next
253
254
temp0 = 0
255
SwingPlatform_startDebugID = DebugMode_ObjCount
256
SwingPlatform_startDebugID--
257
while temp0 < 8
258
SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)
259
SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
260
SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
261
DebugMode_ObjCount++
262
temp0++
263
loop
264
end event
265
266
267
// ========================
268
// Editor Events
269
// ========================
270
271
event RSDKEdit
272
if editor.returnVariable == true
273
switch editor.variableID
274
case EDIT_VAR_PROPVAL // property value
275
checkResult = object.propertyValue
276
break
277
278
case 0 // length
279
checkResult = object.propertyValue
280
checkResult &= 0x7F
281
break
282
283
case 1 // canSnap
284
GetBit(checkResult, object.propertyValue, 7)
285
break
286
287
end switch
288
else
289
switch editor.variableID
290
case EDIT_VAR_PROPVAL // property value
291
object.propertyValue = editor.variableValue
292
break
293
294
case 0 // length
295
editor.variableValue &= 0x7F
296
object.propertyValue &= 0x80
297
298
object.propertyValue |= editor.variableValue
299
break
300
301
case 1 // canSnap
302
CheckNotEqual(editor.variableValue, false)
303
SetBit(object.propertyValue, 7, checkResult)
304
break
305
306
end switch
307
end if
308
end event
309
310
311
event RSDKDraw
312
temp7 = object.propertyValue
313
temp7 &= 0x7F
314
315
DrawSprite(0)
316
317
temp0 = 0
318
temp1 = 16
319
while temp0 < temp7
320
Cos(temp2, 128)
321
temp2 *= temp1
322
temp2 <<= 7
323
temp2 += object.xpos
324
325
Sin(temp3, 128)
326
temp3 *= temp1
327
temp3 <<= 7
328
temp3 += object.ypos
329
330
DrawSpriteXY(1, temp2, temp3)
331
temp0++
332
temp1 += 16
333
loop
334
temp1 -= 8
335
336
Cos(temp2, 128)
337
temp2 *= temp1
338
temp2 <<= 7
339
temp2 += object.xpos
340
341
Sin(temp3, 128)
342
temp3 *= temp1
343
temp3 <<= 7
344
temp3 += object.ypos
345
346
DrawSpriteXY(2, temp2, temp3)
347
348
if editor.showGizmos == true
349
editor.drawingOverlay = true
350
351
object.inkEffect = INK_BLEND
352
353
// Draw right side
354
temp0 = 0
355
temp1 = 16
356
while temp0 < temp7
357
Cos(temp2, 0)
358
temp2 *= temp1
359
temp2 <<= 7
360
temp2 += object.xpos
361
362
Sin(temp3, 0)
363
temp3 *= temp1
364
temp3 <<= 7
365
temp3 += object.ypos
366
367
DrawSpriteFX(1, FX_INK, temp2, temp3)
368
temp0++
369
temp1 += 16
370
loop
371
temp1 -= 8
372
373
Cos(temp2, 0)
374
temp2 *= temp1
375
temp2 <<= 7
376
temp2 += object.xpos
377
378
Sin(temp3, 0)
379
temp3 *= temp1
380
temp3 <<= 7
381
temp3 += object.ypos
382
383
DrawSpriteFX(2, FX_INK, temp2, temp3)
384
385
// Draw left side
386
temp0 = 0
387
temp1 = 16
388
while temp0 < temp7
389
Cos(temp2, 256)
390
temp2 *= temp1
391
temp2 <<= 7
392
temp2 += object.xpos
393
394
Sin(temp3, 256)
395
temp3 *= temp1
396
temp3 <<= 7
397
temp3 += object.ypos
398
399
DrawSpriteFX(1, FX_INK, temp2, temp3)
400
temp0++
401
temp1 += 16
402
loop
403
temp1 -= 8
404
405
Cos(temp2, 256)
406
temp2 *= temp1
407
temp2 <<= 7
408
temp2 += object.xpos
409
410
Sin(temp3, 256)
411
temp3 *= temp1
412
temp3 <<= 7
413
temp3 += object.ypos
414
415
DrawSpriteFX(2, FX_INK, temp2, temp3)
416
417
editor.drawingOverlay = false
418
end if
419
end event
420
421
422
event RSDKLoad
423
LoadSpriteSheet("OOZ/Objects.gif")
424
SpriteFrame(-8, -8, 16, 16, 51, 75)
425
SpriteFrame(-8, -8, 16, 16, 51, 75)
426
SpriteFrame(-32, -8, 64, 32, 68, 75)
427
428
AddEditorVariable("length")
429
SetActiveVariable("length")
430
431
AddEditorVariable("canSnap")
432
SetActiveVariable("canSnap")
433
AddEnumVariable("false", false)
434
AddEnumVariable("true", true)
435
end event
436
437