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/Global/Springboard.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Springboard 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.bounceDelay
13
private alias object.value1 : object.force // unused (set but never actually used properly, which funnily enough is how it works in the original S2 too)
14
private alias object.value2 : object.activePlayers
15
16
// Player Aliases
17
private alias object.state : player.state
18
private alias object.xpos : player.xpos
19
private alias object.ypos : player.ypos
20
private alias object.iypos : player.iypos
21
private alias object.xvel : player.xvel
22
private alias object.yvel : player.yvel
23
private alias object.speed : player.speed
24
private alias object.gravity : player.gravity
25
private alias object.frame : player.frame
26
private alias object.prevAnimation : player.prevAnimation
27
private alias object.animationSpeed : player.animationSpeed
28
private alias object.animation : player.animation
29
private alias object.collisionBottom : player.collisionBottom
30
private alias object.tileCollisions : player.tileCollisions
31
private alias object.value1 : player.timer
32
private alias object.value10 : player.animationReserve
33
private alias object.value17 : debugMode.currentSelection
34
private alias object.value25 : player.gravityStrength
35
36
37
// ========================
38
// Function Declarations
39
// ========================
40
41
reserve function Springboard_DebugDraw
42
reserve function Springboard_DebugSpawn
43
44
45
// ========================
46
// Static Values
47
// ========================
48
49
private value Springboard_debugStartID = 0
50
51
52
// ========================
53
// Tables
54
// ========================
55
56
// tech
57
private table Springboard_springForceTable
58
-0x40000, -0xA0000, -0x80000
59
end table
60
61
private table Springboard_springPowerTable
62
0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000
63
-0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000
64
-0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000
65
-0x20000, -0x20000, -0x20000, -0x20000, -0x20000, -0x20000, -0x20000, -0x20000
66
-0x30000, -0x30000, -0x30000, -0x30000, -0x30000, -0x30000, -0x40000, -0x40000
67
end table
68
69
private table Springboard_heightsReadyTable
70
8, 9, 10, 11, 12, 13, 14
71
15, 16, 16, 17, 18, 19, 20
72
20, 21, 21, 22, 23, 24, 24
73
24, 24, 24, 24, 24, 24, 24
74
end table
75
76
private table Springboard_heightsFlatTable
77
8, 9, 10, 11, 12, 12, 12
78
12, 13, 13, 13, 13, 13, 13
79
14, 14, 15, 15, 16, 16, 16
80
16, 15, 15, 14, 14, 13, 13
81
end table
82
83
84
// ========================
85
// Function Definitions
86
// ========================
87
88
private function Springboard_DebugDraw
89
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
90
end function
91
92
93
private function Springboard_DebugSpawn
94
temp0 = debugMode[0].currentSelection
95
temp0 -= Springboard_debugStartID
96
CreateTempObject(TypeName[Springboard], 0, object.xpos, object.ypos)
97
GetTableValue(object[tempObjectPos].force, temp0, Springboard_springForceTable) // doesn't really mean anything since object.force is unused
98
object[tempObjectPos].direction = object.direction
99
end function
100
101
102
// ========================
103
// Events
104
// ========================
105
106
event ObjectUpdate
107
if object.bounceDelay != 0
108
object.bounceDelay--
109
switch object.bounceDelay
110
case 0
111
temp2 = 0
112
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
113
GetBit(temp3, object.activePlayers, temp2)
114
if temp3 == true
115
temp0 = player[currentPlayer].xpos
116
temp0 -= object.xpos
117
temp0 += 0x1C0000
118
temp0 >>= 17
119
GetBit(temp3, object.direction, 0)
120
if temp3 == FLIP_X
121
temp0 -= 28
122
FlipSign(temp0)
123
end if
124
125
if temp0 >= 8
126
player[currentPlayer].animationReserve = ANI_WALKING
127
if player[currentPlayer].animation == ANI_RUNNING
128
player[currentPlayer].animationReserve = ANI_RUNNING
129
end if
130
131
if player[currentPlayer].animation == ANI_PEELOUT
132
player[currentPlayer].animationReserve = ANI_PEELOUT
133
end if
134
135
object.bounceDelay = 1
136
#platform: USE_STANDALONE
137
player[currentPlayer].state = Player_State_Air
138
#endplatform
139
#platform: USE_ORIGINS
140
player[currentPlayer].state = Player_State_Air_NoDropDash
141
#endplatform
142
player[currentPlayer].tileCollisions = true
143
player[currentPlayer].gravity = GRAVITY_AIR
144
player[currentPlayer].speed = player[currentPlayer].xvel
145
temp0 -= 8
146
temp0 <<= 1
147
if temp0 > 39
148
temp0 = 39
149
end if
150
151
GetTableValue(player[currentPlayer].yvel, temp0, Springboard_springPowerTable)
152
player[currentPlayer].yvel -= 0x40000 // constant in place of object.force (see ObjectStartup)
153
player[currentPlayer].yvel -= player[currentPlayer].gravityStrength
154
player[currentPlayer].animation = ANI_TWIRL
155
player[currentPlayer].prevAnimation = ANI_TWIRL
156
player[currentPlayer].frame = 0
157
player[currentPlayer].animationSpeed = 80
158
player[currentPlayer].timer = 0
159
PlaySfx(SfxName[Spring], false)
160
end if
161
end if
162
temp2++
163
next
164
break
165
166
case 1
167
object.frame = 0
168
break
169
170
default
171
object.frame = 1
172
break
173
174
end switch
175
end if
176
177
temp2 = 0
178
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
179
temp0 = player[currentPlayer].xpos
180
temp0 -= object.xpos
181
temp0 += 0x1C0000
182
temp0 >>= 17
183
if temp0 < 0
184
temp0 = 0
185
end if
186
if temp0 > 27
187
temp0 = 27
188
end if
189
190
switch object.direction
191
case FLIP_NONE
192
if object.frame == 0
193
GetTableValue(temp1, temp0, Springboard_heightsReadyTable)
194
else
195
GetTableValue(temp1, temp0, Springboard_heightsFlatTable)
196
end if
197
198
FlipSign(temp1)
199
temp4 = player[currentPlayer].speed
200
temp5 = player[currentPlayer].xpos
201
BoxCollisionTest(C_SOLID, object.entityPos, -28, temp1, 28, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
202
switch checkResult
203
case COL_LEFT
204
player[currentPlayer].speed = temp4
205
player[currentPlayer].xpos = temp5
206
// [Fallthrough]
207
case COL_NONE
208
case COL_RIGHT
209
case COL_BOTTOM
210
GetBit(temp3, object.activePlayers, temp2)
211
if temp3 == true
212
temp3 = player[currentPlayer].xpos
213
temp3 -= object.xpos
214
temp3 >>= 16
215
Abs(temp3)
216
if temp3 < 28
217
if player[currentPlayer].yvel >= 0
218
player[currentPlayer].iypos = player[currentPlayer].collisionBottom
219
FlipSign(player[currentPlayer].ypos)
220
temp1 <<= 16
221
player[currentPlayer].ypos += temp1
222
player[currentPlayer].ypos += object.ypos
223
checkResult = true
224
end if
225
end if
226
end if
227
break
228
end switch
229
break
230
231
case FLIP_X
232
temp0 -= 27
233
Abs(temp0)
234
if object.frame == 0
235
GetTableValue(temp1, temp0, Springboard_heightsReadyTable)
236
else
237
GetTableValue(temp1, temp0, Springboard_heightsFlatTable)
238
end if
239
240
FlipSign(temp1)
241
temp4 = player[currentPlayer].speed
242
temp5 = player[currentPlayer].xpos
243
BoxCollisionTest(C_SOLID, object.entityPos, -28, temp1, 28, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
244
switch checkResult
245
case COL_RIGHT
246
player[currentPlayer].speed = temp4
247
player[currentPlayer].xpos = temp5
248
// [Fallthrough]
249
case COL_NONE
250
case COL_LEFT
251
case COL_TOP
252
GetBit(temp3, object.activePlayers, temp2)
253
if temp3 == true
254
temp3 = player[currentPlayer].xpos
255
temp3 -= object.xpos
256
temp3 >>= 16
257
Abs(temp3)
258
if temp3 < 28
259
if player[currentPlayer].yvel >= 0
260
player[currentPlayer].iypos = player[currentPlayer].collisionBottom
261
FlipSign(player[currentPlayer].ypos)
262
temp1 <<= 16
263
player[currentPlayer].ypos += temp1
264
player[currentPlayer].ypos += object.ypos
265
checkResult = true
266
end if
267
end if
268
end if
269
break
270
end switch
271
break
272
273
// Sorry, no upside-down Springboards..
274
case FLIP_Y
275
break
276
277
case FLIP_XY
278
break
279
280
end switch
281
282
if checkResult == true
283
SetBit(object.activePlayers, temp2, true)
284
if temp0 >= 8
285
if object.bounceDelay == 0
286
object.bounceDelay = 6
287
end if
288
end if
289
else
290
SetBit(object.activePlayers, temp2, false)
291
end if
292
293
temp2++
294
next
295
end event
296
297
298
event ObjectDraw
299
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
300
end event
301
302
303
event ObjectStartup
304
LoadSpriteSheet("Global/Items.gif")
305
306
foreach (TypeName[Springboard], arrayPos0, ALL_ENTITIES)
307
// This part is... weird
308
// For one, where is this temp0 coming from?
309
// Here's some fun little notes
310
// - This object was definitely scripted using the original game's asm as reference, seeing that the two's code are pretty similar
311
// - In the original S2, the object would get a force value based on (subtype & 2)
312
// - However, even with that, the force value would never get read and a force of 0x40000 (the first entry on the table) would be used all the time instead
313
// - For some reason, it looks like they decided to do the same thing in this remake?
314
// - They still have the same force table, they still get the force value and store it, and they even still force a force of 0x40000 in the actual script too
315
// - this whole situation is kinda really confusing, but at the very least we can guess that temp0 was like
316
// GetBit(temp0, object.propertyValue, 1)
317
// - Or something like that (in the original game bit 0 was useTwirlAnim and the second bit would be force)
318
319
GetTableValue(object[arrayPos0].force, temp0, Springboard_springForceTable)
320
next
321
322
// One of the rare instances of code being between the sprite sheet and Sprite Frames, a Springboard only has two frames
323
SpriteFrame(-28, -24, 56, 16, 52, 160)
324
SpriteFrame(-28, -16, 56, 8, 52, 177)
325
326
temp0 = 0
327
Springboard_debugStartID = DebugMode_ObjCount
328
while temp0 < 3
329
SetTableValue(TypeName[Springboard], DebugMode_ObjCount, DebugMode_TypesTable)
330
SetTableValue(Springboard_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
331
SetTableValue(Springboard_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
332
DebugMode_ObjCount++
333
temp0++
334
loop
335
end event
336
337
338
// ========================
339
// Editor Events
340
// ========================
341
342
event RSDKDraw
343
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
344
end event
345
346
347
event RSDKLoad
348
LoadSpriteSheet("Global/Items.gif")
349
SpriteFrame(-28, -24, 56, 16, 52, 160)
350
351
// dir is attr to set from scene, prop val is unused even if it is set sometimes (in the original game it was force/useTwirlAnim)
352
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
353
end event
354
355