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/ARZ/SwingPlat.txt
1482 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
// Path ID Aliases
33
private alias 0 : PATH_A
34
35
36
// ========================
37
// Function Declarations
38
// ========================
39
40
reserve function SwingPlatform_DebugDraw
41
reserve function SwingPlatform_DebugSpawn
42
43
44
// ========================
45
// Static Values
46
// ========================
47
48
private value SwingPlatform_startDebugID = 0
49
50
51
// ========================
52
// Function Definitions
53
// ========================
54
55
private function SwingPlatform_DebugDraw
56
temp7 = debugMode[0].currentSelection
57
temp7 -= SwingPlatform_startDebugID
58
DrawSprite(0)
59
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
temp3 *= temp1
69
temp3 <<= 7
70
temp3 += object.ypos
71
DrawSpriteXY(1, temp2, temp3)
72
temp0++
73
temp1 += 16
74
loop
75
temp1 -= 8
76
77
Cos(temp2, 128)
78
temp2 *= temp1
79
temp2 <<= 7
80
temp2 += object.xpos
81
82
Sin(temp3, 128)
83
temp3 *= temp1
84
temp3 <<= 7
85
temp3 += object.ypos
86
87
DrawSpriteXY(2, temp2, temp3)
88
end function
89
90
91
private function SwingPlatform_DebugSpawn
92
temp0 = debugMode[0].currentSelection
93
temp0 -= SwingPlatform_startDebugID
94
CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)
95
object[tempObjectPos].direction = object.direction
96
end function
97
98
99
// ========================
100
// Events
101
// ========================
102
103
event ObjectUpdate
104
temp2 = object.xpos
105
temp3 = object.ypos
106
GetTableValue(object.swingAngle, 12, StageSetup_oscillationTable)
107
object.swingAngle >>= 8
108
if object.direction == FLIP_X
109
object.swingAngle ^= 255
110
object.swingAngle += 129
111
end if
112
object.swingAngle <<= 1
113
114
temp1 = object.length
115
temp1++
116
temp1 <<= 4
117
temp1 -= 8
118
object.xpos = object.drawPos.x
119
object.ypos = object.drawPos.y
120
121
switch object.state
122
case SWINGPLAT_SWING
123
Cos(object.xpos, object.swingAngle)
124
object.xpos *= temp1
125
object.xpos <<= 7
126
object.xpos += temp2
127
128
Sin(object.ypos, object.swingAngle)
129
object.ypos *= temp1
130
object.ypos <<= 7
131
object.ypos += temp3
132
break
133
134
case SWINGPLAT_SNAPPED
135
object.ypos += object.yvel
136
object.yvel += 0x1800
137
temp7 = stage.waterLevel
138
temp7 <<= 16
139
if object.ypos >= temp7
140
object.xvel = 0x10000
141
object.state++
142
end if
143
object.xpos += object.xvel
144
break
145
146
case SWINGPLAT_FLOATING
147
object.ypos = stage.waterLevel
148
object.ypos <<= 16
149
object.xpos += object.xvel
150
if object.direction == FLIP_NONE
151
ObjectTileCollision(CSIDE_LWALL, 32, 12, PATH_A)
152
else
153
ObjectTileCollision(CSIDE_RWALL, -32, 12, PATH_A)
154
end if
155
break
156
157
end switch
158
159
object.collisionOffset.x = object.xpos
160
object.collisionOffset.x &= 0xFFFF0000
161
temp4 = object.drawPos.x
162
temp4 &= 0xFFFF0000
163
object.collisionOffset.x -= temp4
164
165
object.collisionOffset.y = object.ypos
166
object.collisionOffset.y &= 0xFFFF0000
167
temp5 = object.drawPos.y
168
temp5 &= 0xFFFF0000
169
object.collisionOffset.y -= temp5
170
171
object.drawPos.x = object.xpos
172
object.drawPos.y = object.ypos
173
174
object.xpos = temp4
175
object.ypos = temp5
176
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
177
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
178
if checkResult == true
179
if object.state == SWINGPLAT_SWING
180
if object.canSnap == true
181
if object.direction == FLIP_NONE
182
if object.swingAngle == 0x00
183
object.xvel = 0x20000
184
object.priority = PRIORITY_ACTIVE
185
object.state = SWINGPLAT_SNAPPED
186
end if
187
else
188
// Bug Details:
189
// -> An inverted platform's range is 0x200 to 0x300, so this never hits..
190
// -> If the goal was to make it snap when it's on the left, then you'd want to use a 0x300 here
191
if object.swingAngle == 0x100
192
object.xvel = -0x20000
193
object.priority = PRIORITY_ACTIVE
194
object.state = SWINGPLAT_SNAPPED
195
end if
196
end if
197
end if
198
end if
199
player[currentPlayer].xpos += object.collisionOffset.x
200
player[currentPlayer].ypos += object.collisionOffset.y
201
end if
202
next
203
204
if object.state > SWINGPLAT_SNAPPED
205
if object.outOfBounds == true
206
object.xpos = temp2
207
object.ypos = temp3
208
if object.outOfBounds == true
209
object.state = SWINGPLAT_SWING
210
object.priority = PRIORITY_BOUNDS
211
object.xvel = 0
212
object.yvel = 0
213
end if
214
end if
215
end if
216
object.xpos = temp2
217
object.ypos = temp3
218
end event
219
220
221
event ObjectDraw
222
temp0 = 0
223
temp1 = 16
224
while temp0 < object.length
225
Cos(temp2, object.swingAngle)
226
temp2 *= temp1
227
temp2 <<= 7
228
temp2 += object.xpos
229
230
Sin(temp3, object.swingAngle)
231
temp3 *= temp1
232
temp3 <<= 7
233
temp3 += object.ypos
234
235
DrawSpriteXY(1, temp2, temp3)
236
237
temp0++
238
temp1 += 16
239
loop
240
temp1 -= 8
241
242
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
243
DrawSprite(0)
244
end event
245
246
247
event ObjectStartup
248
LoadSpriteSheet("ARZ/Objects.gif")
249
SpriteFrame(-15, -12, 30, 20, 160, 235)
250
SpriteFrame(-8, -8, 16, 16, 174, 218)
251
SpriteFrame(-32, -8, 64, 16, 126, 191)
252
253
foreach (TypeName[Swing Platform], arrayPos0, ALL_ENTITIES)
254
GetBit(object[arrayPos0].canSnap, object[arrayPos0].length, 7)
255
object[arrayPos0].length &= 0x7F
256
next
257
258
temp0 = 0
259
SwingPlatform_startDebugID = DebugMode_ObjCount
260
SwingPlatform_startDebugID--
261
while temp0 < 8
262
SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)
263
SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
264
SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
265
DebugMode_ObjCount++
266
temp0++
267
loop
268
end event
269
270
271
// ========================
272
// Editor Events
273
// ========================
274
275
event RSDKEdit
276
if editor.returnVariable == true
277
switch editor.variableID
278
case EDIT_VAR_PROPVAL // property value
279
checkResult = object.propertyValue
280
break
281
282
case 0 // length
283
checkResult = object.propertyValue
284
checkResult &= 0x7F
285
break
286
287
case 1 // canSnap
288
GetBit(checkResult, object.propertyValue, 7)
289
break
290
end switch
291
else
292
switch editor.variableID
293
case EDIT_VAR_PROPVAL // property value
294
object.propertyValue = editor.variableValue
295
break
296
297
case 0 // length
298
editor.variableValue &= 0x7F
299
object.propertyValue &= 0x80
300
301
object.propertyValue |= editor.variableValue
302
break
303
304
case 1 // canSnap
305
CheckNotEqual(editor.variableValue, false)
306
SetBit(object.propertyValue, 7, checkResult)
307
break
308
end switch
309
end if
310
end event
311
312
313
event RSDKDraw
314
temp7 = object.propertyValue
315
temp7 &= 0x7F
316
317
DrawSprite(0)
318
319
temp0 = 0
320
temp1 = 16
321
while temp0 < temp7
322
Cos(temp2, 128)
323
temp2 *= temp1
324
temp2 <<= 7
325
temp2 += object.xpos
326
327
Sin(temp3, 128)
328
temp3 *= temp1
329
temp3 <<= 7
330
temp3 += object.ypos
331
332
DrawSpriteXY(1, temp2, temp3)
333
temp0++
334
temp1 += 16
335
loop
336
temp1 -= 8
337
338
Cos(temp2, 128)
339
temp2 *= temp1
340
temp2 <<= 7
341
temp2 += object.xpos
342
343
Sin(temp3, 128)
344
temp3 *= temp1
345
temp3 <<= 7
346
temp3 += object.ypos
347
348
DrawSpriteXY(2, temp2, temp3)
349
end event
350
351
352
event RSDKLoad
353
LoadSpriteSheet("ARZ/Objects.gif")
354
SpriteFrame(-15, -12, 30, 20, 160, 235)
355
SpriteFrame(-8, -8, 16, 16, 174, 218)
356
SpriteFrame(-32, -8, 64, 16, 126, 191)
357
358
AddEditorVariable("length")
359
SetActiveVariable("length")
360
361
AddEditorVariable("canSnap")
362
SetActiveVariable("canSnap")
363
AddEnumVariable("false", false)
364
AddEnumVariable("true", true)
365
end event
366
367