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/MZ/HCrusher.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Horiz Crusher 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.crusherType // unused
14
private alias object.value2 : object.useButton
15
private alias object.value3 : object.startPos.x
16
private alias object.value4 : object.endPos.x
17
private alias object.value5 : object.collisionOffset.x
18
private alias object.value6 : object.currentPos.x
19
private alias object.value7 : object.dontPlaySfx // not really used in any substantial way
20
private alias object.value8 : object.moveVel
21
22
// States
23
private alias 0 : HORIZCRUSHER_DROPPING
24
private alias 1 : HORIZCRUSHER_DROPPED
25
private alias 2 : HORIZCRUSHER_RISING
26
private alias 3 : HORIZCRUSHER_RISEN
27
28
// Player Aliases
29
private alias object.xpos : player.xpos
30
private alias object.gravity : player.gravity
31
32
private alias object.value17 : debugMode.currentSelection
33
34
// PushButton aliases
35
private alias object.propertyValue : pushButton.stood
36
37
38
// ========================
39
// Function Declarations
40
// ========================
41
42
reserve function HorizCrusher_DebugDraw
43
reserve function HorizCrusher_DebugSpawn
44
reserve function HorizCrusher_CheckOnScreen
45
46
47
// ========================
48
// Static Values
49
// ========================
50
51
private value HorizCrusher_startDebugID = 0
52
53
54
// ========================
55
// Function Definitions
56
// ========================
57
58
private function HorizCrusher_DebugDraw
59
temp7 = debugMode[0].currentSelection
60
temp7 -= HorizCrusher_startDebugID
61
62
temp5 = object.xpos
63
switch temp7
64
case 0
65
temp6 = 0x380000
66
break
67
68
case 1
69
temp6 = 0x9F0000
70
break
71
72
case 2
73
temp6 = 0x500000
74
break
75
76
case 3
77
temp6 = 0x380000
78
break
79
80
end switch
81
82
if object.direction == FLIP_NONE
83
FlipSign(temp6)
84
end if
85
86
temp5 += temp6
87
if temp5 > object.xpos
88
temp0 = temp5
89
temp0 -= object.xpos
90
else
91
temp0 = object.xpos
92
temp0 -= temp5
93
end if
94
95
temp0 >>= 16
96
temp0 += 4
97
temp1 = 299
98
temp1 -= temp0
99
if object.direction == FLIP_X
100
temp2 = temp0
101
temp2 += 34
102
FlipSign(temp2)
103
else
104
temp2 = 16
105
end if
106
temp0 += 17
107
EditFrame(3, temp2, -8, temp0, 16, temp1, 388)
108
109
DrawSpriteXY(3, temp5, object.ypos)
110
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
111
DrawSpriteFX(1, FX_FLIP, temp5, object.ypos)
112
DrawSpriteFX(2, FX_FLIP, temp5, object.ypos)
113
end function
114
115
116
private function HorizCrusher_DebugSpawn
117
temp7 = debugMode[0].currentSelection
118
temp7 -= HorizCrusher_startDebugID
119
120
CreateTempObject(TypeName[Horiz Crusher], 0, object.xpos, object.ypos)
121
object[tempObjectPos].direction = object.direction
122
object[tempObjectPos].useButton = false
123
if object.direction == FLIP_NONE
124
object[tempObjectPos].moveVel = -0x7000
125
else
126
object[tempObjectPos].moveVel = 0x7000
127
end if
128
129
object[tempObjectPos].startPos.x = object.xpos
130
object[tempObjectPos].endPos.x = object[tempObjectPos].startPos.x
131
132
switch temp7
133
case 0
134
temp6 = 0x380000
135
break
136
137
case 1
138
temp6 = 0x9F0000
139
break
140
141
case 2
142
temp6 = 0x500000
143
break
144
145
case 3
146
temp6 = 0x380000
147
break
148
149
end switch
150
151
if object.direction == FLIP_NONE
152
FlipSign(temp6)
153
end if
154
155
object[tempObjectPos].endPos.x += temp6
156
157
if object[tempObjectPos].useButton == true // this is never true (it's set to false right above)
158
object[tempObjectPos].xpos = object[tempObjectPos].endPos.x
159
end if
160
end function
161
162
163
// Unused func
164
private function HorizCrusher_CheckOnScreen
165
checkResult = false
166
temp0 = object.ypos
167
temp0 >>= 16
168
temp0 -= camera[0].ypos
169
Abs(temp0)
170
if 64 <= screen.ycenter // huh? 64? i think that's supposed to be temp0...
171
temp1 = object.endPos.x
172
temp1 -= object.startPos.x
173
temp1 >>= 16
174
temp1 += 8
175
temp1 >>= 1
176
temp0 = object.startPos.x
177
temp0 += object.endPos.x
178
temp0 >>= 17
179
temp0 -= 12
180
temp0 -= camera[0].xpos
181
Abs(temp0)
182
temp0 -= temp1
183
temp0 -= 40
184
if temp0 <= screen.xcenter
185
checkResult = true
186
end if
187
end if
188
end function
189
190
191
// ========================
192
// Events
193
// ========================
194
195
event ObjectUpdate
196
if object.useButton == true
197
if pushButton[+1].stood == false
198
object.dontPlaySfx = false
199
object.xvel += object.moveVel
200
object.xpos += object.xvel
201
202
temp0 = false
203
if object.direction == FLIP_NONE
204
if object.xpos <= object.endPos.x
205
temp0 = true
206
end if
207
else
208
if object.xpos >= object.endPos.x
209
temp0 = true
210
end if
211
end if
212
213
if temp0 == true
214
object.xpos = object.endPos.x
215
object.xvel = 0
216
end if
217
else
218
if object.moveVel > 0
219
object.xpos -= 0x8000
220
else
221
object.xpos += 0x8000
222
end if
223
224
temp0 = false
225
if object.direction == FLIP_NONE
226
if object.xpos >= object.startPos.x
227
temp0 = true
228
end if
229
else
230
if object.xpos <= object.startPos.x
231
temp0 = true
232
end if
233
end if
234
235
if temp0 == true
236
object.xpos = object.startPos.x
237
object.xvel = 0
238
end if
239
end if
240
else
241
switch object.state
242
case HORIZCRUSHER_DROPPING
243
object.dontPlaySfx = false
244
object.xvel += object.moveVel
245
object.xpos += object.xvel
246
temp0 = false
247
if object.direction == FLIP_NONE
248
if object.xpos <= object.endPos.x
249
temp0 = true
250
end if
251
else
252
if object.xpos >= object.endPos.x
253
temp0 = true
254
end if
255
end if
256
257
if temp0 == true
258
object.xpos = object.endPos.x
259
object.xvel = 0
260
object.state++
261
end if
262
break
263
264
case HORIZCRUSHER_DROPPED
265
object.timer++
266
if object.timer == 60
267
object.timer = 0
268
if object.moveVel > 0
269
object.xvel = -0x8000
270
else
271
object.xvel = 0x8000
272
end if
273
object.state++
274
end if
275
break
276
277
case HORIZCRUSHER_RISING
278
object.xpos += object.xvel
279
temp0 = false
280
if object.direction == FLIP_NONE
281
if object.xpos >= object.startPos.x
282
temp0 = true
283
end if
284
else
285
if object.xpos <= object.startPos.x
286
temp0 = true
287
end if
288
end if
289
290
if temp0 == true
291
object.xpos = object.startPos.x
292
object.xvel = 0
293
object.state++
294
end if
295
break
296
297
case HORIZCRUSHER_RISEN
298
object.timer++
299
if object.timer == 4
300
object.timer = 0
301
object.state = HORIZCRUSHER_DROPPING
302
end if
303
break
304
305
end switch
306
end if
307
308
object.collisionOffset.x = object.xpos
309
object.collisionOffset.x &= 0xFFFF0000
310
object.collisionOffset.x -= object.currentPos.x
311
312
temp0 = object.xpos
313
object.xpos = object.currentPos.x
314
temp5 = object.collisionOffset.x
315
temp5 >>= 16
316
if object.direction == FLIP_NONE
317
temp6 = -42
318
temp6 += temp5
319
temp7 = -12
320
temp7 += temp5
321
else
322
temp6 = 12
323
temp6 += temp5
324
temp7 = 42
325
temp7 += temp5
326
end if
327
328
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
329
BoxCollisionTest(C_SOLID, object.entityPos, -12, -32, 12, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
330
switch checkResult
331
case COL_TOP
332
player[currentPlayer].xpos += object.collisionOffset.x
333
break
334
335
case COL_LEFT
336
if object.collisionOffset.x < 0
337
player[currentPlayer].xpos += object.collisionOffset.x
338
end if
339
break
340
341
case COL_RIGHT
342
if object.collisionOffset.x > 0
343
player[currentPlayer].xpos += object.collisionOffset.x
344
end if
345
break
346
347
case COL_BOTTOM
348
if player[currentPlayer].gravity == GRAVITY_GROUND
349
CallFunction(Player_Kill)
350
end if
351
break
352
353
end switch
354
355
BoxCollisionTest(C_TOUCH, object.entityPos, temp6, -24, temp7, 24, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
356
if checkResult == true
357
CallFunction(Player_Hit)
358
end if
359
next
360
361
object.xpos = temp0
362
object.currentPos.x = object.xpos
363
object.currentPos.x &= 0xFFFF0000
364
end event
365
366
367
event ObjectDraw
368
if object.xpos > object.startPos.x
369
temp0 = object.xpos
370
temp0 -= object.startPos.x
371
else
372
temp0 = object.startPos.x
373
temp0 -= object.xpos
374
end if
375
temp0 >>= 16
376
temp0 += 4
377
temp1 = 299
378
temp1 -= temp0
379
380
if object.direction == FLIP_X
381
temp2 = temp0
382
temp2 += 34
383
FlipSign(temp2)
384
else
385
temp2 = 16
386
end if
387
temp0 += 17
388
EditFrame(3, temp2, -8, temp0, 16, temp1, 388)
389
390
DrawSpriteXY(3, object.currentPos.x, object.ypos)
391
DrawSpriteFX(0, FX_FLIP, object.startPos.x, object.ypos)
392
DrawSpriteFX(1, FX_FLIP, object.currentPos.x, object.ypos)
393
DrawSpriteFX(2, FX_FLIP, object.currentPos.x, object.ypos)
394
end event
395
396
397
event ObjectStartup
398
LoadSpriteSheet("MZ/Objects.gif")
399
SpriteFrame(36, -16, 8, 32, 289, 158)
400
SpriteFrame(-12, -32, 32, 64, 256, 142)
401
SpriteFrame(-43, -24, 31, 48, 256, 207)
402
SpriteFrame(-92, -8, 184, 16, 132, 388)
403
404
foreach (TypeName[Horiz Crusher], arrayPos0, ALL_ENTITIES)
405
object[arrayPos0].useButton = object[arrayPos0].propertyValue
406
object[arrayPos0].useButton >>= 7
407
408
GetBit(object[arrayPos0].direction, object[arrayPos0].propertyValue, 6)
409
410
// Bug Details:
411
// Right-facing crushers should have a positive velocity value, but this startup code gives a negative vel to *all* crushers, not just left-facing ones
412
// This object isn't normally placed in any scenes, though, so it doesn't matter too much (and the debug spawn code gives the correct vels too, it's only here where it's wrong)
413
object[arrayPos0].moveVel = -0x7000
414
415
object[arrayPos0].state = object[arrayPos0].propertyValue
416
object[arrayPos0].state &= 3
417
418
object[arrayPos0].startPos.x = object[arrayPos0].xpos
419
object[arrayPos0].endPos.x = object[arrayPos0].startPos.x
420
switch object[arrayPos0].state
421
case HORIZCRUSHER_DROPPING
422
temp0 = 0x380000
423
break
424
425
case HORIZCRUSHER_DROPPED
426
temp0 = 0x9F0000
427
break
428
429
case HORIZCRUSHER_RISING
430
temp0 = 0x500000
431
break
432
433
case HORIZCRUSHER_RISEN
434
temp0 = 0x380000
435
break
436
437
end switch
438
439
if object[arrayPos0].direction == FLIP_NONE
440
FlipSign(temp0)
441
end if
442
443
object[arrayPos0].endPos.x += temp0
444
445
if object[arrayPos0].useButton == true
446
object[arrayPos0].xpos = object[arrayPos0].endPos.x
447
end if
448
next
449
450
temp0 = 0
451
HorizCrusher_startDebugID = DebugMode_ObjCount
452
while temp0 < 4
453
SetTableValue(TypeName[Horiz Crusher], DebugMode_ObjCount, DebugMode_TypesTable)
454
SetTableValue(HorizCrusher_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
455
SetTableValue(HorizCrusher_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
456
DebugMode_ObjCount++
457
temp0++
458
loop
459
end event
460
461
462
// ========================
463
// Editor Events
464
// ========================
465
466
event RSDKEdit
467
if editor.returnVariable == true
468
switch editor.variableID
469
case EDIT_VAR_PROPVAL // property value
470
checkResult = object.propertyValue
471
break
472
473
case 0 // useButton
474
GetBit(checkResult, object.propertyValue, 7)
475
break
476
477
case 1 // direction
478
GetBit(checkResult, object.propertyValue, 6)
479
break
480
481
case 2 // type
482
checkResult = object.propertyValue
483
checkResult &= 3
484
break
485
486
end switch
487
else
488
switch editor.variableID
489
case EDIT_VAR_PROPVAL // property value
490
object.propertyValue = editor.variableValue
491
break
492
493
case 0 // useButton
494
CheckNotEqual(editor.variableValue, false)
495
SetBit(object.propertyValue, 7, checkResult)
496
break
497
498
case 1 // direction
499
CheckNotEqual(editor.variableValue, false)
500
SetBit(object.propertyValue, 6, checkResult)
501
break
502
503
case 2 // type
504
temp1 = 3
505
Not(temp1)
506
object.propertyValue &= temp1
507
508
temp0 = editor.variableValue
509
temp0 &= 3
510
object.propertyValue |= temp0
511
break
512
513
end switch
514
end if
515
end event
516
517
518
event RSDKDraw
519
GetBit(object.useButton, object.propertyValue, 7)
520
521
GetBit(object.direction, object.propertyValue, 6)
522
523
object.startPos.x = object.xpos
524
object.endPos.x = object.startPos.x
525
526
object.state = object.propertyValue
527
object.state &= 3
528
529
switch object.state
530
case HORIZCRUSHER_DROPPING
531
case HORIZCRUSHER_RISEN
532
object.endPos.x += 0x380000
533
break
534
535
case HORIZCRUSHER_DROPPED
536
object.endPos.x += 0x9F0000
537
break
538
539
case HORIZCRUSHER_RISING
540
object.endPos.x += 0x500000
541
break
542
543
end switch
544
object.currentPos.x = object.xpos
545
object.currentPos.x &= 0xFFFF0000
546
547
if object.xpos > object.startPos.x
548
temp0 = object.xpos
549
temp0 -= object.startPos.x
550
else
551
temp0 = object.startPos.x
552
temp0 -= object.xpos
553
end if
554
temp0 >>= 16
555
temp0 += 4
556
temp1 = 299
557
temp1 -= temp0
558
559
if object.direction == FLIP_X
560
temp2 = temp0
561
temp2 += 34
562
FlipSign(temp2)
563
else
564
temp2 = 16
565
end if
566
temp0 += 17
567
EditFrame(3, temp2, -8, temp0, 16, temp1, 388)
568
569
DrawSpriteXY(3, object.currentPos.x, object.ypos)
570
DrawSpriteFX(0, FX_FLIP, object.startPos.x, object.ypos)
571
DrawSpriteFX(1, FX_FLIP, object.currentPos.x, object.ypos)
572
DrawSpriteFX(2, FX_FLIP, object.currentPos.x, object.ypos)
573
end event
574
575
576
event RSDKLoad
577
LoadSpriteSheet("MZ/Objects.gif")
578
SpriteFrame(36, -16, 8, 32, 289, 158)
579
SpriteFrame(-12, -32, 32, 64, 256, 142)
580
SpriteFrame(-43, -24, 31, 48, 256, 207)
581
SpriteFrame(-92, -8, 184, 16, 132, 388)
582
583
AddEditorVariable("useButton")
584
SetActiveVariable("useButton")
585
AddEnumVariable("false", false)
586
AddEnumVariable("true", true)
587
588
AddEditorVariable("direction")
589
SetActiveVariable("direction")
590
AddEnumVariable("Left", 0)
591
AddEnumVariable("Right", 1)
592
593
AddEditorVariable("length")
594
SetActiveVariable("length")
595
AddEnumVariable("56 Pixels", 0)
596
AddEnumVariable("159 Pixels", 1)
597
AddEnumVariable("80 Pixels", 2)
598
AddEnumVariable("56 Pixels (Use Button)", 3)
599
end event
600
601