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