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/MZ/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("MZ/Objects.gif")
190
SpriteFrame(-8, -8, 16, 16, 76, 160) // connection joint - #0
191
SpriteFrame(-8, -8, 16, 16, 93, 160) // chain link - #1
192
SpriteFrame(-24, -8, 48, 16, 69, 177) // platform - #2
193
194
temp0 = 0
195
SwingPlatform_startDebugID = DebugMode_ObjCount
196
SwingPlatform_startDebugID--
197
while temp0 < 8
198
SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)
199
SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
200
SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
201
DebugMode_ObjCount++
202
temp0++
203
loop
204
end event
205
206
207
event RSDKDraw
208
DrawSprite(0)
209
210
temp0 = 0
211
temp1 = 16
212
while temp0 < object.length
213
Cos(temp2, 128)
214
temp2 *= temp1
215
temp2 <<= 7
216
temp2 += object.xpos
217
Sin(temp3, 128)
218
temp3 *= temp1
219
temp3 <<= 7
220
temp3 += object.ypos
221
DrawSpriteXY(1, temp2, temp3)
222
temp0++
223
temp1 += 16
224
loop
225
226
temp1 -= 8
227
Cos(temp2, 128)
228
temp2 *= temp1
229
temp2 <<= 7
230
temp2 += object.xpos
231
Sin(temp3, 128)
232
temp3 *= temp1
233
temp3 <<= 7
234
temp3 += object.ypos
235
DrawSpriteXY(2, temp2, temp3)
236
237
if editor.showGizmos == true
238
editor.drawingOverlay = true
239
// Draw the platform's path to the right and left too to show where and how far it'll go
240
241
object.inkEffect = INK_ALPHA
242
243
// Left chains
244
temp0 = 0
245
temp1 = 16
246
while temp0 < object.length
247
Cos(temp2, 0)
248
temp2 *= temp1
249
temp2 <<= 7
250
temp2 += object.xpos
251
Sin(temp3, 0)
252
temp3 *= temp1
253
temp3 <<= 7
254
temp3 += object.ypos
255
DrawSpriteFX(1, FX_INK, temp2, temp3)
256
temp0++
257
temp1 += 16
258
loop
259
260
// Left platform
261
temp1 -= 8
262
Cos(temp2, 0)
263
temp2 *= temp1
264
temp2 <<= 7
265
temp2 += object.xpos
266
Sin(temp3, 0)
267
temp3 *= temp1
268
temp3 <<= 7
269
temp3 += object.ypos
270
DrawSpriteFX(2, FX_INK, temp2, temp3)
271
272
// Right chains
273
temp0 = 0
274
temp1 = 16
275
while temp0 < object.length
276
Cos(temp2, 256)
277
temp2 *= temp1
278
temp2 <<= 7
279
temp2 += object.xpos
280
Sin(temp3, 256)
281
temp3 *= temp1
282
temp3 <<= 7
283
temp3 += object.ypos
284
DrawSpriteFX(1, FX_INK, temp2, temp3)
285
temp0++
286
temp1 += 16
287
loop
288
289
// Right platform
290
temp1 -= 8
291
Cos(temp2, 256)
292
temp2 *= temp1
293
temp2 <<= 7
294
temp2 += object.xpos
295
Sin(temp3, 256)
296
temp3 *= temp1
297
temp3 <<= 7
298
temp3 += object.ypos
299
DrawSpriteFX(2, FX_INK, temp2, temp3)
300
301
editor.drawingOverlay = false
302
end if
303
end event
304
305
306
event RSDKLoad
307
LoadSpriteSheet("MZ/Objects.gif")
308
SpriteFrame(-8, -8, 16, 16, 76, 160) // connection joint - #0
309
SpriteFrame(-8, -8, 16, 16, 93, 160) // chain link - #1
310
SpriteFrame(-24, -8, 48, 16, 69, 177) // platform - #2
311
312
SetVariableAlias(ALIAS_VAR_PROPVAL, "length")
313
end event
314
315