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/SBZ/BeltPlatform.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
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.movePos.x
13
private alias object.value1 : object.movePos.y
14
private alias object.value2 : object.collisionOffset.x
15
private alias object.value3 : object.collisionOffset.y
16
private alias object.value4 : object.tablePtr
17
private alias object.value5 : object.tablePos
18
private alias object.value6 : object.tableSize
19
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
private alias object.ypos : player.ypos
23
24
25
// ========================
26
// Function Declarations
27
// ========================
28
29
reserve function BeltPlatform_UpdateMovement
30
31
32
// ========================
33
// Tables
34
// ========================
35
36
private table BeltPlatform_frameTable
37
0, 1, 2, 3, 4, 3, 2, 1
38
end table
39
40
private table BeltPlatform_directionTable
41
0, 0, 0, 0
42
0, 2, 2, 2
43
2, 3, 3, 3
44
3, 1, 1, 1
45
end table
46
47
private table BeltPlatform_tableSizes
48
6, 6, 6, 6, 6, 6
49
end table
50
51
private table BeltPlatform_tablePtrs[6]
52
53
// format of these tables:
54
// x, y (total world-space positions, not relative to anything)
55
private table BeltPlatform_movementTable0
56
3604, 880
57
3824, 770
58
3824, 832
59
3604, 942
60
end table
61
62
private table BeltPlatform_movementTable1
63
3860, 736
64
4080, 626
65
4080, 688
66
3860, 798
67
end table
68
69
private table BeltPlatform_movementTable2
70
4116, 624
71
4336, 514
72
4336, 576
73
4116, 686
74
end table
75
76
private table BeltPlatform_movementTable3
77
3860, 1392
78
4080, 1282
79
4080, 1344
80
3860, 1454
81
end table
82
83
private table BeltPlatform_movementTable4
84
6932, 1648
85
7152, 1538
86
7152, 1600
87
6932, 1710
88
end table
89
90
private table BeltPlatform_movementTable5
91
7188, 1504
92
7408, 1394
93
7408, 1456
94
7188, 1566
95
end table
96
97
98
// ========================
99
// Function Definitions
100
// ========================
101
102
private function BeltPlatform_UpdateMovement
103
temp0 = object[arrayPos0].tablePos
104
GetTableValue(object[arrayPos0].movePos.x, temp0, object[arrayPos0].tablePtr)
105
temp0++
106
GetTableValue(object[arrayPos0].movePos.y, temp0, object[arrayPos0].tablePtr)
107
108
temp0 = object[arrayPos0].ixpos
109
temp0 -= object[arrayPos0].movePos.x
110
Abs(temp0)
111
temp1 = object[arrayPos0].iypos
112
temp1 -= object[arrayPos0].movePos.y
113
Abs(temp1)
114
115
if temp1 < temp0
116
object[arrayPos0].xvel = 0x10000
117
temp1 <<= 16
118
object[arrayPos0].yvel = temp1
119
object[arrayPos0].yvel /= temp0
120
else
121
if temp1 != 0
122
temp0 <<= 16
123
object[arrayPos0].xvel = temp0
124
object[arrayPos0].xvel /= temp1
125
else
126
object[arrayPos0].xvel = 0
127
end if
128
129
object[arrayPos0].yvel = 0x10000
130
end if
131
132
if object[arrayPos0].movePos.x < object[arrayPos0].ixpos
133
FlipSign(object[arrayPos0].xvel)
134
end if
135
136
if object[arrayPos0].movePos.y < object[arrayPos0].iypos
137
FlipSign(object[arrayPos0].yvel)
138
end if
139
end function
140
141
142
// ========================
143
// Events
144
// ========================
145
146
event ObjectUpdate
147
temp0 = object.xpos
148
temp1 = object.ypos
149
temp0 >>= 16
150
temp1 >>= 16
151
152
if temp0 == object.movePos.x
153
if temp1 == object.movePos.y
154
object.tablePos += 2
155
if object.tablePos > object.tableSize
156
object.tablePos = 0
157
end if
158
arrayPos0 = object.entityPos
159
CallFunction(BeltPlatform_UpdateMovement)
160
end if
161
end if
162
163
if object.rotation != 0
164
object.rotation++
165
object.rotation &= 15
166
else
167
if object.tablePos > 2
168
object.rotation++
169
end if
170
end if
171
172
temp0 = object.rotation
173
GetTableValue(object.direction, temp0, BeltPlatform_directionTable)
174
temp0 &= 7
175
GetTableValue(object.frame, temp0, BeltPlatform_frameTable)
176
temp0 = object.xpos
177
temp0 &= 0xFFFF0000
178
temp1 = object.ypos
179
temp1 &= 0xFFFF0000
180
temp2 = object.xpos
181
temp2 += object.xvel
182
temp3 = object.ypos
183
temp3 += object.yvel
184
185
object.collisionOffset.x = temp2
186
object.collisionOffset.x &= 0xFFFF0000
187
object.collisionOffset.x -= temp0
188
object.collisionOffset.y = temp3
189
object.collisionOffset.y &= 0xFFFF0000
190
object.collisionOffset.y -= temp1
191
192
if object.rotation == 0
193
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
194
BoxCollisionTest(C_SOLID, object.entityPos, -16, -7, 16, 7, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
195
if checkResult == COL_TOP
196
player[currentPlayer].xpos += object.collisionOffset.x
197
player[currentPlayer].ypos += object.collisionOffset.y
198
end if
199
next
200
end if
201
202
object.xpos = temp2
203
object.ypos = temp3
204
end event
205
206
207
event ObjectDraw
208
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
209
end event
210
211
212
event ObjectStartup
213
LoadSpriteSheet("SBZ/Objects.gif")
214
SpriteFrame(-16, -7, 32, 14, 413, 166)
215
SpriteFrame(-16, -12, 32, 25, 446, 169)
216
SpriteFrame(-15, -15, 30, 30, 480, 166)
217
SpriteFrame(-13, -16, 25, 32, 449, 198)
218
SpriteFrame(-7, -16, 14, 32, 480, 198)
219
220
SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)
221
SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)
222
SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)
223
SetTableValue(BeltPlatform_movementTable3, 3, BeltPlatform_tablePtrs)
224
SetTableValue(BeltPlatform_movementTable4, 4, BeltPlatform_tablePtrs)
225
SetTableValue(BeltPlatform_movementTable5, 5, BeltPlatform_tablePtrs)
226
227
foreach (TypeName[Belt Platform], arrayPos0, ALL_ENTITIES)
228
object[arrayPos0].priority = PRIORITY_INACTIVE
229
230
temp0 = object[arrayPos0].propertyValue
231
temp0 >>= 4
232
GetTableValue(object[arrayPos0].tablePtr, temp0, BeltPlatform_tablePtrs)
233
GetTableValue(object[arrayPos0].tableSize, temp0, BeltPlatform_tableSizes)
234
235
object[arrayPos0].tablePos = object[arrayPos0].propertyValue
236
object[arrayPos0].tablePos &= 15
237
object[arrayPos0].tablePos <<= 1
238
CallFunction(BeltPlatform_UpdateMovement)
239
next
240
end event
241
242
243
// ========================
244
// Editor Events
245
// ========================
246
247
event RSDKEdit
248
if editor.returnVariable == true
249
switch editor.variableID
250
case EDIT_VAR_PROPVAL // property value
251
checkResult = object.propertyValue
252
break
253
254
case 0 // type
255
checkResult = object.propertyValue
256
checkResult >>= 4
257
checkResult %= 6
258
break
259
260
case 1 // startOffset
261
checkResult = object.propertyValue
262
checkResult &= 0x0F
263
break
264
265
end switch
266
else
267
switch editor.variableID
268
case EDIT_VAR_PROPVAL // property value
269
object.propertyValue = editor.variableValue
270
break
271
272
case 0 // type
273
editor.variableValue %= 6
274
editor.variableValue <<= 4
275
276
object.propertyValue &= 0x0F
277
object.propertyValue |= editor.variableValue
278
break
279
280
case 1 // startOffset
281
editor.variableValue &= 0x0F
282
283
object.propertyValue &= 0xF0
284
object.propertyValue |= editor.variableValue
285
break
286
287
end switch
288
end if
289
end event
290
291
292
event RSDKDraw
293
DrawSprite(0)
294
295
if editor.showGizmos == true
296
editor.drawingOverlay = true
297
298
temp0 = object.propertyValue
299
temp0 >>= 4
300
GetTableValue(object.tablePtr, temp0, BeltPlatform_tablePtrs)
301
GetTableValue(object.tableSize, temp0, BeltPlatform_tableSizes)
302
303
object.tablePos = object.propertyValue
304
object.tablePos &= 15
305
object.tablePos <<= 1
306
arrayPos0 = object.entityPos
307
CallFunction(BeltPlatform_UpdateMovement)
308
309
temp0 = object.xvel
310
temp0 <<= 5
311
temp0 += object.xpos
312
313
temp1 = object.yvel
314
temp1 <<= 5
315
temp1 += object.ypos
316
317
DrawArrow(object.xpos, object.ypos, temp0, temp1, 0x00, 0xFF, 0x00)
318
319
editor.drawingOverlay = false
320
end if
321
end event
322
323
324
event RSDKLoad
325
LoadSpriteSheet("SBZ/Objects.gif")
326
SpriteFrame(-16, -7, 32, 14, 413, 166)
327
328
SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)
329
SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)
330
SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)
331
SetTableValue(BeltPlatform_movementTable3, 3, BeltPlatform_tablePtrs)
332
SetTableValue(BeltPlatform_movementTable4, 4, BeltPlatform_tablePtrs)
333
SetTableValue(BeltPlatform_movementTable5, 5, BeltPlatform_tablePtrs)
334
335
AddEditorVariable("type")
336
SetActiveVariable("type")
337
338
AddEditorVariable("startOffset")
339
SetActiveVariable("startOffset")
340
end event
341
342