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/LZ/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
private alias object.value7 : object.beltDir
20
21
// Player Aliases
22
private alias object.xpos : player.xpos
23
private alias object.ypos : player.ypos
24
25
26
// ========================
27
// Function Declarations
28
// ========================
29
30
reserve function BeltPlatform_UpdateMovement
31
32
33
// ========================
34
// Tables
35
// ========================
36
37
private table BeltPlatform_tableSizes
38
10, 8, 6, 6, 8, 6
39
end table
40
41
private table BeltPlatform_tablePtrs[6]
42
43
// format of these tables:
44
// x, y (total world-space positions, not relative to anything)
45
private table BeltPlatform_movementTable0
46
4216, 538
47
4286, 608
48
4286, 915
49
4236, 965
50
4130, 912
51
4130, 580
52
end table
53
54
private table BeltPlatform_movementTable1
55
4734, 640
56
4814, 720
57
4814, 1134
58
4658, 1056
59
4658, 716
60
end table
61
62
private table BeltPlatform_movementTable2
63
3362, 1154
64
3362, 1502
65
3502, 1502
66
3502, 1154
67
end table
68
69
private table BeltPlatform_movementTable3
70
3426, 930
71
3566, 930
72
3566, 1246
73
3426, 1246
74
end table
75
76
private table BeltPlatform_movementTable4
77
3244, 578
78
3550, 578
79
3550, 990
80
3154, 990
81
3154, 668
82
end table
83
84
private table BeltPlatform_movementTable5
85
4690, 522
86
5086, 522
87
5086, 702
88
4690, 702
89
end table
90
91
92
// ========================
93
// Function Definitions
94
// ========================
95
96
private function BeltPlatform_UpdateMovement
97
temp0 = object[arrayPos0].tablePos
98
GetTableValue(object[arrayPos0].movePos.x, temp0, object[arrayPos0].tablePtr)
99
temp0++
100
GetTableValue(object[arrayPos0].movePos.y, temp0, object[arrayPos0].tablePtr)
101
102
temp0 = object[arrayPos0].ixpos
103
temp0 -= object[arrayPos0].movePos.x
104
Abs(temp0)
105
temp1 = object[arrayPos0].iypos
106
temp1 -= object[arrayPos0].movePos.y
107
Abs(temp1)
108
109
if temp1 < temp0
110
object[arrayPos0].xvel = 0x10000
111
temp1 <<= 16
112
object[arrayPos0].yvel = temp1
113
object[arrayPos0].yvel /= temp0
114
else
115
if temp1 != 0
116
temp0 <<= 16
117
object[arrayPos0].xvel = temp0
118
object[arrayPos0].xvel /= temp1
119
else
120
object[arrayPos0].xvel = 0
121
end if
122
123
object[arrayPos0].yvel = 0x10000
124
end if
125
126
if object[arrayPos0].movePos.x < object[arrayPos0].ixpos
127
FlipSign(object[arrayPos0].xvel)
128
end if
129
130
if object[arrayPos0].movePos.y < object[arrayPos0].iypos
131
FlipSign(object[arrayPos0].yvel)
132
end if
133
end function
134
135
136
// ========================
137
// Events
138
// ========================
139
140
event ObjectUpdate
141
temp2 = false
142
143
if object.beltDir != LZSetup_beltDirection
144
object.direction ^= FLIP_X
145
object.beltDir = LZSetup_beltDirection
146
temp2 = true
147
else
148
temp0 = object.xpos
149
temp1 = object.ypos
150
temp0 >>= 16
151
temp1 >>= 16
152
if temp0 == object.movePos.x
153
if temp1 == object.movePos.y
154
temp2 = true
155
end if
156
end if
157
end if
158
159
if temp2 == true
160
if object.direction == FLIP_NONE
161
object.tablePos += 2
162
if object.tablePos > object.tableSize
163
object.tablePos = 0
164
end if
165
else
166
object.tablePos -= 2
167
if object.tablePos < 0
168
object.tablePos = object.tableSize
169
end if
170
end if
171
arrayPos0 = object.entityPos
172
CallFunction(BeltPlatform_UpdateMovement)
173
end if
174
175
temp0 = object.xpos
176
temp0 &= 0xFFFF0000
177
temp1 = object.ypos
178
temp1 &= 0xFFFF0000
179
temp2 = object.xpos
180
temp2 += object.xvel
181
temp3 = object.ypos
182
temp3 += object.yvel
183
184
object.collisionOffset.x = temp2
185
object.collisionOffset.x &= 0xFFFF0000
186
object.collisionOffset.x -= temp0
187
object.collisionOffset.y = temp3
188
object.collisionOffset.y &= 0xFFFF0000
189
object.collisionOffset.y -= temp1
190
191
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
192
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -8, 16, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
193
if checkResult == true
194
player[currentPlayer].xpos += object.collisionOffset.x
195
player[currentPlayer].ypos += object.collisionOffset.y
196
end if
197
next
198
199
object.xpos = temp2
200
object.ypos = temp3
201
end event
202
203
204
event ObjectDraw
205
DrawSprite(0)
206
end event
207
208
209
event ObjectStartup
210
LoadSpriteSheet("LZ/Objects.gif")
211
SpriteFrame(-16, -8, 32, 16, 223, 154)
212
213
SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)
214
SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)
215
SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)
216
SetTableValue(BeltPlatform_movementTable3, 3, BeltPlatform_tablePtrs)
217
SetTableValue(BeltPlatform_movementTable4, 4, BeltPlatform_tablePtrs)
218
SetTableValue(BeltPlatform_movementTable5, 5, BeltPlatform_tablePtrs)
219
220
foreach (TypeName[Belt Platform], arrayPos0, ALL_ENTITIES)
221
object[arrayPos0].priority = PRIORITY_INACTIVE
222
223
temp0 = object[arrayPos0].propertyValue
224
temp0 >>= 4
225
GetTableValue(object[arrayPos0].tablePtr, temp0, BeltPlatform_tablePtrs)
226
GetTableValue(object[arrayPos0].tableSize, temp0, BeltPlatform_tableSizes)
227
228
object[arrayPos0].tablePos = object[arrayPos0].propertyValue
229
object[arrayPos0].tablePos &= 15
230
object[arrayPos0].tablePos <<= 1
231
CallFunction(BeltPlatform_UpdateMovement)
232
next
233
end event
234
235
236
// ========================
237
// Editor Events
238
// ========================
239
240
event RSDKEdit
241
if editor.returnVariable == true
242
switch editor.variableID
243
case EDIT_VAR_PROPVAL // property value
244
checkResult = object.propertyValue
245
break
246
247
case 0 // type
248
checkResult = object.propertyValue
249
checkResult >>= 4
250
checkResult %= 6
251
break
252
253
case 1 // startOffset
254
checkResult = object.propertyValue
255
checkResult &= 0x0F
256
break
257
258
end switch
259
else
260
switch editor.variableID
261
case EDIT_VAR_PROPVAL // property value
262
object.propertyValue = editor.variableValue
263
break
264
265
case 0 // type
266
editor.variableValue %= 6
267
editor.variableValue <<= 4
268
269
object.propertyValue &= 0x0F
270
object.propertyValue |= editor.variableValue
271
break
272
273
case 1 // startOffset
274
editor.variableValue &= 0x0F
275
276
object.propertyValue &= 0xF0
277
object.propertyValue |= editor.variableValue
278
break
279
280
end switch
281
end if
282
end event
283
284
285
event RSDKDraw
286
DrawSprite(0)
287
288
if editor.showGizmos == true
289
editor.drawingOverlay = true
290
291
temp0 = object.propertyValue
292
temp0 >>= 4
293
GetTableValue(object.tablePtr, temp0, BeltPlatform_tablePtrs)
294
GetTableValue(object.tableSize, temp0, BeltPlatform_tableSizes)
295
296
object.tablePos = object.propertyValue
297
object.tablePos &= 15
298
object.tablePos <<= 1
299
arrayPos0 = object.entityPos
300
CallFunction(BeltPlatform_UpdateMovement)
301
302
temp0 = object.xvel
303
temp0 <<= 5
304
temp0 += object.xpos
305
306
temp1 = object.yvel
307
temp1 <<= 5
308
temp1 += object.ypos
309
310
DrawArrow(object.xpos, object.ypos, temp0, temp1, 0x00, 0xFF, 0x00)
311
312
editor.drawingOverlay = false
313
end if
314
end event
315
316
317
event RSDKLoad
318
LoadSpriteSheet("LZ/Objects.gif")
319
SpriteFrame(-16, -8, 32, 16, 223, 154)
320
321
SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)
322
SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)
323
SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)
324
SetTableValue(BeltPlatform_movementTable3, 3, BeltPlatform_tablePtrs)
325
SetTableValue(BeltPlatform_movementTable4, 4, BeltPlatform_tablePtrs)
326
SetTableValue(BeltPlatform_movementTable5, 5, BeltPlatform_tablePtrs)
327
328
AddEditorVariable("type")
329
SetActiveVariable("type")
330
331
AddEditorVariable("startOffset")
332
SetActiveVariable("startOffset")
333
end event
334
335