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/GHZ/SwingPlat.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
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
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
private alias object.ypos : player.ypos
23
24
private alias object.value17 : debugMode.currentSelection
25
26
27
// ========================
28
// Function Declarations
29
// ========================
30
31
reserve function SwingPlatform_DebugDraw
32
reserve function SwingPlatform_DebugSpawn
33
34
35
// ========================
36
// Static Values
37
// ========================
38
39
private value SwingPlatform_startDebugID = 0
40
41
42
// ========================
43
// Function Definitions
44
// ========================
45
46
private function SwingPlatform_DebugDraw
47
temp7 = debugMode[0].currentSelection
48
temp7 -= SwingPlatform_startDebugID
49
50
// Draw the post
51
DrawSprite(0)
52
53
// Draw the chains
54
temp0 = 0
55
temp1 = 16
56
while temp0 < temp7
57
Cos(temp2, 128)
58
temp2 *= temp1
59
temp2 <<= 7
60
temp2 += object.xpos
61
Sin(temp3, 128)
62
temp3 *= temp1
63
temp3 <<= 7
64
temp3 += object.ypos
65
DrawSpriteXY(1, temp2, temp3)
66
temp0++
67
temp1 += 16
68
loop
69
70
// Draw the platform itself
71
temp1 -= 8
72
Cos(temp2, 128)
73
temp2 *= temp1
74
temp2 <<= 7
75
temp2 += object.xpos
76
77
Sin(temp3, 128)
78
temp3 *= temp1
79
temp3 <<= 7
80
temp3 += object.ypos
81
82
DrawSpriteXY(2, temp2, temp3)
83
end function
84
85
86
private function SwingPlatform_DebugSpawn
87
temp0 = debugMode[0].currentSelection
88
temp0 -= SwingPlatform_startDebugID
89
90
CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)
91
object[tempObjectPos].direction = object.direction
92
end function
93
94
95
// ========================
96
// Events
97
// ========================
98
99
event ObjectUpdate
100
// Backup the object's position, as it'll need to be moved for collision checks
101
temp2 = object.xpos
102
temp3 = object.ypos
103
104
GetTableValue(object.swingAngle, 12, StageSetup_oscillationTable)
105
object.swingAngle >>= 8
106
if object.direction == FLIP_X
107
object.swingAngle ^= 255
108
object.swingAngle += 129
109
end if
110
object.swingAngle <<= 1
111
112
temp1 = object.length
113
temp1++
114
temp1 <<= 4
115
temp1 -= 8
116
object.xpos = object.drawPos.x
117
object.ypos = object.drawPos.y
118
119
Cos(object.collisionOffset.x, object.swingAngle)
120
object.collisionOffset.x *= temp1
121
object.collisionOffset.x <<= 7
122
object.collisionOffset.x += temp2
123
object.collisionOffset.x &= 0xFFFF0000
124
object.drawPos.x = object.collisionOffset.x
125
object.collisionOffset.x -= object.xpos
126
127
Sin(object.collisionOffset.y, object.swingAngle)
128
object.collisionOffset.y *= temp1
129
object.collisionOffset.y <<= 7
130
object.collisionOffset.y += temp3
131
object.collisionOffset.y &= 0xFFFF0000
132
object.drawPos.y = object.collisionOffset.y
133
object.collisionOffset.y -= object.ypos
134
135
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
136
BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
137
if checkResult == true
138
player[currentPlayer].xpos += object.collisionOffset.x
139
player[currentPlayer].ypos += object.collisionOffset.y
140
end if
141
next
142
143
// Move the object back to its actual position
144
object.xpos = temp2
145
object.ypos = temp3
146
end event
147
148
149
event ObjectDraw
150
// Draw the post
151
DrawSprite(0)
152
153
// Draw the chains
154
temp0 = 0
155
temp1 = 16
156
while temp0 < object.length
157
Cos(temp2, object.swingAngle)
158
temp2 *= temp1
159
temp2 <<= 7
160
temp2 += object.xpos
161
Sin(temp3, object.swingAngle)
162
temp3 *= temp1
163
temp3 <<= 7
164
temp3 += object.ypos
165
DrawSpriteXY(1, temp2, temp3)
166
temp0++
167
temp1 += 16
168
loop
169
170
// Draw the platform itself
171
temp1 -= 8
172
Cos(object.drawPos.x, object.swingAngle)
173
object.drawPos.x *= temp1
174
object.drawPos.x <<= 7
175
object.drawPos.x += object.xpos
176
object.drawPos.x &= 0xFFFF0000
177
178
Sin(object.drawPos.y, object.swingAngle)
179
object.drawPos.y *= temp1
180
object.drawPos.y <<= 7
181
object.drawPos.y += object.ypos
182
object.drawPos.y &= 0xFFFF0000
183
184
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
185
end event
186
187
188
event ObjectStartup
189
LoadSpriteSheet("GHZ/Objects.gif")
190
191
// Swinging Platform frames
192
SpriteFrame(-8, -8, 16, 16, 84, 1) // connection joint - #0
193
SpriteFrame(-8, -8, 16, 16, 101, 1) // chain link - #1
194
SpriteFrame(-24, -8, 48, 16, 118, 1) // platform - #2
195
196
// Add this object to the debug mode item list 8 times, for 8 different lengths
197
// All entries have different lengths
198
temp0 = 0
199
SwingPlatform_startDebugID = DebugMode_ObjCount
200
SwingPlatform_startDebugID--
201
while temp0 < 8
202
SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)
203
SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
204
SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
205
DebugMode_ObjCount++
206
temp0++
207
loop
208
end event
209
210
211
// ========================
212
// Editor Events
213
// ========================
214
215
event RSDKEdit
216
if editor.returnVariable == true
217
switch editor.variableID
218
case EDIT_VAR_PROPVAL // property value
219
checkResult = object.propertyValue
220
break
221
222
case 0 // startDir
223
checkResult = object.direction
224
break
225
226
end switch
227
else
228
switch editor.variableID
229
case EDIT_VAR_PROPVAL // property value
230
object.propertyValue = editor.variableValue
231
break
232
233
case 0 // startDir
234
object.direction = editor.variableValue
235
break
236
237
end switch
238
end if
239
end event
240
241
242
event RSDKDraw
243
// Draw the post
244
DrawSprite(0)
245
246
// Draw the chains
247
temp0 = 0
248
temp1 = 16
249
while temp0 < object.length
250
Cos(temp2, 128)
251
temp2 *= temp1
252
temp2 <<= 7
253
temp2 += object.xpos
254
Sin(temp3, 128)
255
temp3 *= temp1
256
temp3 <<= 7
257
temp3 += object.ypos
258
DrawSpriteXY(1, temp2, temp3)
259
temp0++
260
temp1 += 16
261
loop
262
263
// Draw the platform itself
264
temp1 -= 8
265
Cos(temp2, 128)
266
temp2 *= temp1
267
temp2 <<= 7
268
temp2 += object.xpos
269
Sin(temp3, 128)
270
temp3 *= temp1
271
temp3 <<= 7
272
temp3 += object.ypos
273
DrawSpriteXY(2, temp2, temp3)
274
275
if editor.showGizmos == true
276
editor.drawingOverlay = true
277
278
#platform: DUMMY
279
// Draw the platform's arc of movement rather than its end points
280
// TODO: Is this too much? It doesn't even work right...
281
282
temp1 += 8
283
temp0 = 1
284
while temp0 < 255
285
Cos(object.drawPos.x, temp0)
286
object.drawPos.x *= temp1
287
object.drawPos.x <<= 7
288
object.drawPos.x += object.xpos
289
object.drawPos.x &= 0xFFFF0000
290
291
Sin(object.drawPos.y, temp0)
292
object.drawPos.y *= temp1
293
object.drawPos.y <<= 7
294
object.drawPos.y += object.ypos
295
object.drawPos.y &= 0xFFFF0000
296
297
DrawRectWorld(object.drawPos.x, object.drawPos.y, 1, 1, 255, 255, 255, 255)
298
299
temp0++
300
loop
301
#endplatform
302
303
// Draw the platform's path to the right and left too to show where and how far it'll go
304
object.inkEffect = INK_BLEND
305
306
// Left chains
307
temp0 = 0
308
temp1 = 16
309
while temp0 < object.length
310
Cos(temp2, 0)
311
temp2 *= temp1
312
temp2 <<= 7
313
temp2 += object.xpos
314
Sin(temp3, 0)
315
temp3 *= temp1
316
temp3 <<= 7
317
temp3 += object.ypos
318
DrawSpriteFX(1, FX_INK, temp2, temp3)
319
temp0++
320
temp1 += 16
321
loop
322
323
// Left platform
324
temp1 -= 8
325
Cos(temp2, 0)
326
temp2 *= temp1
327
temp2 <<= 7
328
temp2 += object.xpos
329
Sin(temp3, 0)
330
temp3 *= temp1
331
temp3 <<= 7
332
temp3 += object.ypos
333
DrawSpriteFX(2, FX_INK, temp2, temp3)
334
335
// Right chains
336
temp0 = 0
337
temp1 = 16
338
while temp0 < object.length
339
Cos(temp2, 256)
340
temp2 *= temp1
341
temp2 <<= 7
342
temp2 += object.xpos
343
Sin(temp3, 256)
344
temp3 *= temp1
345
temp3 <<= 7
346
temp3 += object.ypos
347
DrawSpriteFX(1, FX_INK, temp2, temp3)
348
temp0++
349
temp1 += 16
350
loop
351
352
// Right platform
353
temp1 -= 8
354
Cos(temp2, 256)
355
temp2 *= temp1
356
temp2 <<= 7
357
temp2 += object.xpos
358
Sin(temp3, 256)
359
temp3 *= temp1
360
temp3 <<= 7
361
temp3 += object.ypos
362
DrawSpriteFX(2, FX_INK, temp2, temp3)
363
364
editor.drawingOverlay = false
365
end if
366
end event
367
368
369
event RSDKLoad
370
LoadSpriteSheet("GHZ/Objects.gif")
371
SpriteFrame(-8, -8, 16, 16, 84, 1) // connection joint - #0
372
SpriteFrame(-8, -8, 16, 16, 101, 1) // chain link - #1
373
SpriteFrame(-24, -8, 48, 16, 118, 1) // platform - #2
374
375
AddEditorVariable("startDir")
376
SetActiveVariable("startDir")
377
AddEnumVariable("Left", 0)
378
AddEnumVariable("Right", 1)
379
380
SetVariableAlias(ALIAS_VAR_PROPVAL, "length")
381
382
// TODO: origins mission m006 uses state attr, for something?
383
end event
384
385