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/InvisibleBlock.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Invisible Block 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.width
13
private alias object.value1 : object.height
14
private alias object.value2 : object.killTimerP1
15
private alias object.value3 : object.killTimerP2
16
17
private alias 0 : INVISIBLEBLOCK_SOLID // regular invis block
18
private alias 1 : INVISIBLEBLOCK_EJECT_L // ejects the player out (to the left)
19
private alias 2 : INVISIBLEBLOCK_EJECT_R // ejects the player out (to the right)
20
21
// Player Aliases
22
private alias object.type : player.type
23
private alias object.state : player.state
24
private alias object.xpos : player.xpos
25
private alias object.speed : player.speed
26
private alias object.gravity : player.gravity
27
private alias object.collisionLeft : player.collisionLeft
28
private alias object.collisionRight : player.collisionRight
29
30
31
// ========================
32
// Function Declarations
33
// ========================
34
35
reserve function InvisibleBlock_DebugDraw
36
reserve function InvisibleBlock_DebugSpawn
37
38
39
// ========================
40
// Static Values
41
// ========================
42
43
// MPZ shortens this, to kill the player fast
44
private value InvisibleBlock_killDelay = 8
45
46
47
// ========================
48
// Function Definitions
49
// ========================
50
51
private function InvisibleBlock_DebugDraw
52
temp0 = object.xpos
53
temp1 = object.ypos
54
temp0 -= 0x80000
55
temp1 -= 0x80000
56
DrawSpriteXY(0, temp0, temp1)
57
58
temp0 += 0x100000
59
DrawSpriteXY(0, temp0, temp1)
60
61
temp0 -= 0x100000
62
temp1 += 0x100000
63
DrawSpriteXY(0, temp0, temp1)
64
65
temp0 += 0x100000
66
DrawSpriteXY(0, temp0, temp1)
67
end function
68
69
70
private function InvisibleBlock_DebugSpawn
71
CreateTempObject(TypeName[Invisible Block], 17, object.xpos, object.ypos)
72
object[tempObjectPos].drawOrder = 5
73
object[tempObjectPos].width = 16
74
object[tempObjectPos].height = 16
75
end function
76
77
78
// ========================
79
// Events
80
// ========================
81
82
event ObjectUpdate
83
temp0 = object.width
84
FlipSign(temp0)
85
temp1 = object.height
86
FlipSign(temp1)
87
88
// Note: state is editable and is set via the editor
89
90
switch object.state
91
case INVISIBLEBLOCK_SOLID
92
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
93
if player[currentPlayer].state != Player_State_LedgePullUp
94
BoxCollisionTest(C_SOLID, object.entityPos, temp0, temp1, object.width, object.height, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
95
switch checkResult
96
case COL_NONE
97
temp0 += 2
98
temp1 += 2
99
temp2 = object.width
100
temp3 = object.height
101
temp2 -= 2
102
temp3 -= 2
103
BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, temp2, temp3, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
104
if checkResult == true
105
player[currentPlayer].gravity = GRAVITY_GROUND
106
end if
107
108
if currentPlayer == 0
109
object.killTimerP1 = 0
110
else
111
object.killTimerP2 = 0
112
end if
113
break
114
115
case COL_BOTTOM
116
if player[currentPlayer].gravity == GRAVITY_GROUND
117
if currentPlayer == 0
118
object.killTimerP1++
119
if object.killTimerP1 > InvisibleBlock_killDelay
120
CallFunction(Player_Kill)
121
end if
122
else
123
object.killTimerP2++
124
if object.killTimerP2 > InvisibleBlock_killDelay
125
CallFunction(Player_Kill)
126
end if
127
end if
128
end if
129
break
130
end switch
131
end if
132
next
133
break
134
135
case INVISIBLEBLOCK_EJECT_L
136
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
137
if player[currentPlayer].state != Player_State_LedgePullUp
138
BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, object.width, object.height, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
139
if checkResult == true
140
if player[currentPlayer].gravity == GRAVITY_GROUND
141
player[currentPlayer].xpos = player[currentPlayer].collisionRight
142
FlipSign(player[currentPlayer].xpos)
143
player[currentPlayer].xpos -= object.width
144
player[currentPlayer].xpos <<= 16
145
player[currentPlayer].xpos += object.xpos
146
if player[currentPlayer].speed > 0
147
player[currentPlayer].speed = 0
148
end if
149
end if
150
end if
151
end if
152
next
153
break
154
155
case INVISIBLEBLOCK_EJECT_R
156
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
157
if player[currentPlayer].state != Player_State_LedgePullUp
158
BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, object.width, object.height, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
159
if checkResult == true
160
if player[currentPlayer].gravity == GRAVITY_GROUND
161
player[currentPlayer].xpos = player[currentPlayer].collisionLeft
162
FlipSign(player[currentPlayer].xpos)
163
player[currentPlayer].xpos += object.width
164
player[currentPlayer].xpos <<= 16
165
player[currentPlayer].xpos += object.xpos
166
if player[currentPlayer].speed < 0
167
player[currentPlayer].speed = 0
168
end if
169
end if
170
end if
171
end if
172
next
173
break
174
175
end switch
176
end event
177
178
179
event ObjectDraw
180
if player[0].type == TypeName[Debug Mode]
181
temp0 = object.xpos
182
temp1 = object.ypos
183
temp2 = object.propertyValue
184
temp4 = temp2
185
temp4 &= 240
186
temp4 <<= 15
187
temp2 >>= 4
188
temp2++
189
temp6 = temp2
190
temp3 = object.propertyValue
191
temp3 &= 15
192
temp5 = temp3
193
temp5 <<= 19
194
temp3++
195
temp0 -= temp4
196
temp4 = temp0
197
temp1 -= temp5
198
while temp3 > 0
199
while temp2 > 0
200
DrawSpriteXY(object.state, temp0, temp1)
201
temp0 += 0x100000
202
temp2--
203
loop
204
temp2 = temp6
205
temp0 = temp4
206
temp1 += 0x100000
207
temp3--
208
loop
209
end if
210
end event
211
212
213
event ObjectStartup
214
LoadSpriteSheet("Global/Display.gif")
215
SpriteFrame(-8, -7, 16, 14, 1, 176)
216
SpriteFrame(-8, -7, 16, 14, 17, 176)
217
SpriteFrame(-8, -7, 16, 14, 1, 190)
218
219
foreach (TypeName[Invisible Block], arrayPos0, ALL_ENTITIES)
220
object[arrayPos0].drawOrder = 5
221
object[arrayPos0].width = object[arrayPos0].propertyValue
222
object[arrayPos0].width &= 0xF0
223
object[arrayPos0].width += 16
224
object[arrayPos0].width >>= 1
225
object[arrayPos0].height = object[arrayPos0].propertyValue
226
object[arrayPos0].height &= 15
227
object[arrayPos0].height++
228
object[arrayPos0].height <<= 3
229
next
230
231
CheckCurrentStageFolder("Zone09")
232
if checkResult == true
233
InvisibleBlock_killDelay = 1
234
end if
235
236
SetTableValue(TypeName[Invisible Block], DebugMode_ObjCount, DebugMode_TypesTable)
237
SetTableValue(InvisibleBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
238
SetTableValue(InvisibleBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
239
DebugMode_ObjCount++
240
end event
241
242
243
// ========================
244
// Editor Events
245
// ========================
246
247
event RSDKEdit
248
if editor.returnVariable == true
249
switch editor.variableID
250
case EDIT_VAR_PROPVAL // property value
251
checkResult = object.propertyValue
252
break
253
254
case 0 // width
255
checkResult = object.propertyValue
256
checkResult >>= 4
257
checkResult &= 0xF
258
break
259
260
case 1 // height
261
checkResult = object.propertyValue
262
checkResult &= 0xF
263
break
264
265
case 2 // type
266
checkResult = object.state
267
break
268
269
end switch
270
else
271
switch editor.variableID
272
case EDIT_VAR_PROPVAL // property value
273
object.propertyValue = editor.variableValue
274
break
275
276
case 0 // width
277
temp0 = editor.variableValue
278
temp0 &= 0xF
279
temp0 <<= 4
280
281
object.propertyValue &= 0x0F
282
object.propertyValue |= temp0
283
break
284
285
case 1 // height
286
temp0 = editor.variableValue
287
temp0 &= 0xF
288
289
object.propertyValue &= 0xF0
290
object.propertyValue |= temp0
291
break
292
293
case 2 // type
294
object.state = editor.variableValue
295
break
296
297
end switch
298
end if
299
end event
300
301
302
event RSDKDraw
303
temp0 = object.xpos
304
temp1 = object.ypos
305
temp2 = object.propertyValue
306
307
temp4 = temp2
308
temp4 &= 0xF0
309
temp4 <<= 15
310
temp2 >>= 4
311
temp2++
312
temp6 = temp2
313
314
temp3 = object.propertyValue
315
temp3 &= 0x0F
316
temp5 = temp3
317
temp5 <<= 19
318
temp3++
319
320
temp0 -= temp4
321
temp4 = temp0
322
temp1 -= temp5
323
while temp3 > 0
324
while temp2 > 0
325
DrawSpriteXY(object.state, temp0, temp1)
326
temp0 += 0x100000
327
temp2--
328
loop
329
temp2 = temp6
330
temp0 = temp4
331
temp1 += 0x100000
332
temp3--
333
loop
334
end event
335
336
337
event RSDKLoad
338
LoadSpriteSheet("Global/Display.gif")
339
SpriteFrame(-8, -7, 16, 14, 1, 176)
340
SpriteFrame(-8, -7, 16, 14, 17, 176)
341
SpriteFrame(-8, -7, 16, 14, 1, 190)
342
343
AddEditorVariable("width")
344
AddEditorVariable("height")
345
346
AddEditorVariable("type")
347
SetActiveVariable("type")
348
AddEnumVariable("Solid", INVISIBLEBLOCK_SOLID)
349
AddEnumVariable("Eject left", INVISIBLEBLOCK_EJECT_L)
350
AddEnumVariable("Eject right", INVISIBLEBLOCK_EJECT_R)
351
end event
352
353