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/HTZ/Earthquake.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Earthquake 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.earthquakeType
13
14
private alias object.value1 : object.maxPos
15
private alias object.value2 : object.minPos
16
17
// First set of sensor values for knowing whether to hold earthquake values or to reset
18
private alias object.value3 : object.sensorHold.left
19
private alias object.value4 : object.sensorHold.top
20
private alias object.value5 : object.sensorHold.right
21
private alias object.value6 : object.sensorHold.bottom
22
23
// Main set of sensor values, used for sensing if the player's in the actual earthquake area
24
private alias object.value7 : object.sensorMain.left
25
private alias object.value8 : object.sensorMain.top
26
private alias object.value9 : object.sensorMain.right
27
private alias object.value10 : object.sensorMain.bottom
28
29
// Acutal collision sizes for the object to use with player interaction during earthquake
30
private alias object.value11 : object.colbox.left
31
private alias object.value12 : object.colbox.top
32
private alias object.value13 : object.colbox.right
33
private alias object.value14 : object.colbox.bottom
34
35
private alias object.value15 : object.prevPos
36
private alias object.value16 : object.scrollStartPos
37
38
// Reserved object slots
39
private alias 0 : SLOT_PLAYER1
40
41
private alias 0 : EARTHQUAKE_NONE
42
private alias 1 : EARTHQUAKE_HOLD
43
private alias 2 : EARTHQUAKE_ACTIVE
44
45
// Player Aliases
46
private alias object.xpos : player.xpos
47
private alias object.ypos : player.ypos
48
private alias object.xvel : player.xvel
49
private alias object.gravity : player.gravity
50
51
private alias object.value42 : player.prevGravity
52
53
54
// ========================
55
// Tables
56
// ========================
57
58
private table Earthquake_collisionBoxSizes
59
-192, -256, 192, 256
60
-192, -320, 192, 320
61
-192, -448, 192, 448
62
-384, -256, 384, 128
63
-448, -448, 448, 448
64
-448, -448, 448, 448
65
end table
66
67
private table Earthquake_sensorsMain
68
-192, -640, 1042, 256
69
0, 0, 0, 0 // Two empty ones here because these are in a set of three earquake objects in the HTZ1 scene, so there's only really need to have one hitbox sensor
70
0, 0, 0, 0
71
-384, -896, 600, 128
72
-448, -1344, 672, 448
73
-448, -1120, 672, 448
74
end table
75
76
private table Earthquake_sensorsHold
77
-448, -640, 1298, 256
78
0, 0, 0, 0
79
0, 0, 0, 0
80
-640, -896, 856, 128
81
-704, -1344, 928, 448
82
-704, -1120, 928, 448
83
end table
84
85
private table Earthquake_types
86
1, 1, 1 // These first three are all the same because they're used in the same earthquake event
87
2, 3, 4
88
end table
89
90
private table Earthquake_maxMinPos
91
-0xE00000, -0x1400000
92
0x000000, -0x2B40000
93
0x000000, -0x3000000
94
0x000000, -0x3500000
95
end table
96
97
private table Earthquake_scrollStartPos
98
0, 0, 0x6800000, 0x11800000
99
end table
100
101
102
// ========================
103
// Events
104
// ========================
105
106
event ObjectUpdate
107
BoxCollisionTest(C_TOUCH, object.entityPos, object.sensorMain.left, object.sensorMain.top, object.sensorMain.right, object.sensorMain.bottom, SLOT_PLAYER1, 0, 0, 0, 0)
108
if checkResult == true
109
if HTZSetup_earthquakeState == EARTHQUAKE_NONE
110
HTZSetup_earthquakeState = EARTHQUAKE_ACTIVE
111
HTZSetup_activeEarthquakeType = object.earthquakeType
112
HTZSetup_earthquakePosMax = object.maxPos
113
HTZSetup_earthquakePosMin = object.minPos
114
hParallax[20].scrollPos = object.scrollStartPos
115
end if
116
end if
117
118
BoxCollisionTest(C_TOUCH, object.entityPos, object.sensorHold.left, object.sensorHold.top, object.sensorHold.right, object.sensorHold.bottom, SLOT_PLAYER1, 0, 0, 0, 0)
119
if checkResult == true
120
if HTZSetup_earthquakeState == EARTHQUAKE_NONE
121
// Player isn't exactly in active earthquake area, but they're not fully out either,
122
// so make the earthquake holds its values in case it's still in view or the player decides to go back
123
HTZSetup_earthquakeState = EARTHQUAKE_HOLD
124
HTZSetup_activeEarthquakeType = object.earthquakeType
125
HTZSetup_earthquakePosMax = object.maxPos
126
HTZSetup_earthquakePosMin = object.minPos
127
hParallax[20].scrollPos = object.scrollStartPos
128
end if
129
end if
130
131
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
132
temp0 = object.colbox.top
133
temp0 -= object.prevPos
134
temp1 = object.colbox.bottom
135
temp1 -= object.prevPos
136
137
if object.propertyValue == 3
138
// If it's the slope version, then account for its special collision properties
139
temp2 = player[currentPlayer].xpos
140
temp2 -= object.xpos
141
temp2 += 0x1800000
142
if temp2 > 0
143
temp2 >>= 18
144
temp0 += temp2
145
end if
146
147
temp0++
148
if player[currentPlayer].prevGravity == GRAVITY_GROUND
149
if player[currentPlayer].gravity == GRAVITY_AIR
150
if player[currentPlayer].xvel > 0
151
temp2 = player[currentPlayer].xvel
152
temp2 >>= 2
153
player[currentPlayer].ypos += temp2
154
player[currentPlayer].ypos += 0x20000
155
end if
156
end if
157
end if
158
end if
159
160
BoxCollisionTest(C_SOLID, object.entityPos, object.colbox.left, temp0, object.colbox.right, temp1, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
161
switch checkResult
162
case COL_TOP
163
temp0 = HTZSetup_earthquakePos
164
temp0 -= object.prevPos
165
temp0 <<= 16
166
player[currentPlayer].ypos -= temp0
167
// [Fallthrough]
168
case COL_LEFT
169
case COL_RIGHT
170
if object.propertyValue == 2
171
CallFunction(Player_FireHit)
172
end if
173
174
if object.propertyValue == 4
175
CallFunction(Player_FireHit)
176
end if
177
178
if object.propertyValue == 5
179
CallFunction(Player_FireHit)
180
end if
181
break
182
183
case COL_BOTTOM
184
if player[currentPlayer].gravity == GRAVITY_GROUND
185
CallFunction(Player_Kill)
186
end if
187
break
188
189
end switch
190
next
191
192
foreach (TypeName[Lose Ring], arrayPos0, ACTIVE_ENTITIES)
193
if object[arrayPos0].yvel >= 0
194
temp0 = object.colbox.top
195
temp0 -= object.prevPos
196
temp1 = object.colbox.bottom
197
temp1 -= object.prevPos
198
if object.propertyValue == 3
199
temp2 = object[arrayPos0].xpos
200
temp2 -= object.xpos
201
temp2 += 0x1800000
202
if temp2 > 0
203
temp2 >>= 18
204
temp0 += temp2
205
end if
206
temp0++
207
end if
208
temp2 = object[arrayPos0].yvel
209
210
BoxCollisionTest(C_PLATFORM, object.entityPos, object.colbox.left, temp0, object.colbox.right, temp1, arrayPos0, -8, -8, 8, 8)
211
if checkResult == true
212
object[arrayPos0].yvel = temp2
213
temp2 >>= 2
214
object[arrayPos0].yvel -= temp2
215
FlipSign(object[arrayPos0].yvel)
216
if object[arrayPos0].yvel > -0x10000
217
object[arrayPos0].yvel = -0x10000
218
end if
219
object[arrayPos0].gravity = GRAVITY_AIR
220
end if
221
end if
222
next
223
224
object.prevPos = HTZSetup_earthquakePos
225
end event
226
227
228
event ObjectStartup
229
foreach (TypeName[Earthquake], arrayPos0, ALL_ENTITIES)
230
object[arrayPos0].priority = PRIORITY_ACTIVE
231
232
// First get the object's target earthquake type based off its property value
233
GetTableValue(object[arrayPos0].earthquakeType, object[arrayPos0].propertyValue, Earthquake_types)
234
235
// Then use the earthquake's dedicated type for the next few value searches rather than simply its property value
236
temp0 = object[arrayPos0].earthquakeType
237
temp0--
238
239
GetTableValue(object[arrayPos0].scrollStartPos, temp0, Earthquake_scrollStartPos)
240
241
temp0 <<= 1
242
GetTableValue(object[arrayPos0].maxPos, temp0, Earthquake_maxMinPos)
243
244
temp0++
245
GetTableValue(object[arrayPos0].minPos, temp0, Earthquake_maxMinPos)
246
247
// Get the sizes of the earthquake boxes
248
temp0 = object[arrayPos0].propertyValue
249
temp0 <<= 2
250
GetTableValue(object[arrayPos0].colbox.left, temp0, Earthquake_collisionBoxSizes)
251
GetTableValue(object[arrayPos0].sensorHold.left, temp0, Earthquake_sensorsHold)
252
GetTableValue(object[arrayPos0].sensorMain.left, temp0, Earthquake_sensorsMain)
253
254
temp0++
255
GetTableValue(object[arrayPos0].colbox.top, temp0, Earthquake_collisionBoxSizes)
256
GetTableValue(object[arrayPos0].sensorHold.top, temp0, Earthquake_sensorsHold)
257
GetTableValue(object[arrayPos0].sensorMain.top, temp0, Earthquake_sensorsMain)
258
259
temp0++
260
GetTableValue(object[arrayPos0].colbox.right, temp0, Earthquake_collisionBoxSizes)
261
GetTableValue(object[arrayPos0].sensorHold.right, temp0, Earthquake_sensorsHold)
262
GetTableValue(object[arrayPos0].sensorMain.right, temp0, Earthquake_sensorsMain)
263
264
temp0++
265
GetTableValue(object[arrayPos0].colbox.bottom, temp0, Earthquake_collisionBoxSizes)
266
GetTableValue(object[arrayPos0].sensorHold.bottom, temp0, Earthquake_sensorsHold)
267
GetTableValue(object[arrayPos0].sensorMain.bottom, temp0, Earthquake_sensorsMain)
268
269
if options.vsMode == true
270
// No earthquakes in 2P
271
ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
272
end if
273
next
274
end event
275
276
277
// ========================
278
// Editor Events
279
// ========================
280
281
event RSDKEdit
282
if editor.returnVariable == true
283
switch editor.variableID
284
case EDIT_VAR_PROPVAL // property value
285
checkResult = object.propertyValue
286
break
287
288
case 0 // type
289
checkResult = object.propertyValue
290
break
291
292
end switch
293
else
294
switch editor.variableID
295
case EDIT_VAR_PROPVAL // property value
296
object.propertyValue = editor.variableValue
297
break
298
299
case 0 // type
300
object.propertyValue = editor.variableValue
301
break
302
303
end switch
304
end if
305
end event
306
307
308
event RSDKDraw
309
DrawSprite(0)
310
end event
311
312
313
event RSDKLoad
314
LoadSpriteSheet("Global/Display.gif")
315
SpriteFrame(-16, -16, 32, 32, 1, 143)
316
317
AddEditorVariable("type")
318
SetActiveVariable("type")
319
AddEnumVariable("Ground (Flat)", 0)
320
AddEnumVariable("Ground (Wall)", 1)
321
AddEnumVariable("Lava (Wide, Ver 1)", 2)
322
AddEnumVariable("Ground (Sloped)", 3)
323
AddEnumVariable("Lava (Wide, Ver 2)", 4)
324
AddEnumVariable("Lava (Wide, Ver 3)", 5)
325
end event
326
327