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/SYZ/Push Block.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Push 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.value1 : object.drawPos.x
13
private alias object.value2 : object.solidBoxL
14
private alias object.value3 : object.solidBoxR
15
private alias object.value4 : object.pushBoxL
16
private alias object.value5 : object.pushBoxR
17
private alias object.value6 : object.beingPushed
18
private alias object.value7 : object.startPos.x
19
private alias object.value8 : object.startPos.y
20
private alias object.value9 : object.pushBoundary
21
private alias object.value10 : object.activePlayers
22
23
private alias 0 : PUSHBLOCK_PUSHABLE
24
private alias 1 : PUSHBLOCK_MOVING
25
private alias 2 : PUSHBLOCK_FALLING
26
27
// Player Aliases
28
private alias object.xpos : player.xpos
29
private alias object.ypos : player.ypos
30
private alias object.ixpos : player.ixpos
31
private alias object.xvel : player.xvel
32
private alias object.speed : player.speed
33
private alias object.left : player.left
34
private alias object.right : player.right
35
private alias object.pushing : player.pushing
36
private alias object.gravity : player.gravity
37
private alias object.collisionLeft : player.collisionLeft
38
private alias object.collisionRight : player.collisionRight
39
40
// Path ID Aliases
41
private alias 0 : PATH_A
42
43
44
// ========================
45
// Function Declarations
46
// ========================
47
48
reserve function PushBlock_DebugDraw
49
reserve function PushBlock_DebugSpawn
50
reserve function PushBlock_HandlePushBounds
51
reserve function PushBlock_HandleObjectCollisions
52
reserve function PushBlock_HandleTileCollisions
53
54
55
// ========================
56
// Function Definitions
57
// ========================
58
59
private function PushBlock_DebugDraw
60
DrawSprite(0)
61
end function
62
63
64
private function PushBlock_DebugSpawn
65
CreateTempObject(TypeName[Push Block], 0, object.xpos, object.ypos)
66
object[tempObjectPos].beingPushed = false
67
68
if object[tempObjectPos].frame == 0
69
object[tempObjectPos].solidBoxL = -16
70
object[tempObjectPos].solidBoxR = 16
71
object[tempObjectPos].pushBoxL = -17
72
object[tempObjectPos].pushBoxR = 17
73
else
74
object[tempObjectPos].solidBoxL = -64
75
object[tempObjectPos].solidBoxR = 64
76
object[tempObjectPos].pushBoxL = -65
77
object[tempObjectPos].pushBoxR = 65
78
79
object[tempObjectPos].drawOrder = 5
80
end if
81
end function
82
83
84
private function PushBlock_HandlePushBounds
85
if object.floorSensorC == false
86
if object.floorSensorL == false
87
object.xvel = -0x40000
88
object.pushBoundary = object.xpos
89
object.pushBoundary &= 0xFFFF00000
90
object.state++
91
else
92
if object.floorSensorR == false
93
object.xvel = 0x40000
94
object.pushBoundary = object.xpos
95
object.pushBoundary &= 0xFFFF00000
96
object.pushBoundary += 0x100000
97
object.state++
98
end if
99
end if
100
end if
101
end function
102
103
104
private function PushBlock_HandleObjectCollisions
105
object.activePlayers = 0
106
temp2 = 0
107
object.xvel = 0
108
109
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
110
CheckEqual(options.attractMode, true)
111
temp1 = checkResult
112
CheckEqual(currentPlayer, 1)
113
temp1 &= checkResult
114
115
if player[currentPlayer].gravity == GRAVITY_GROUND
116
if player[currentPlayer].xvel < 0
117
BoxCollisionTest(C_TOUCH, object.entityPos, 0, -12, object.pushBoxR, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
118
if checkResult == true
119
if player[currentPlayer].left == true
120
if temp1 == false
121
SetBit(object.activePlayers, temp2, true)
122
object.xvel -= 0x6000
123
object.beingPushed = true
124
end if
125
end if
126
127
player[currentPlayer].xpos = player[currentPlayer].collisionRight
128
player[currentPlayer].xpos += object.solidBoxR
129
player[currentPlayer].xpos <<= 16
130
player[currentPlayer].xpos += object.drawPos.x
131
player[currentPlayer].xvel = 0
132
player[currentPlayer].speed = 0
133
player[currentPlayer].pushing = 2
134
end if
135
else
136
if player[currentPlayer].xvel > 0
137
BoxCollisionTest(C_TOUCH, object.entityPos, object.pushBoxL, -12, 0, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
138
if checkResult == true
139
if player[currentPlayer].right == true
140
if temp1 == false
141
SetBit(object.activePlayers, temp2, true)
142
object.xvel += 0x6000
143
object.beingPushed = true
144
end if
145
end if
146
147
player[currentPlayer].xpos = player[currentPlayer].collisionLeft
148
player[currentPlayer].xpos += object.solidBoxL
149
player[currentPlayer].xpos <<= 16
150
player[currentPlayer].xpos += object.drawPos.x
151
player[currentPlayer].xvel = 0
152
player[currentPlayer].speed = 0
153
player[currentPlayer].pushing = 2
154
end if
155
else
156
BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
157
end if
158
end if
159
else
160
BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
161
end if
162
163
temp2++
164
next
165
166
if object.xvel != 0
167
object.xpos += object.xvel
168
if object.xvel < 0
169
ObjectTileCollision(CSIDE_RWALL, object.solidBoxL, 0, PATH_A)
170
else
171
ObjectTileCollision(CSIDE_LWALL, object.solidBoxR, 0, PATH_A)
172
end if
173
174
if checkResult == false
175
temp0 = oscillation
176
temp0 &= 31
177
if temp0 < 3
178
PlaySfx(SfxName[Push Block], false)
179
end if
180
end if
181
182
CallFunction(PushBlock_HandlePushBounds)
183
temp0 = object.xpos
184
temp0 &= 0xFFFF0000
185
if object.drawPos.x != temp0
186
// No code? ok...
187
// (in other zones this plays the PushBlock SFX here)
188
end if
189
end if
190
191
object.drawPos.x = object.xpos
192
object.drawPos.x &= 0xFFFF0000
193
temp2 = 0
194
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
195
GetBit(temp0, object.activePlayers, temp2)
196
if temp0 == true
197
if player[currentPlayer].xpos < object.xpos
198
player[currentPlayer].ixpos = player[currentPlayer].collisionRight
199
temp1 = object.solidBoxL
200
else
201
player[currentPlayer].ixpos = player[currentPlayer].collisionLeft
202
temp1 = object.solidBoxR
203
end if
204
205
FlipSign(player[currentPlayer].xpos)
206
temp1 <<= 16
207
player[currentPlayer].xpos += temp1
208
player[currentPlayer].xpos += object.xpos
209
else
210
BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
211
end if
212
213
temp2++
214
next
215
end function
216
217
218
private function PushBlock_HandleTileCollisions
219
if object.beingPushed == true
220
if object.gravity == GRAVITY_AIR
221
object.yvel += 0x1800
222
object.ypos += object.yvel
223
temp0 = object.solidBoxL
224
temp0 += 2
225
ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)
226
object.floorSensorL = checkResult
227
object.gravity = checkResult
228
229
ObjectTileCollision(CSIDE_FLOOR, 0, 16, PATH_A)
230
object.floorSensorC = checkResult
231
object.gravity |= checkResult
232
233
temp0 = object.solidBoxR
234
temp0 -= 2
235
ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)
236
object.floorSensorR = checkResult
237
object.gravity |= checkResult
238
else
239
object.yvel = 0
240
temp0 = object.solidBoxL
241
temp0 += 2
242
ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)
243
244
object.floorSensorL = checkResult
245
object.gravity = checkResult
246
ObjectTileGrip(CSIDE_FLOOR, 0, 16, PATH_A)
247
248
object.floorSensorC = checkResult
249
object.gravity |= checkResult
250
251
temp0 = object.solidBoxR
252
temp0 -= 2
253
ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)
254
object.floorSensorR = checkResult
255
object.gravity |= checkResult
256
end if
257
object.gravity ^= 1
258
else
259
object.floorSensorL = true
260
object.floorSensorC = true
261
object.floorSensorR = true
262
end if
263
end function
264
265
266
// ========================
267
// Events
268
// ========================
269
270
event ObjectUpdate
271
temp6 = object.xpos
272
temp7 = object.ypos
273
274
switch object.state
275
case PUSHBLOCK_PUSHABLE
276
object.priority = PRIORITY_ACTIVE
277
CallFunction(PushBlock_HandleObjectCollisions)
278
CallFunction(PushBlock_HandleTileCollisions)
279
break
280
281
case PUSHBLOCK_MOVING
282
object.xpos += object.xvel
283
if object.xvel > 0
284
if object.xpos >= object.pushBoundary
285
object.xpos = object.pushBoundary
286
object.xvel = 0
287
object.gravity = GRAVITY_AIR
288
object.state = PUSHBLOCK_FALLING
289
end if
290
else
291
if object.xpos <= object.pushBoundary
292
object.xpos = object.pushBoundary
293
object.xvel = 0
294
object.gravity = GRAVITY_AIR
295
object.state = PUSHBLOCK_FALLING
296
end if
297
end if
298
break
299
300
case PUSHBLOCK_FALLING
301
CallFunction(PushBlock_HandleTileCollisions)
302
if object.gravity == GRAVITY_GROUND
303
object.state = PUSHBLOCK_PUSHABLE
304
end if
305
break
306
307
end switch
308
309
temp0 = object.xpos
310
temp1 = object.ypos
311
temp4 = object.xpos
312
temp4 &= 0xFFFF0000
313
temp5 = object.ypos
314
temp5 &= 0xFFFF0000
315
object.xpos = temp6
316
object.ypos = temp7
317
temp6 &= 0xFFFF0000
318
temp7 &= 0xFFFF0000
319
temp4 -= temp6
320
temp5 -= temp7
321
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
322
CheckNotEqual(player[currentPlayer].pushing, false)
323
temp2 = checkResult
324
CheckEqual(object.state, PUSHBLOCK_PUSHABLE)
325
temp2 &= checkResult
326
if temp2 == 0
327
BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
328
if checkResult == COL_TOP
329
player[currentPlayer].xpos += temp4
330
player[currentPlayer].ypos += temp5
331
end if
332
end if
333
next
334
object.xpos = temp0
335
object.ypos = temp1
336
337
object.drawPos.x = object.xpos
338
object.drawPos.x &= 0xFFFF0000
339
if object.outOfBounds == true
340
temp0 = object.xpos
341
temp1 = object.ypos
342
object.xpos = object.startPos.x
343
object.ypos = object.startPos.y
344
if object.outOfBounds == true
345
object.yvel = 0
346
object.beingPushed = false
347
object.priority = PRIORITY_BOUNDS
348
object.state = PUSHBLOCK_PUSHABLE
349
else
350
object.xpos = temp0
351
object.ypos = temp1
352
end if
353
end if
354
end event
355
356
357
event ObjectDraw
358
DrawSpriteXY(object.frame, object.drawPos.x, object.ypos)
359
end event
360
361
362
event ObjectStartup
363
LoadSpriteSheet("SYZ/Objects.gif")
364
SpriteFrame(-16, -16, 32, 32, 119, 34)
365
SpriteFrame(-16, -16, 32, 32, 119, 34) // Supposed to be 128x32 frame, SYZ doesn't need it though (do note, this script is copied from the MZ PushBlock script where the large variant *is* used)
366
367
foreach (TypeName[Push Block], arrayPos0, ALL_ENTITIES)
368
object[arrayPos0].frame = object[arrayPos0].propertyValue
369
object[arrayPos0].frame &= 1
370
object[arrayPos0].startPos.x = object[arrayPos0].xpos
371
object[arrayPos0].startPos.y = object[arrayPos0].ypos
372
object[arrayPos0].beingPushed = false
373
if object[arrayPos0].frame == 0
374
object[arrayPos0].solidBoxL = -16
375
object[arrayPos0].solidBoxR = 16
376
object[arrayPos0].pushBoxL = -17
377
object[arrayPos0].pushBoxR = 17
378
else
379
object[arrayPos0].solidBoxL = -64
380
object[arrayPos0].solidBoxR = 64
381
object[arrayPos0].pushBoxL = -65
382
object[arrayPos0].pushBoxR = 65
383
end if
384
next
385
386
SetTableValue(TypeName[Push Block], DebugMode_ObjCount, DebugMode_TypesTable)
387
SetTableValue(PushBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
388
SetTableValue(PushBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
389
DebugMode_ObjCount++
390
end event
391
392
393
// ========================
394
// Editor Events
395
// ========================
396
397
event RSDKEdit
398
if editor.returnVariable == true
399
switch editor.variableID
400
case EDIT_VAR_PROPVAL // property value
401
checkResult = object.propertyValue
402
checkResult &= 1
403
break
404
405
case 0 // type
406
checkResult = object.propertyValue
407
checkResult &= 1
408
break
409
410
end switch
411
else
412
switch editor.variableID
413
case EDIT_VAR_PROPVAL // property value
414
object.propertyValue = editor.variableValue
415
object.propertyValue &= 1
416
break
417
418
case 0 // type
419
object.propertyValue = editor.variableValue
420
object.propertyValue &= 1
421
break
422
423
end switch
424
end if
425
end event
426
427
428
event RSDKDraw
429
DrawSprite(0)
430
end event
431
432
433
event RSDKLoad
434
LoadSpriteSheet("SYZ/Objects.gif")
435
SpriteFrame(-16, -16, 32, 32, 119, 34)
436
SpriteFrame(-16, -16, 32, 32, 119, 34)
437
438
AddEditorVariable("frameID")
439
SetActiveVariable("frameID")
440
AddEnumVariable("Small", 0)
441
// Not used I dont think, it's meant to be a long block but the spriteFrame isn't even setup properly so...
442
// Update: its not used its a leftover from the marble zone PushBlock object LOL
443
// AddEnumVariable("Long", 1)
444
end event
445
446