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/BreakBlock.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Break 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 0 : BREAKBLOCK_BLOCK
13
private alias 1 : BREAKBLOCK_FRAGMENT
14
15
16
// Player Aliases
17
private alias object.yvel : player.yvel
18
private alias object.gravity : player.gravity
19
private alias object.animation : player.animation
20
private alias object.collisionPlane : player.collisionPlane
21
22
private alias object.value16 : player.isSidekick
23
private alias object.value19 : player.badnikBonus
24
private alias object.value40 : player.hitboxLeft
25
private alias object.value38 : player.hitboxTop
26
private alias object.value41 : player.hitboxRight
27
private alias object.value39 : player.hitboxBottom
28
29
// Debug Mode aliases
30
private alias object.value17 : debugMode.currentSelection
31
32
// Global Variable ID Aliases
33
private alias 22 : GLOBAL_PLAYERSCORE
34
35
36
// ========================
37
// Function Declarations
38
// ========================
39
40
reserve function BreakBlock_DebugDraw
41
reserve function BreakBlock_DebugSpawn
42
43
44
// ========================
45
// Static Values
46
// ========================
47
48
private value BreakBlock_debugStartID = 0
49
private value BreakBlock_groundOffset = 0
50
private value BreakBlock_playerHit = 0 // Introduced in Origins Plus, because using a temp value wasn't good enough
51
52
53
// ========================
54
// Tables
55
// ========================
56
57
private table BreakBlock_fragmentVels
58
-0x10000, -0x80000
59
0x10000, -0x80000
60
-0xE000, -0x70000
61
0xE000, -0x70000
62
-0xC000, -0x60000
63
0xC000, -0x60000
64
-0xA000, -0x50000
65
0xA000, -0x50000
66
-0x8000, -0x40000
67
0x8000, -0x40000
68
end table
69
70
71
// ========================
72
// Function Definitions
73
// ========================
74
75
private function BreakBlock_DebugDraw
76
temp0 = debugMode.currentSelection
77
temp0 -= BreakBlock_debugStartID
78
DrawSprite(temp0)
79
end function
80
81
82
private function BreakBlock_DebugSpawn
83
temp0 = debugMode.currentSelection
84
temp0 -= BreakBlock_debugStartID
85
temp0 |= 0x80 // Set it to be on 1
86
CreateTempObject(TypeName[Break Block], temp0, object.xpos, object.ypos)
87
end function
88
89
90
// ========================
91
// Events
92
// ========================
93
94
event ObjectUpdate
95
switch object.state
96
case BREAKBLOCK_BLOCK
97
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
98
temp1 = object.propertyValue
99
temp1 &= 0x7F
100
if temp1 == 0
101
temp0 = 4
102
else
103
temp0 = 5
104
temp0 -= temp1
105
end if
106
temp0 <<= 3
107
temp1 = temp0
108
FlipSign(temp0)
109
110
#platform: USE_STANDALONE
111
if player[currentPlayer].animation != ANI_JUMPING
112
temp0 += BreakBlock_groundOffset
113
end if
114
115
BoxCollisionTest(C_SOLID, object.entityPos, -16, temp0, 16, temp1, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
116
if checkResult == COL_TOP
117
if player[currentPlayer].animation == ANI_JUMPING
118
#endplatform
119
#platform: USE_ORIGINS
120
BreakBlock_playerHit = false
121
122
if player[currentPlayer].animation == ANI_JUMPING
123
BreakBlock_playerHit = true
124
end if
125
126
if player[currentPlayer].animation == ANI_HAMMER_JUMP
127
BreakBlock_playerHit = 2
128
end if
129
130
if BreakBlock_playerHit == false
131
temp0 += BreakBlock_groundOffset
132
end if
133
134
if BreakBlock_playerHit != 2
135
BoxCollisionTest(C_SOLID, object.entityPos, -16, temp0, 16, temp1, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
136
else
137
BoxCollisionTest(C_SOLID, object.entityPos, -16, temp0, 16, temp1, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
138
end if
139
140
if checkResult == true
141
if BreakBlock_playerHit != false
142
#endplatform
143
GetBit(temp3, object.propertyValue, 7)
144
CheckEqual(player[currentPlayer].collisionPlane, 1)
145
temp3 |= checkResult
146
if temp3 == true
147
player[currentPlayer].yvel = 0
148
player[currentPlayer].gravity = GRAVITY_AIR
149
temp0 += 8
150
temp0 <<= 16
151
temp0 += object.ypos
152
153
temp3 = object.propertyValue
154
temp3 &= 0x7F
155
temp4 = 5
156
temp4 += temp3
157
temp5 = temp3
158
temp5 <<= 2
159
while temp3 < 5
160
CreateTempObject(TypeName[Break Block], temp4, object.xpos, temp0)
161
object[tempObjectPos].ixpos -= 8
162
GetTableValue(object[tempObjectPos].xvel, temp5, BreakBlock_fragmentVels)
163
temp5++
164
GetTableValue(object[tempObjectPos].yvel, temp5, BreakBlock_fragmentVels)
165
temp5++
166
object[tempObjectPos].state = BREAKBLOCK_FRAGMENT
167
object[tempObjectPos].drawOrder = 5
168
169
CreateTempObject(TypeName[Break Block], temp4, object.xpos, temp0)
170
object[tempObjectPos].ixpos += 8
171
GetTableValue(object[tempObjectPos].xvel, temp5, BreakBlock_fragmentVels)
172
temp5++
173
GetTableValue(object[tempObjectPos].yvel, temp5, BreakBlock_fragmentVels)
174
temp5++
175
object[tempObjectPos].state = BREAKBLOCK_FRAGMENT
176
object[tempObjectPos].drawOrder = 5
177
temp0 += 0x100000
178
179
temp3++
180
temp4++
181
loop
182
183
CreateTempObject(TypeName[Object Score], player[currentPlayer].badnikBonus, object.xpos, object.ypos)
184
object[tempObjectPos].drawOrder = 5
185
186
// Decrease the object's height, and shift it down to match
187
object.propertyValue++
188
object.ypos += 0x80000
189
190
temp0 = object.propertyValue
191
temp0 &= 0x7F
192
if temp0 >= 5
193
// If the object's height is 0 now, then remove it
194
object.type = TypeName[Blank Object]
195
end if
196
197
// global variable "array" (yes, this is actually how its done)
198
arrayPos0 = GLOBAL_PLAYERSCORE
199
#platform: USE_DECOMP
200
arrayPos0 = VarName[player.score]
201
#endplatform
202
if player[currentPlayer].isSidekick == false
203
arrayPos0 += currentPlayer
204
end if
205
206
switch player[currentPlayer].badnikBonus
207
case 0
208
global[arrayPos0] += 100
209
break
210
211
case 1
212
global[arrayPos0] += 200
213
break
214
215
case 2
216
global[arrayPos0] += 500
217
break
218
219
case 3
220
case 4
221
case 5
222
case 6
223
case 7
224
case 8
225
case 9
226
case 10
227
case 11
228
case 12
229
case 13
230
case 14
231
global[arrayPos0] += 1000
232
break
233
234
case 15
235
global[arrayPos0] += 10000
236
break
237
238
end switch
239
240
if player[currentPlayer].gravity == GRAVITY_AIR
241
if player[currentPlayer].badnikBonus < 15
242
player[currentPlayer].badnikBonus++
243
end if
244
end if
245
246
PlaySfx(SfxName[Block Break], false)
247
end if
248
end if
249
end if
250
next
251
break
252
253
case BREAKBLOCK_FRAGMENT
254
object.xpos += object.xvel
255
object.ypos += object.yvel
256
object.yvel += 0x1800
257
258
if object.outOfBounds == true
259
object.type = TypeName[Blank Object]
260
end if
261
break
262
263
end switch
264
end event
265
266
267
event ObjectDraw
268
temp0 = object.propertyValue
269
temp0 &= 0x7F
270
DrawSprite(temp0)
271
end event
272
273
274
event ObjectStartup
275
CheckCurrentStageFolder("Zone05")
276
if checkResult == true
277
LoadSpriteSheet("HTZ/Objects.gif")
278
SpriteFrame(-16, -40, 32, 80, 69, 1)
279
SpriteFrame(-16, -32, 32, 64, 69, 17)
280
SpriteFrame(-16, -24, 32, 48, 69, 33)
281
SpriteFrame(-16, -16, 32, 32, 69, 49)
282
SpriteFrame(-16, -8, 32, 16, 69, 65)
283
SpriteFrame(-8, -8, 16, 16, 69, 1)
284
SpriteFrame(-8, -8, 16, 16, 69, 17)
285
SpriteFrame(-8, -8, 16, 16, 69, 33)
286
SpriteFrame(-8, -8, 16, 16, 69, 49)
287
SpriteFrame(-8, -8, 16, 16, 69, 65)
288
BreakBlock_groundOffset = 0
289
else
290
LoadSpriteSheet("MBZ/Objects.gif")
291
SpriteFrame(-16, -40, 32, 80, 105, 687)
292
SpriteFrame(-16, -32, 32, 64, 105, 703)
293
SpriteFrame(-16, -24, 32, 48, 105, 719)
294
SpriteFrame(-16, -16, 32, 32, 105, 735)
295
SpriteFrame(-16, -8, 32, 16, 105, 751)
296
SpriteFrame(-8, -8, 16, 16, 105, 687)
297
SpriteFrame(-8, -8, 16, 16, 105, 703)
298
SpriteFrame(-8, -8, 16, 16, 105, 719)
299
SpriteFrame(-8, -8, 16, 16, 105, 735)
300
SpriteFrame(-8, -8, 16, 16, 105, 751)
301
BreakBlock_groundOffset = -8
302
end if
303
304
temp0 = 0
305
BreakBlock_debugStartID = DebugMode_ObjCount
306
while temp0 < 5
307
SetTableValue(TypeName[Break Block], DebugMode_ObjCount, DebugMode_TypesTable)
308
SetTableValue(BreakBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
309
SetTableValue(BreakBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
310
DebugMode_ObjCount++
311
temp0++
312
loop
313
end event
314
315
316
// ========================
317
// Editor Events
318
// ========================
319
320
event RSDKEdit
321
if editor.returnVariable == true
322
switch editor.variableID
323
case EDIT_VAR_PROPVAL // property value
324
checkResult = object.propertyValue
325
break
326
327
case 0 // size
328
checkResult = object.propertyValue
329
checkResult &= 0x7F
330
break
331
332
case 1 // collisionPlane
333
GetBit(checkResult, object.propertyValue, 7)
334
break
335
336
end switch
337
else
338
switch editor.variableID
339
case EDIT_VAR_PROPVAL // property value
340
object.propertyValue = editor.variableValue
341
break
342
343
case 0 // size
344
editor.variableValue &= 0x7F
345
object.propertyValue &= 0x80
346
object.propertyValue |= temp0
347
break
348
349
case 1 // collisionPlane
350
CheckNotEqual(editor.variableValue, false)
351
SetBit(object.propertyValue, 7, checkResult)
352
break
353
354
end switch
355
end if
356
end event
357
358
359
event RSDKDraw
360
temp0 = object.propertyValue
361
temp0 &= 0x7F
362
DrawSprite(temp0)
363
end event
364
365
366
event RSDKLoad
367
CheckCurrentStageFolder("Zone05")
368
if checkResult == true
369
LoadSpriteSheet("HTZ/Objects.gif")
370
SpriteFrame(-16, -40, 32, 80, 69, 1)
371
SpriteFrame(-16, -32, 32, 64, 69, 17)
372
SpriteFrame(-16, -24, 32, 48, 69, 33)
373
SpriteFrame(-16, -16, 32, 32, 69, 49)
374
SpriteFrame(-16, -8, 32, 16, 69, 65)
375
else
376
LoadSpriteSheet("MBZ/Objects.gif")
377
SpriteFrame(-16, -40, 32, 80, 105, 687)
378
SpriteFrame(-16, -32, 32, 64, 105, 703)
379
SpriteFrame(-16, -24, 32, 48, 105, 719)
380
SpriteFrame(-16, -16, 32, 32, 105, 735)
381
SpriteFrame(-16, -8, 32, 16, 105, 751)
382
end if
383
384
AddEditorVariable("size")
385
SetActiveVariable("size")
386
AddEnumVariable("5 Blocks", 0)
387
AddEnumVariable("4 Blocks", 1)
388
AddEnumVariable("3 Blocks", 2)
389
AddEnumVariable("2 Blocks", 3)
390
AddEnumVariable("1 Block", 4)
391
392
AddEditorVariable("collisionPlane")
393
SetActiveVariable("collisionPlane")
394
AddEnumVariable("Plane A", 0)
395
AddEnumVariable("Plane B", 1)
396
end event
397
398