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/MCZ/SwingPlat.txt
1483 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.value1 : object.drawPos.x
15
private alias object.value2 : object.drawPos.y
16
private alias object.value3 : object.collisionOffset.x
17
private alias object.value4 : object.collisionOffset.y
18
private alias object.value5 : object.recoilDir
19
private alias object.value6 : object.collided
20
21
private alias 0 : SWINGPLAT_RECOILDIR_LEFT
22
private alias 1 : SWINGPLAT_RECOILDIR_RIGHT
23
24
// Player Aliases
25
private alias object.xpos : player.xpos
26
private alias object.ypos : player.ypos
27
28
private alias object.value17 : debugMode.currentSelection
29
30
31
// ========================
32
// Function Declarations
33
// ========================
34
35
reserve function SwingPlatform_DebugDraw
36
reserve function SwingPlatform_DebugSpawn
37
38
39
// ========================
40
// Static Values
41
// ========================
42
43
private value SwingPlatform_startDebugID = 0
44
45
46
// ========================
47
// Function Definitions
48
// ========================
49
50
private function SwingPlatform_DebugDraw
51
52
temp7 = debugMode[0].currentSelection
53
temp7 -= SwingPlatform_startDebugID
54
55
// Draw the chains
56
temp0 = 0
57
temp1 = 16
58
while temp0 < temp7
59
Cos(temp2, 128)
60
temp2 *= temp1
61
temp2 <<= 7
62
temp2 += object.xpos
63
64
Sin(temp3, 128)
65
temp3 *= temp1
66
temp3 <<= 7
67
temp3 += object.ypos
68
69
DrawSpriteXY(1, temp2, temp3)
70
71
temp0++
72
temp1 += 16
73
loop
74
temp1 -= 8
75
76
Cos(temp2, 128)
77
temp2 *= temp1
78
temp2 <<= 7
79
temp2 += object.xpos
80
81
Sin(temp3, 128)
82
temp3 *= temp1
83
temp3 <<= 7
84
temp3 += object.ypos
85
86
// Draw the post
87
DrawSprite(0)
88
89
// Draw the platform itself
90
DrawSpriteXY(2, temp2, temp3)
91
end function
92
93
94
private function SwingPlatform_DebugSpawn
95
temp0 = debugMode[0].currentSelection
96
temp0 -= SwingPlatform_startDebugID
97
CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)
98
object[tempObjectPos].recoilDir = object.direction
99
end function
100
101
102
// ========================
103
// Events
104
// ========================
105
106
event ObjectUpdate
107
// Backup the object's position
108
temp2 = object.xpos
109
temp3 = object.ypos
110
111
// Oscillate in accordance with the rest of the stage's objects (namely other swinging platforms)
112
GetTableValue(object.angle, 12, StageSetup_oscillationTable)
113
object.angle >>= 8
114
115
if object.recoilDir == SWINGPLAT_RECOILDIR_LEFT // As in, is the object is going to bounce back to the left?
116
if object.angle <= 0x40
117
object.angle = 0x40
118
if object.collided == false
119
object.collided = true
120
PlaySfx(SfxName[Plat Collide], false)
121
end if
122
else
123
object.collided = false
124
end if
125
else
126
if object.angle >= 0x40
127
object.angle = 0x40
128
if object.collided == false
129
object.collided = true
130
PlaySfx(SfxName[Plat Collide], false)
131
end if
132
else
133
object.collided = false
134
end if
135
end if
136
137
if object.direction == FLIP_X
138
object.angle ^= 0xFF
139
object.angle += 0x81
140
end if
141
142
object.angle <<= 1
143
144
temp1 = object.length
145
temp1++
146
temp1 <<= 4
147
temp1 -= 8
148
149
object.xpos = object.drawPos.x
150
object.ypos = object.drawPos.y
151
152
Cos(object.collisionOffset.x, object.angle)
153
object.collisionOffset.x *= temp1
154
object.collisionOffset.x <<= 7
155
object.collisionOffset.x += temp2
156
object.collisionOffset.x &= 0xFFFF0000
157
object.drawPos.x = object.collisionOffset.x
158
object.collisionOffset.x -= object.xpos
159
160
Sin(object.collisionOffset.y, object.angle)
161
object.collisionOffset.y *= temp1
162
object.collisionOffset.y <<= 7
163
object.collisionOffset.y += temp3
164
object.collisionOffset.y &= 0xFFFF0000
165
object.drawPos.y = object.collisionOffset.y
166
object.collisionOffset.y -= object.ypos
167
168
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
169
BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
170
if checkResult == true
171
player[currentPlayer].xpos += object.collisionOffset.x
172
player[currentPlayer].ypos += object.collisionOffset.y
173
end if
174
next
175
176
// Restore object position
177
object.xpos = temp2
178
object.ypos = temp3
179
end event
180
181
182
event ObjectDraw
183
// First draw the chains...
184
temp0 = 0
185
temp1 = 16
186
while temp0 < object.length
187
Cos(temp2, object.angle)
188
temp2 *= temp1
189
temp2 <<= 7
190
temp2 += object.xpos
191
192
Sin(temp3, object.angle)
193
temp3 *= temp1
194
temp3 <<= 7
195
temp3 += object.ypos
196
197
DrawSpriteXY(1, temp2, temp3)
198
199
temp0++
200
temp1 += 16
201
loop
202
temp1 -= 8
203
204
// Then calculate platform position...
205
Cos(object.drawPos.x, object.angle)
206
object.drawPos.x *= temp1
207
object.drawPos.x <<= 7
208
object.drawPos.x += object.xpos
209
object.drawPos.x &= 0xFFFF0000
210
211
Sin(object.drawPos.y, object.angle)
212
object.drawPos.y *= temp1
213
object.drawPos.y <<= 7
214
object.drawPos.y += object.ypos
215
object.drawPos.y &= 0xFFFF0000
216
217
// Then draw the base rock anchor...
218
DrawSprite(0)
219
220
// And finally draw the platform
221
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
222
end event
223
224
225
event ObjectStartup
226
LoadSpriteSheet("MCZ/Objects.gif")
227
SpriteFrame(-12, -12, 23, 33, 152, 131) // 0 - Anchor frame
228
SpriteFrame( -8, -8, 16, 16, 135, 148) // 1 - Link frame
229
SpriteFrame(-24, -8, 48, 16, 141, 165) // 2 - Platform frame
230
231
foreach (TypeName[Swing Platform], arrayPos0, ALL_ENTITIES)
232
if object[arrayPos0].length > 0
233
object[arrayPos0].length--
234
end if
235
236
object[arrayPos0].collided = true
237
238
// Get the fourth bit of the property/length value
239
object[arrayPos0].recoilDir = object[arrayPos0].length
240
object[arrayPos0].recoilDir >>= 3
241
object[arrayPos0].recoilDir &= 1
242
243
// Limit max chain length to 7
244
object[arrayPos0].length &= 7
245
object[arrayPos0].length++
246
next
247
248
// Add this object to the debug mode object list a few times for the different chain lengths
249
temp0 = 0
250
SwingPlatform_startDebugID = DebugMode_ObjCount
251
SwingPlatform_startDebugID--
252
while temp0 < 8
253
SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)
254
SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
255
SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
256
DebugMode_ObjCount++
257
temp0++
258
loop
259
end event
260
261
262
// ========================
263
// Editor Events
264
// ========================
265
266
event RSDKEdit
267
if editor.returnVariable == true
268
switch editor.variableID
269
case EDIT_VAR_PROPVAL // property value
270
checkResult = object.propertyValue
271
break
272
273
case 0 // length
274
checkResult = object.propertyValue
275
checkResult &= 7
276
break
277
278
case 1 // swingDir
279
GetBit(checkResult, object.propertyValue, 4)
280
break
281
282
end switch
283
else
284
switch editor.variableID
285
case EDIT_VAR_PROPVAL // property value
286
object.propertyValue = editor.variableValue
287
break
288
289
case 0 // length
290
temp0 = 7
291
Not(temp0)
292
object.propertyValue &= temp0
293
editor.variableValue &= 7
294
295
object.propertyValue |= editor.variableValue
296
break
297
298
case 1 // swingDir
299
CheckNotEqual(editor.variableValue, 0)
300
SetBit(object.propertyValue, 4, checkResult)
301
break
302
303
end switch
304
end if
305
end event
306
307
308
event RSDKDraw
309
temp7 = object.propertyValue
310
if temp7 > 0
311
temp7--
312
end if
313
temp7 &= 7
314
temp7++
315
316
// Draw the chains
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
332
temp0++
333
temp1 += 16
334
loop
335
temp1 -= 8
336
337
Cos(temp2, 128)
338
temp2 *= temp1
339
temp2 <<= 7
340
temp2 += object.xpos
341
342
Sin(temp3, 128)
343
temp3 *= temp1
344
temp3 <<= 7
345
temp3 += object.ypos
346
347
// Draw the post
348
DrawSprite(0)
349
350
// Draw the platform itself
351
DrawSpriteXY(2, temp2, temp3)
352
end event
353
354
355
event RSDKLoad
356
LoadSpriteSheet("MCZ/Objects.gif")
357
SpriteFrame(-12, -12, 23, 33, 152, 131) // 0 - Anchor frame
358
SpriteFrame( -8, -8, 16, 16, 135, 148) // 1 - Link frame
359
SpriteFrame(-24, -8, 48, 16, 141, 165) // 2 - Platform frame
360
361
AddEditorVariable("length")
362
SetActiveVariable("length")
363
364
AddEditorVariable("swingDir")
365
SetActiveVariable("swingDir")
366
AddEnumVariable("Left", SWINGPLAT_RECOILDIR_LEFT)
367
AddEnumVariable("Right", SWINGPLAT_RECOILDIR_RIGHT)
368
end event
369
370