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/MPZ/BeltPlatform.txt
1479 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Belt 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.value0 : object.basePos.x
13
private alias object.value1 : object.basePos.y
14
private alias object.value2 : object.movePos.x
15
private alias object.value3 : object.movePos.y
16
private alias object.value4 : object.collisionOffset.x
17
private alias object.value5 : object.collisionOffset.y
18
private alias object.value6 : object.tablePtr
19
private alias object.value7 : object.tablePos
20
private alias object.value8 : object.tableSize
21
private alias object.value31 : object.wrapOffset.y
22
23
// Player Aliases
24
private alias object.xpos : player.xpos
25
private alias object.ypos : player.ypos
26
27
28
// ========================
29
// Function Declarations
30
// ========================
31
32
reserve function BeltPlatform_UpdateMovement
33
34
35
// ========================
36
// Tables
37
// ========================
38
39
private table BeltPlatform_flippedTablePos
40
5, 9, 3, 2, 6, 0, 4, 8, 7, 1
41
end table
42
43
private table BeltPlatform_tableSizes
44
18, 18, 18
45
end table
46
47
private table BeltPlatform_tablePtrs[3]
48
49
private table BeltPlatform_movementTable0
50
0, 0, -22, 10, -32, 32, -32, 224, -22, 246, 0, 256, 22, 246, 32, 224, 32, 32, 22, 10
51
end table
52
53
private table BeltPlatform_movementTable1
54
0, 0, -22, 10, -32, 32, -32, 352, -22, 374, 0, 384, 22, 374, 32, 352, 32, 32, 22, 10
55
end table
56
57
private table BeltPlatform_movementTable2
58
0, 0, -22, 10, -32, 32, -32, 480, -22, 502, 0, 512, 22, 502, 32, 480, 32, 32, 22, 10
59
end table
60
61
62
// ========================
63
// Funcion Definitions
64
// ========================
65
66
private function BeltPlatform_UpdateMovement
67
temp0 = object[arrayPos0].tablePos
68
GetTableValue(object[arrayPos0].movePos.x, temp0, object[arrayPos0].tablePtr)
69
object[arrayPos0].movePos.x += object[arrayPos0].basePos.x
70
71
temp0++
72
GetTableValue(object[arrayPos0].movePos.y, temp0, object[arrayPos0].tablePtr)
73
object[arrayPos0].movePos.y += object[arrayPos0].basePos.y
74
75
temp0 = object[arrayPos0].xpos
76
temp0 >>= 16
77
temp2 = temp0
78
temp0 -= object[arrayPos0].movePos.x
79
Abs(temp0)
80
81
temp1 = object[arrayPos0].ypos
82
temp1 -= object.wrapOffset.y
83
temp1 >>= 16
84
temp1 &= 0x7FF
85
temp3 = temp1
86
temp1 -= object[arrayPos0].movePos.y
87
Abs(temp1)
88
89
if temp1 < temp0
90
object[arrayPos0].xvel = 0x10000
91
temp1 <<= 16
92
object[arrayPos0].yvel = temp1
93
object[arrayPos0].yvel /= temp0
94
else
95
if temp1 != 0
96
temp0 <<= 16
97
object[arrayPos0].xvel = temp0
98
object[arrayPos0].xvel /= temp1
99
else
100
object[arrayPos0].xvel = 0
101
end if
102
object[arrayPos0].yvel = 0x10000
103
end if
104
105
if object[arrayPos0].movePos.x < temp2
106
FlipSign(object[arrayPos0].xvel)
107
end if
108
109
if object[arrayPos0].movePos.y < temp3
110
FlipSign(object[arrayPos0].yvel)
111
end if
112
end function
113
114
115
// ========================
116
// Events
117
// ========================
118
119
event ObjectUpdate
120
temp2 = 0
121
temp0 = object.xpos
122
temp1 = object.ypos
123
temp0 >>= 16
124
temp1 >>= 16
125
temp1 &= 0x7FF
126
127
if object.xvel < 0
128
if object.yvel < 0
129
if temp0 <= object.movePos.x
130
if temp1 <= object.movePos.y
131
temp2 = true
132
end if
133
end if
134
else
135
if temp0 <= object.movePos.x
136
if temp1 >= object.movePos.y
137
temp2 = true
138
end if
139
end if
140
end if
141
else
142
if object.yvel < 0
143
if temp0 >= object.movePos.x
144
if temp1 <= object.movePos.y
145
temp2 = true
146
end if
147
end if
148
else
149
if temp0 >= object.movePos.x
150
if temp1 >= object.movePos.y
151
temp2 = true
152
end if
153
end if
154
end if
155
end if
156
157
if temp2 == true
158
if object.direction == FLIP_NONE
159
object.tablePos += 2
160
if object.tablePos > object.tableSize
161
object.tablePos = 0
162
end if
163
else
164
object.tablePos -= 2
165
if object.tablePos < 0
166
object.tablePos = object.tableSize
167
end if
168
end if
169
170
arrayPos0 = object.entityPos
171
CallFunction(BeltPlatform_UpdateMovement)
172
end if
173
174
temp0 = object.xpos
175
temp0 &= 0xFFFF0000
176
temp1 = object.ypos
177
temp1 &= 0xFFFF0000
178
temp2 = object.xpos
179
temp2 += object.xvel
180
temp3 = object.ypos
181
temp3 += object.yvel
182
183
object.collisionOffset.x = temp2
184
object.collisionOffset.x &= 0xFFFF0000
185
object.collisionOffset.x -= temp0
186
object.collisionOffset.y = temp3
187
object.collisionOffset.y &= 0xFFFF0000
188
object.collisionOffset.y -= temp1
189
190
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
191
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -8, 16, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
192
if checkResult == true
193
player[currentPlayer].xpos += object.collisionOffset.x
194
player[currentPlayer].ypos += object.collisionOffset.y
195
end if
196
next
197
198
object.xpos = temp2
199
object.ypos = temp3
200
end event
201
202
203
event ObjectDraw
204
DrawSprite(0)
205
end event
206
207
208
event ObjectStartup
209
LoadSpriteSheet("MPZ/Objects.gif")
210
SpriteFrame(-16, -8, 32, 16, 34, 67)
211
212
SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)
213
SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)
214
SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)
215
216
foreach (TypeName[Belt Platform], arrayPos0, ALL_ENTITIES)
217
object[arrayPos0].priority = PRIORITY_INACTIVE
218
219
temp0 = object[arrayPos0].propertyValue
220
temp0 >>= 4
221
GetTableValue(object[arrayPos0].tablePtr, temp0, BeltPlatform_tablePtrs)
222
GetTableValue(object[arrayPos0].tableSize, temp0, BeltPlatform_tableSizes)
223
224
object[arrayPos0].tablePos = object[arrayPos0].propertyValue
225
object[arrayPos0].tablePos &= 0xF
226
if object[arrayPos0].direction == FLIP_X
227
GetTableValue(temp0, object[arrayPos0].tablePos, BeltPlatform_flippedTablePos)
228
object[arrayPos0].tablePos = temp0
229
end if
230
object[arrayPos0].tablePos <<= 1
231
232
CallFunction(BeltPlatform_UpdateMovement)
233
next
234
end event
235
236
237
// ========================
238
// Editor Events
239
// ========================
240
241
event RSDKEdit
242
if editor.returnVariable == true
243
switch editor.variableID
244
case EDIT_VAR_PROPVAL // property value
245
checkResult = object.propertyValue
246
break
247
248
case 0 // type
249
checkResult = object.propertyValue
250
checkResult >>= 4
251
checkResult %= 6
252
break
253
254
case 1 // startOffset
255
checkResult = object.propertyValue
256
checkResult &= 0x0F
257
break
258
259
case 2 // direction
260
checkResult = object.direction
261
checkResult &= 1
262
break
263
264
end switch
265
else
266
switch editor.variableID
267
case EDIT_VAR_PROPVAL // property value
268
object.propertyValue = editor.variableValue
269
break
270
271
case 0 // type
272
editor.variableValue %= 6
273
editor.variableValue <<= 4
274
275
object.propertyValue &= 0x0F
276
object.propertyValue |= editor.variableValue
277
break
278
279
case 1 // startOffset
280
editor.variableValue &= 0x0F
281
282
object.propertyValue &= 0xF0
283
object.propertyValue |= editor.variableValue
284
break
285
286
case 2 // direction
287
editor.variableValue &= 1
288
object.direction = editor.variableValue
289
break
290
291
end switch
292
end if
293
end event
294
295
296
event RSDKDraw
297
DrawSprite(0)
298
299
if editor.showGizmos == true
300
temp0 = object.propertyValue
301
temp0 >>= 4
302
GetTableValue(object.tablePtr, temp0, BeltPlatform_tablePtrs)
303
GetTableValue(object.tableSize, temp0, BeltPlatform_tableSizes)
304
305
object.tablePos = object.propertyValue
306
object.tablePos &= 15
307
if object.direction == FLIP_X
308
GetTableValue(temp0, object.tablePos, BeltPlatform_flippedTablePos)
309
object.tablePos = temp0
310
end if
311
object.tablePos <<= 1
312
arrayPos0 = object.entityPos
313
CallFunction(BeltPlatform_UpdateMovement)
314
315
temp0 = object.xvel
316
temp0 <<= 5
317
temp0 += object.xpos
318
319
temp1 = object.yvel
320
temp1 <<= 5
321
temp1 += object.ypos
322
323
DrawArrow(object.xpos, object.ypos, temp0, temp1, 0x00, 0xFF, 0x00)
324
end if
325
end event
326
327
328
event RSDKLoad
329
LoadSpriteSheet("MPZ/Objects.gif")
330
SpriteFrame(-16, -8, 32, 16, 34, 67)
331
332
SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)
333
SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)
334
SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)
335
336
AddEditorVariable("type")
337
SetActiveVariable("type")
338
339
AddEditorVariable("startOffset")
340
SetActiveVariable("startOffset")
341
342
AddEditorVariable("direction")
343
SetActiveVariable("direction")
344
AddEnumVariable("Clockwise", 0)
345
AddEnumVariable("Counter-clockwise", 1)
346
347
// represent positions in the scene
348
// should be aligned with top most platform in the chain
349
SetVariableAlias(ALIAS_VAR_VAL0, "basePos.x")
350
SetVariableAlias(ALIAS_VAR_VAL1, "basePos.y")
351
end event
352
353