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/RotatePlatform.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Rotate 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.rotateAngle
13
private alias object.value1 : object.drawPos.x
14
private alias object.value2 : object.drawPos.y
15
private alias object.value3 : object.collisionOffset.x
16
private alias object.value4 : object.collisionOffset.y
17
private alias object.value5 : object.length // Always 3
18
private alias object.value6 : object.rotateSpeed
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 RotatePlatform_DebugDraw
30
reserve function RotatePlatform_DebugSpawn
31
32
33
// ========================
34
// Function Definitions
35
// ========================
36
37
private function RotatePlatform_DebugDraw
38
temp7 = 3
39
DrawSprite(0)
40
41
temp0 = 0
42
temp1 = 16
43
while temp0 < temp7
44
Cos(temp2, 128)
45
temp2 *= temp1
46
temp2 <<= 7
47
temp2 += object.xpos
48
49
Sin(temp3, 128)
50
temp3 *= temp1
51
temp3 <<= 7
52
temp3 += object.ypos
53
54
DrawSpriteXY(1, temp2, temp3)
55
56
temp0++
57
temp1 += 16
58
loop
59
temp1 -= 8
60
61
Cos(temp2, 128)
62
temp2 *= temp1
63
temp2 <<= 7
64
temp2 += object.xpos
65
66
Sin(temp3, 128)
67
temp3 *= temp1
68
temp3 <<= 7
69
temp3 += object.ypos
70
71
DrawSpriteXY(2, temp2, temp3)
72
end function
73
74
75
private function RotatePlatform_DebugSpawn
76
// Bug Details:
77
// -> Only the last Rotate Platform spawned here is given the PRIORITY_XBOUNDS_DESTROY priority, while the first two aren't
78
// -> Because of this, if you go make these go off screen and then return to them later,
79
// it'll only be a set of 2 platforms rather than the usual 3
80
// (yeah this really isn't too big of a bug but hey, it's worth noting anyway)
81
82
CreateTempObject(TypeName[Rotate Platform], 0, object.xpos, object.ypos)
83
object[tempObjectPos].length = 3
84
object[tempObjectPos].rotateSpeed = 128
85
object[tempObjectPos].rotateAngle = 0x0000
86
87
CreateTempObject(TypeName[Rotate Platform], 0, object.xpos, object.ypos)
88
object[tempObjectPos].length = 3
89
object[tempObjectPos].rotateSpeed = 128
90
object[tempObjectPos].rotateAngle = 0x5500
91
92
CreateTempObject(TypeName[Rotate Platform], 0, object.xpos, object.ypos)
93
object[tempObjectPos].length = 3
94
object[tempObjectPos].rotateSpeed = 128
95
object[tempObjectPos].rotateAngle = 0xAB00
96
end function
97
98
99
// ========================
100
// Events
101
// ========================
102
103
event ObjectUpdate
104
temp2 = object.xpos
105
temp3 = object.ypos
106
object.rotateAngle += object.rotateSpeed
107
object.rotateAngle &= 0x1FFFF
108
109
temp0 = object.rotateAngle
110
temp0 >>= 8
111
temp1 = object.length
112
temp1++
113
temp1 <<= 4
114
object.xpos = object.drawPos.x
115
object.ypos = object.drawPos.y
116
117
Cos256(object.collisionOffset.x, temp0)
118
object.collisionOffset.x *= temp1
119
object.collisionOffset.x <<= 8
120
object.collisionOffset.x += temp2
121
object.collisionOffset.x &= 0xFFFF0000
122
object.drawPos.x = object.collisionOffset.x
123
object.collisionOffset.x -= object.xpos
124
125
Sin256(object.collisionOffset.y, temp0)
126
object.collisionOffset.y *= temp1
127
object.collisionOffset.y <<= 8
128
object.collisionOffset.y += temp3
129
object.collisionOffset.y &= 0xFFFF0000
130
object.drawPos.y = object.collisionOffset.y
131
object.collisionOffset.y -= object.ypos
132
133
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
134
BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX) // 24 length on both sides? The sprite's width is 64, and other scripts' uses of this platform sprite use -32,32 hitboxes too...
135
if checkResult == true
136
player[currentPlayer].xpos += object.collisionOffset.x
137
player[currentPlayer].ypos += object.collisionOffset.y
138
end if
139
next
140
object.xpos = temp2
141
object.ypos = temp3
142
end event
143
144
145
event ObjectDraw
146
temp0 = 0
147
temp1 = 16
148
149
temp4 = object.rotateAngle
150
temp4 >>= 8
151
while temp0 < object.length
152
Cos256(temp2, temp4)
153
temp2 *= temp1
154
temp2 <<= 8
155
temp2 += object.xpos
156
157
Sin256(temp3, temp4)
158
temp3 *= temp1
159
temp3 <<= 8
160
temp3 += object.ypos
161
162
DrawSpriteXY(1, temp2, temp3)
163
164
temp0++
165
temp1 += 16
166
loop
167
Cos256(object.drawPos.x, temp4)
168
object.drawPos.x *= temp1
169
object.drawPos.x <<= 8
170
object.drawPos.x += object.xpos
171
object.drawPos.x &= 0xFFFF0000
172
173
Sin256(object.drawPos.y, temp4)
174
object.drawPos.y *= temp1
175
object.drawPos.y <<= 8
176
object.drawPos.y += object.ypos
177
object.drawPos.y &= 0xFFFF0000
178
179
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
180
181
DrawSprite(0)
182
end event
183
184
185
event ObjectStartup
186
LoadSpriteSheet("ARZ/Objects.gif")
187
SpriteFrame(-15, -12, 30, 20, 160, 235)
188
SpriteFrame(-8, -8, 16, 16, 174, 218)
189
SpriteFrame(-32, -8, 64, 16, 126, 191)
190
191
SetTableValue(TypeName[Rotate Platform], DebugMode_ObjCount, DebugMode_TypesTable)
192
SetTableValue(RotatePlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
193
SetTableValue(RotatePlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
194
DebugMode_ObjCount++
195
196
foreach (TypeName[Rotate Platform], arrayPos0, ALL_ENTITIES)
197
object[arrayPos0].length = 3
198
199
object[arrayPos0].rotateSpeed = object[arrayPos0].propertyValue
200
object[arrayPos0].rotateSpeed &= 0xF0
201
if object[arrayPos0].rotateSpeed >= 0x80
202
object[arrayPos0].rotateSpeed -= 0x80
203
FlipSign(object[arrayPos0].rotateSpeed)
204
end if
205
object[arrayPos0].rotateSpeed <<= 3
206
207
object[arrayPos0].rotateAngle = object[arrayPos0].propertyValue
208
object[arrayPos0].rotateAngle &= 3
209
object[arrayPos0].rotateAngle <<= 15
210
211
temp5 = object[arrayPos0].propertyValue
212
temp5 >>= 2
213
temp5 &= 3
214
if temp5 == 1
215
object[arrayPos0].rotateAngle += 0x5500
216
end if
217
218
if temp5 == 2
219
object[arrayPos0].rotateAngle -= 0x5500
220
end if
221
next
222
end event
223
224
225
// ========================
226
// Editor Events
227
// ========================
228
229
event RSDKEdit
230
if editor.returnVariable == true
231
switch editor.variableID
232
case EDIT_VAR_PROPVAL // property value
233
checkResult = object.propertyValue
234
break
235
236
case 0 // angle
237
checkResult = object.propertyValue
238
checkResult &= 3
239
break
240
241
case 1 // offset
242
checkResult = object.propertyValue
243
checkResult >>= 2
244
checkResult &= 3
245
break
246
247
case 2 // rotateSpeed
248
checkResult = object.propertyValue
249
checkResult >>= 4
250
checkResult &= 0xF
251
break
252
end switch
253
else
254
switch editor.variableID
255
case EDIT_VAR_PROPVAL // property value
256
object.propertyValue = editor.variableValue
257
break
258
259
case 0 // angle
260
editor.variableValue &= 3
261
262
temp0 = 3
263
Not(temp0)
264
object.propertyValue &= temp0
265
266
object.propertyValue |= editor.variableValue
267
break
268
269
case 1 // offset
270
editor.variableValue &= 3
271
editor.variableValue <<= 2
272
273
temp0 = 3
274
temp0 <<= 2
275
Not(temp0)
276
object.propertyValue &= temp0
277
278
object.propertyValue |= editor.variableValue
279
break
280
281
case 2 // rotateSpeed
282
editor.variableValue &= 0xF
283
editor.variableValue <<= 4
284
285
temp0 = 0x0F
286
object.propertyValue &= temp0
287
288
object.propertyValue |= editor.variableValue
289
break
290
end switch
291
end if
292
end event
293
294
295
event RSDKDraw
296
object.length = 3
297
298
object.rotateSpeed = object.propertyValue
299
object.rotateSpeed &= 0xF0
300
if object.rotateSpeed >= 0x80
301
object.rotateSpeed -= 0x80
302
FlipSign(object.rotateSpeed)
303
end if
304
305
object.rotateAngle = object.propertyValue
306
object.rotateAngle &= 3
307
object.rotateAngle <<= 15
308
309
temp5 = object.propertyValue
310
temp5 >>= 2
311
temp5 &= 3
312
if temp5 == 1
313
object.rotateAngle += 0x5500
314
end if
315
316
if temp5 == 2
317
object.rotateAngle -= 0x5500
318
end if
319
320
temp2 = object.xpos
321
temp3 = object.ypos
322
object.rotateAngle &= 0x1FFFF
323
324
temp0 = object.rotateAngle
325
temp0 >>= 8
326
temp1 = object.length
327
temp1++
328
temp1 <<= 4
329
object.xpos = object.drawPos.x
330
object.ypos = object.drawPos.y
331
332
Cos256(object.collisionOffset.x, temp0)
333
object.collisionOffset.x *= temp1
334
object.collisionOffset.x <<= 8
335
object.collisionOffset.x += temp2
336
object.collisionOffset.x &= 0xFFFF0000
337
object.drawPos.x = object.collisionOffset.x
338
object.collisionOffset.x -= object.xpos
339
340
Sin256(object.collisionOffset.y, temp0)
341
object.collisionOffset.y *= temp1
342
object.collisionOffset.y <<= 8
343
object.collisionOffset.y += temp3
344
object.collisionOffset.y &= 0xFFFF0000
345
object.drawPos.y = object.collisionOffset.y
346
object.collisionOffset.y -= object.ypos
347
348
object.xpos = temp2
349
object.ypos = temp3
350
351
temp0 = 0
352
temp1 = 16
353
354
temp4 = object.rotateAngle
355
temp4 >>= 8
356
while temp0 < object.length
357
Cos256(temp2, temp4)
358
temp2 *= temp1
359
temp2 <<= 8
360
temp2 += object.xpos
361
362
Sin256(temp3, temp4)
363
temp3 *= temp1
364
temp3 <<= 8
365
temp3 += object.ypos
366
367
DrawSpriteXY(1, temp2, temp3)
368
369
temp0++
370
temp1 += 16
371
loop
372
Cos256(object.drawPos.x, temp4)
373
object.drawPos.x *= temp1
374
object.drawPos.x <<= 8
375
object.drawPos.x += object.xpos
376
object.drawPos.x &= 0xFFFF0000
377
378
Sin256(object.drawPos.y, temp4)
379
object.drawPos.y *= temp1
380
object.drawPos.y <<= 8
381
object.drawPos.y += object.ypos
382
object.drawPos.y &= 0xFFFF0000
383
384
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
385
386
DrawSprite(0)
387
end event
388
389
390
event RSDKLoad
391
LoadSpriteSheet("ARZ/Objects.gif")
392
SpriteFrame(-15, -12, 30, 20, 160, 235)
393
SpriteFrame(-8, -8, 16, 16, 174, 218)
394
SpriteFrame(-32, -8, 64, 16, 126, 191)
395
396
AddEditorVariable("angle")
397
SetActiveVariable("angle")
398
399
AddEditorVariable("offset")
400
SetActiveVariable("offset")
401
AddEnumVariable("None", 0)
402
AddEnumVariable("Right", 1)
403
AddEnumVariable("Left", 2)
404
405
AddEditorVariable("rotateSpeed")
406
SetActiveVariable("rotateSpeed")
407
end event
408
409