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