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/MCZ/MovingCrates.txt
1482 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Moving Crates Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
// Each box is pretty much its own mini-object
13
// Note: positions are relative values to the base object's position
14
15
// This object got a major rewrite in Origins Plus, likely to prevent the crush death bug from happening with it
16
// (It should be noted they did not actually fix the root cause of the bug LOL)
17
// For the sake of preservation, both the original and Origins Plus versions of the object are included here
18
19
// Standalone Aliases
20
private alias object.value15 : object.box1.state
21
private alias object.value1 : object.box1.x
22
private alias object.value2 : object.box1.y
23
private alias object.value7 : object.box1.xvel
24
private alias object.value8 : object.box1.yvel
25
private alias object.value18 : object.box1.crushTimer
26
27
private alias object.value16 : object.box2.state
28
private alias object.value3 : object.box2.x
29
private alias object.value4 : object.box2.y
30
private alias object.value9 : object.box2.xvel
31
private alias object.value10 : object.box2.yvel
32
private alias object.value19 : object.box2.crushTimer
33
34
private alias object.value17 : object.box3.state
35
private alias object.value5 : object.box3.x
36
private alias object.value6 : object.box3.y
37
private alias object.value11 : object.box3.xvel
38
private alias object.value12 : object.box3.yvel
39
private alias object.value20 : object.box3.crushTimer
40
41
// Origins Plus Aliases
42
private alias object.value30 : object.boxUpdate
43
private alias object.value31 : object.box.x.store
44
private alias object.value32 : object.box.y.store
45
private alias object.value33 : object.box.xvel.store
46
private alias object.value34 : object.box.yvel.store
47
private alias object.value35 : object.box.state.store
48
private alias object.value36 : object.box.crushTimer.store
49
private alias object.value37 : object.xpos.store
50
private alias object.value38 : object.ypos.store
51
52
// values 13 and 14 are unused
53
54
// Object states
55
// Clockwise and counter-clockwise versions have separate states
56
private alias 0 : MOVINGCRATE_CW_RIGHT
57
private alias 1 : MOVINGCRATE_CW_DOWN
58
private alias 2 : MOVINGCRATE_CW_LEFT
59
private alias 3 : MOVINGCRATE_CW_UP
60
61
private alias 4 : MOVINGCRATE_CCW_LEFT
62
private alias 5 : MOVINGCRATE_CCW_DOWN
63
private alias 6 : MOVINGCRATE_CCW_RIGHT
64
private alias 7 : MOVINGCRATE_CCW_UP
65
66
// Crate Numbers
67
private alias 1 : MOVINGCRATE_1
68
private alias 2 : MOVINGCRATE_2
69
private alias 3 : MOVINGCRATE_3
70
71
// Player Aliases
72
private alias object.state : player.state
73
private alias object.xpos : player.xpos
74
private alias object.ypos : player.ypos
75
private alias object.gravity : player.gravity
76
private alias object.animation : player.animation
77
private alias object.value1 : player.timer
78
79
80
// ========================
81
// Function Declarations
82
// ========================
83
84
reserve function MovingCrates_DebugDraw
85
reserve function MovingCrates_DebugSpawn
86
87
reserve function MovingCrates_UpdateCrate1
88
reserve function MovingCrates_UpdateCrate2
89
reserve function MovingCrates_UpdateCrate3
90
91
92
// ========================
93
// Function Definitions
94
// ========================
95
96
private function MovingCrates_DebugDraw
97
// Only draw the first box
98
DrawSprite(0)
99
end function
100
101
102
private function MovingCrates_DebugSpawn
103
// Spawn a Moving Crates object and init its values for the three crates
104
CreateTempObject(TypeName[Moving Crates], 0, object.xpos, object.ypos)
105
if object.direction == FLIP_NONE
106
// Clockwise rotating version
107
object[tempObjectPos].box1.x = 0x000000
108
object[tempObjectPos].box1.y = 0x000000
109
object[tempObjectPos].box1.xvel = 0x10000
110
object[tempObjectPos].box1.yvel = 0x00000
111
112
object[tempObjectPos].box2.x = 0x400000
113
object[tempObjectPos].box2.y = 0x400000
114
object[tempObjectPos].box2.xvel = -0x10000
115
object[tempObjectPos].box2.yvel = 0x00000
116
117
object[tempObjectPos].box3.x = -0x400000
118
object[tempObjectPos].box3.y = 0x400000
119
object[tempObjectPos].box3.xvel = 0x00000
120
object[tempObjectPos].box3.yvel = -0x10000
121
122
object[tempObjectPos].box1.state = MOVINGCRATE_CW_RIGHT
123
object[tempObjectPos].box2.state = MOVINGCRATE_CW_LEFT
124
object[tempObjectPos].box3.state = MOVINGCRATE_CW_UP
125
else
126
// Counter-clockwise rotating version
127
object[tempObjectPos].box1.x = 0x000000
128
object[tempObjectPos].box1.y = 0x000000
129
object[tempObjectPos].box1.xvel = -0x10000
130
object[tempObjectPos].box1.yvel = 0x00000
131
132
object[tempObjectPos].box2.x = 0x400000
133
object[tempObjectPos].box2.y = 0x400000
134
object[tempObjectPos].box2.xvel = 0x00000
135
object[tempObjectPos].box2.yvel = -0x10000
136
137
object[tempObjectPos].box3.x = -0x400000
138
object[tempObjectPos].box3.y = 0x400000
139
object[tempObjectPos].box3.xvel = 0x10000
140
object[tempObjectPos].box3.yvel = 0x00000
141
142
object[tempObjectPos].box1.state = MOVINGCRATE_CCW_LEFT
143
object[tempObjectPos].box2.state = MOVINGCRATE_CCW_UP
144
object[tempObjectPos].box3.state = MOVINGCRATE_CCW_RIGHT
145
end if
146
end function
147
148
149
private function MovingCrates_UpdateCrate1
150
#platform: USE_STANDALONE
151
temp0 = object.xpos
152
temp1 = object.ypos
153
object.xpos += object.box1.x
154
object.ypos += object.box1.y
155
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
156
BoxCollisionTest(C_SOLID, object.entityPos, -32, -32, 32, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
157
switch checkResult
158
case COL_TOP
159
player[currentPlayer].xpos += object.box1.xvel
160
player[currentPlayer].ypos += object.box1.yvel
161
break
162
163
case COL_LEFT
164
case COL_RIGHT
165
// If the player attempts to climb on these, block them from doing so and make them drop off
166
if player[currentPlayer].state == Player_State_Climb
167
player[currentPlayer].timer = 0
168
player[currentPlayer].animation = ANI_GLIDING_DROP
169
player[currentPlayer].state = Player_State_GlideDrop
170
end if
171
break
172
173
case COL_BOTTOM
174
if player[currentPlayer].gravity == GRAVITY_GROUND
175
if object.box1.yvel > 0
176
object.box1.crushTimer++
177
if object.box1.crushTimer > 9
178
CallFunction(Player_Kill)
179
end if
180
end if
181
end if
182
break
183
end switch
184
next
185
186
object.xpos = temp0
187
object.ypos = temp1
188
object.box1.x += object.box1.xvel
189
object.box1.y += object.box1.yvel
190
switch object.box1.state
191
case MOVINGCRATE_CW_RIGHT
192
if object.box1.x >= 0x400000
193
object.box1.state++
194
object.box1.x = 0x400000
195
object.box1.xvel = 0
196
object.box1.yvel = 0x10000
197
end if
198
break
199
200
case MOVINGCRATE_CW_DOWN
201
if object.box1.y >= 0x400000
202
object.box1.state++
203
object.box1.y = 0x400000
204
object.box1.xvel = -0x10000
205
object.box1.yvel = 0
206
end if
207
break
208
209
case MOVINGCRATE_CW_LEFT
210
if object.box1.x <= -0x400000
211
object.box1.state++
212
object.box1.x = -0x400000
213
object.box1.xvel = 0
214
object.box1.yvel = -0x10000
215
end if
216
break
217
218
case MOVINGCRATE_CW_UP
219
if object.box1.y <= 0
220
object.box1.state = MOVINGCRATE_CW_RIGHT
221
object.box1.y = 0
222
object.box1.xvel = 0x10000
223
object.box1.yvel = 0
224
object.box1.crushTimer = 0
225
end if
226
break
227
228
// Counter-clockwise states
229
230
case MOVINGCRATE_CCW_LEFT
231
if object.box1.x <= -0x400000
232
object.box1.state++
233
object.box1.x = -0x400000
234
object.box1.xvel = 0
235
object.box1.yvel = 0x10000
236
end if
237
break
238
239
case MOVINGCRATE_CCW_DOWN
240
if object.box1.y >= 0x400000
241
object.box1.state++
242
object.box1.y = 0x400000
243
object.box1.xvel = 0x10000
244
object.box1.yvel = 0
245
end if
246
break
247
248
case MOVINGCRATE_CCW_RIGHT
249
if object.box1.x >= 0x400000
250
object.box1.state++
251
object.box1.x = 0x400000
252
object.box1.xvel = 0
253
object.box1.yvel = -0x10000
254
end if
255
break
256
257
case MOVINGCRATE_CCW_UP
258
if object.box1.y <= 0
259
object.box1.state = MOVINGCRATE_CCW_LEFT
260
object.box1.y = 0
261
object.box1.xvel = -0x10000
262
object.box1.yvel = 0
263
object.box1.crushTimer = 0
264
end if
265
break
266
end switch
267
#endplatform
268
269
#platform: USE_ORIGINS
270
switch object.boxUpdate
271
case MOVINGCRATE_1
272
object.box.x.store = object.box1.x
273
object.box.y.store = object.box1.y
274
object.box.xvel.store = object.box1.xvel
275
object.box.yvel.store = object.box1.yvel
276
object.box.state.store = object.box1.state
277
object.box.crushTimer.store = object.box1.crushTimer
278
break
279
280
case MOVINGCRATE_2
281
object.box.x.store = object.box2.x
282
object.box.y.store = object.box2.y
283
object.box.xvel.store = object.box2.xvel
284
object.box.yvel.store = object.box2.yvel
285
object.box.state.store = object.box2.state
286
object.box.crushTimer.store = object.box2.crushTimer
287
break
288
289
case MOVINGCRATE_3
290
object.box.x.store = object.box3.x
291
object.box.y.store = object.box3.y
292
object.box.xvel.store = object.box3.xvel
293
object.box.yvel.store = object.box3.yvel
294
object.box.state.store = object.box3.state
295
object.box.crushTimer.store = object.box3.crushTimer
296
break
297
end switch
298
#endplatform
299
end function
300
301
302
private function MovingCrates_UpdateCrate2
303
#platform: USE_STANDALONE
304
temp0 = object.xpos
305
temp1 = object.ypos
306
object.xpos += object.box2.x
307
object.ypos += object.box2.y
308
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
309
BoxCollisionTest(C_SOLID, object.entityPos, -32, -32, 32, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
310
switch checkResult
311
case COL_TOP
312
player[currentPlayer].xpos += object.box2.xvel
313
player[currentPlayer].ypos += object.box2.yvel
314
break
315
316
case COL_LEFT
317
case COL_RIGHT
318
// If the player attempts to climb on these, block them from doing so and make them drop off
319
if player[currentPlayer].state == Player_State_Climb
320
player[currentPlayer].timer = 0
321
player[currentPlayer].animation = ANI_GLIDING_DROP
322
player[currentPlayer].state = Player_State_GlideDrop
323
end if
324
break
325
326
case COL_BOTTOM
327
if player[currentPlayer].gravity == GRAVITY_GROUND
328
if object.box2.yvel > 0
329
object.box2.crushTimer++
330
if object.box2.crushTimer > 9
331
CallFunction(Player_Kill)
332
end if
333
end if
334
end if
335
break
336
end switch
337
next
338
339
object.xpos = temp0
340
object.ypos = temp1
341
object.box2.x += object.box2.xvel
342
object.box2.y += object.box2.yvel
343
switch object.box2.state
344
case MOVINGCRATE_CW_RIGHT
345
if object.box2.x >= 0x400000
346
object.box2.state++
347
object.box2.x = 0x400000
348
object.box2.xvel = 0
349
object.box2.yvel = 0x10000
350
end if
351
break
352
353
case MOVINGCRATE_CW_DOWN
354
if object.box2.y >= 0x400000
355
object.box2.state++
356
object.box2.y = 0x400000
357
object.box2.xvel = -0x10000
358
object.box2.yvel = 0
359
end if
360
break
361
362
case MOVINGCRATE_CW_LEFT
363
if object.box2.x <= -0x400000
364
object.box2.state++
365
object.box2.x = -0x400000
366
object.box2.xvel = 0
367
object.box2.yvel = -0x10000
368
end if
369
break
370
371
case MOVINGCRATE_CW_UP
372
if object.box2.y <= 0
373
object.box2.state = MOVINGCRATE_CW_RIGHT
374
object.box2.y = 0
375
object.box2.xvel = 0x10000
376
object.box2.yvel = 0
377
object.box2.crushTimer = 0
378
end if
379
break
380
381
// Counter-clockwise states
382
383
case MOVINGCRATE_CCW_LEFT
384
if object.box2.x <= -0x400000
385
object.box2.state++
386
object.box2.x = -0x400000
387
object.box2.xvel = 0
388
object.box2.yvel = 0x10000
389
end if
390
break
391
392
case MOVINGCRATE_CCW_DOWN
393
if object.box2.y >= 0x400000
394
object.box2.state++
395
object.box2.y = 0x400000
396
object.box2.xvel = 0x10000
397
object.box2.yvel = 0
398
end if
399
break
400
401
case MOVINGCRATE_CCW_RIGHT
402
if object.box2.x >= 0x400000
403
object.box2.state++
404
object.box2.x = 0x400000
405
object.box2.xvel = 0
406
object.box2.yvel = -0x10000
407
end if
408
break
409
410
case MOVINGCRATE_CCW_UP
411
if object.box2.y <= 0
412
object.box2.state = MOVINGCRATE_CCW_LEFT
413
object.box2.y = 0
414
object.box2.xvel = -0x10000
415
object.box2.yvel = 0
416
object.box2.crushTimer = 0
417
end if
418
break
419
end switch
420
#endplatform
421
422
#platform: USE_ORIGINS
423
switch object.boxUpdate
424
case MOVINGCRATE_1
425
object.box1.x = object.box.x.store
426
object.box1.y = object.box.y.store
427
object.box1.xvel = object.box.xvel.store
428
object.box1.yvel = object.box.yvel.store
429
object.box1.state = object.box.state.store
430
object.box1.crushTimer = object.box.crushTimer.store
431
break
432
433
case MOVINGCRATE_2
434
object.box2.x = object.box.x.store
435
object.box2.y = object.box.y.store
436
object.box2.xvel = object.box.xvel.store
437
object.box2.yvel = object.box.yvel.store
438
object.box2.state = object.box.state.store
439
object.box2.crushTimer = object.box.crushTimer.store
440
break
441
442
case MOVINGCRATE_3
443
object.box3.x = object.box.x.store
444
object.box3.y = object.box.y.store
445
object.box3.xvel = object.box.xvel.store
446
object.box3.yvel = object.box.yvel.store
447
object.box3.state = object.box.state.store
448
object.box3.crushTimer = object.box.crushTimer.store
449
break
450
end switch
451
#endplatform
452
end function
453
454
455
private function MovingCrates_UpdateCrate3
456
#platform: USE_STANDALONE
457
temp0 = object.xpos
458
temp1 = object.ypos
459
object.xpos += object.box3.x
460
object.ypos += object.box3.y
461
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
462
BoxCollisionTest(C_SOLID, object.entityPos, -32, -32, 32, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
463
switch checkResult
464
case COL_TOP
465
player[currentPlayer].xpos += object.box3.xvel
466
player[currentPlayer].ypos += object.box3.yvel
467
break
468
469
case COL_LEFT
470
case COL_RIGHT
471
// If the player attempts to climb on these, block them from doing so and make them drop off
472
if player[currentPlayer].state == Player_State_Climb
473
player[currentPlayer].timer = 0
474
player[currentPlayer].animation = ANI_GLIDING_DROP
475
player[currentPlayer].state = Player_State_GlideDrop
476
end if
477
break
478
479
case COL_BOTTOM
480
if player[currentPlayer].gravity == GRAVITY_GROUND
481
if object.box3.yvel > 0
482
object.box3.crushTimer++
483
if object.box3.crushTimer > 9
484
CallFunction(Player_Kill)
485
end if
486
end if
487
end if
488
break
489
end switch
490
next
491
492
object.xpos = temp0
493
object.ypos = temp1
494
object.box3.x += object.box3.xvel
495
object.box3.y += object.box3.yvel
496
switch object.box3.state
497
case MOVINGCRATE_CW_RIGHT
498
if object.box3.x >= 0x400000
499
object.box3.state++
500
object.box3.x = 0x400000
501
object.box3.xvel = 0
502
object.box3.yvel = 0x10000
503
end if
504
break
505
506
case MOVINGCRATE_CW_DOWN
507
if object.box3.y >= 0x400000
508
object.box3.state++
509
object.box3.y = 0x400000
510
object.box3.xvel = -0x10000
511
object.box3.yvel = 0
512
end if
513
break
514
515
case MOVINGCRATE_CW_LEFT
516
if object.box3.x <= -0x400000
517
object.box3.state++
518
object.box3.x = -0x400000
519
object.box3.xvel = 0
520
object.box3.yvel = -0x10000
521
end if
522
break
523
524
case MOVINGCRATE_CW_UP
525
if object.box3.y <= 0
526
object.box3.state = MOVINGCRATE_CW_RIGHT
527
object.box3.y = 0
528
object.box3.xvel = 0x10000
529
object.box3.yvel = 0
530
object.box3.crushTimer = 0
531
end if
532
break
533
534
// Counter-clockwise states
535
536
case MOVINGCRATE_CCW_LEFT
537
if object.box3.x <= -0x400000
538
object.box3.state++
539
object.box3.x = -0x400000
540
object.box3.xvel = 0
541
object.box3.yvel = 0x10000
542
end if
543
break
544
545
case MOVINGCRATE_CCW_DOWN
546
if object.box3.y >= 0x400000
547
object.box3.state++
548
object.box3.y = 0x400000
549
object.box3.xvel = 0x10000
550
object.box3.yvel = 0
551
end if
552
break
553
554
case MOVINGCRATE_CCW_RIGHT
555
if object.box3.x >= 0x400000
556
object.box3.state++
557
object.box3.x = 0x400000
558
object.box3.xvel = 0
559
object.box3.yvel = -0x10000
560
end if
561
break
562
563
case MOVINGCRATE_CCW_UP
564
if object.box3.y <= 0
565
object.box3.state = MOVINGCRATE_CCW_LEFT
566
object.box3.y = 0
567
object.box3.xvel = -0x10000
568
object.box3.yvel = 0
569
object.box3.crushTimer = 0
570
end if
571
break
572
end switch
573
#endplatform
574
575
#platform: USE_ORIGINS
576
CallFunction(MovingCrates_UpdateCrate1)
577
object.xpos.store = object.xpos
578
object.ypos.store = object.ypos
579
object.xpos += object.box.x.store
580
object.ypos += object.box.y.store
581
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
582
BoxCollisionTest(C_SOLID, object.entityPos, -32, -32, 32, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
583
switch checkResult
584
case COL_TOP
585
player[currentPlayer].xpos += object.box.xvel.store
586
player[currentPlayer].ypos += object.box.yvel.store
587
break
588
589
case COL_LEFT
590
case COL_RIGHT
591
// If the player attempts to climb on these, block them from doing so and make them drop off
592
if player[currentPlayer].state == Player_State_Climb
593
player[currentPlayer].timer = 0
594
player[currentPlayer].animation = ANI_GLIDING_DROP
595
player[currentPlayer].state = Player_State_GlideDrop
596
end if
597
break
598
599
case COL_BOTTOM
600
if player[currentPlayer].gravity == GRAVITY_GROUND
601
if object.box.yvel.store > 0
602
object.box.crushTimer.store++
603
if object.box.crushTimer.store > 9
604
CallFunction(Player_Kill)
605
end if
606
end if
607
end if
608
break
609
end switch
610
next
611
612
object.xpos = object.xpos.store
613
object.ypos = object.ypos.store
614
object.box.x.store += object.box.xvel.store
615
object.box.y.store += object.box.yvel.store
616
switch object.box.state.store
617
case MOVINGCRATE_CW_RIGHT
618
if object.box.x.store >= 0x400000
619
object.box.state.store++
620
object.box.x.store = 0x400000
621
object.box.xvel.store = 0
622
object.box.yvel.store = 0x10000
623
end if
624
break
625
626
case MOVINGCRATE_CW_DOWN
627
if object.box.y.store >= 0x400000
628
object.box.state.store++
629
object.box.y.store = 0x400000
630
object.box.xvel.store = -0x10000
631
object.box.yvel.store = 0
632
end if
633
break
634
635
case MOVINGCRATE_CW_LEFT
636
if object.box.x.store <= -0x400000
637
object.box.state.store++
638
object.box.x.store = -0x400000
639
object.box.xvel.store = 0
640
object.box.yvel.store = -0x10000
641
end if
642
break
643
644
case MOVINGCRATE_CW_UP
645
if object.box.y.store <= 0
646
object.box.state.store = 0
647
object.box.y.store = 0
648
object.box.xvel.store = 0x10000
649
object.box.yvel.store = 0
650
object.box.crushTimer.store = 0
651
end if
652
break
653
654
// Counter-clockwise states
655
656
case MOVINGCRATE_CCW_LEFT
657
if object.box.x.store <= -0x400000
658
object.box.state.store++
659
object.box.x.store = -0x400000
660
object.box.xvel.store = 0
661
object.box.yvel.store = 0x10000
662
end if
663
break
664
665
case MOVINGCRATE_CCW_DOWN
666
if object.box.y.store >= 0x400000
667
object.box.state.store++
668
object.box.y.store = 0x400000
669
object.box.xvel.store = 0x10000
670
object.box.yvel.store = 0
671
end if
672
break
673
674
case MOVINGCRATE_CCW_RIGHT
675
if object.box.x.store >= 0x400000
676
object.box.state.store++
677
object.box.x.store = 0x400000
678
object.box.xvel.store = 0
679
object.box.yvel.store = -0x10000
680
end if
681
break
682
683
case MOVINGCRATE_CCW_UP
684
if object.box.y.store <= 0
685
object.box.state.store = 4
686
object.box.y.store = 0
687
object.box.xvel.store = -0x10000
688
object.box.yvel.store = 0
689
object.box.crushTimer.store = 0
690
end if
691
break
692
end switch
693
694
CallFunction(MovingCrates_UpdateCrate2)
695
#endplatform
696
end function
697
698
699
// ========================
700
// Events
701
// ========================
702
703
event ObjectUpdate
704
#platform: USE_STANDALONE
705
// Update the three crates individually
706
// These are all the same function, just using different variables
707
// If it existed at the time Get/SetObjectValue could've been used in a cool way here, but alas Sonic 2 was created in a pre-GetObjectValue world.
708
CallFunction(MovingCrates_UpdateCrate1)
709
CallFunction(MovingCrates_UpdateCrate2)
710
CallFunction(MovingCrates_UpdateCrate3)
711
#endplatform
712
713
#platform: USE_ORIGINS
714
object.boxUpdate = 1
715
while object.boxUpdate <= 3
716
CallFunction(MovingCrates_UpdateCrate3)
717
object.boxUpdate++
718
loop
719
#endplatform
720
end event
721
722
723
event ObjectDraw
724
// Draw box 1
725
temp0 = object.xpos
726
temp1 = object.ypos
727
temp0 += object.box1.x
728
temp1 += object.box1.y
729
DrawSpriteXY(0, temp0, temp1)
730
731
// Then box 2
732
temp0 = object.xpos
733
temp1 = object.ypos
734
temp0 += object.box2.x
735
temp1 += object.box2.y
736
DrawSpriteXY(0, temp0, temp1)
737
738
// And finally, box 3
739
temp0 = object.xpos
740
temp1 = object.ypos
741
temp0 += object.box3.x
742
temp1 += object.box3.y
743
DrawSpriteXY(0, temp0, temp1)
744
end event
745
746
747
event ObjectStartup
748
CheckCurrentStageFolder("Zone06")
749
if checkResult == true
750
LoadSpriteSheet("MCZ/Objects.gif")
751
SpriteFrame(-32, -32, 64, 64, 136, 1)
752
else
753
LoadSpriteSheet("MBZ/Objects.gif")
754
SpriteFrame(-32, -32, 64, 64, 797, 697)
755
end if
756
757
// Initialise all Moving Crates
758
foreach (TypeName[Moving Crates], arrayPos0, ALL_ENTITIES)
759
if object[arrayPos0].propertyValue == 0
760
// Clockwise rotating version
761
762
object[arrayPos0].box1.x = 0x000000
763
object[arrayPos0].box1.y = 0x000000
764
object[arrayPos0].box1.xvel = 0x10000
765
object[arrayPos0].box1.yvel = 0x00000
766
767
object[arrayPos0].box2.x = 0x400000
768
object[arrayPos0].box2.y = 0x400000
769
object[arrayPos0].box2.xvel = -0x10000
770
object[arrayPos0].box2.yvel = 0x00000
771
772
object[arrayPos0].box3.x = -0x400000
773
object[arrayPos0].box3.y = 0x400000
774
object[arrayPos0].box3.xvel = 0x00000
775
object[arrayPos0].box3.yvel = -0x10000
776
777
object[arrayPos0].box1.state = MOVINGCRATE_CW_RIGHT
778
object[arrayPos0].box2.state = MOVINGCRATE_CW_LEFT
779
object[arrayPos0].box3.state = MOVINGCRATE_CW_UP
780
else
781
// Counter-clockwise rotating version
782
783
object[arrayPos0].box1.x = 0x000000
784
object[arrayPos0].box1.y = 0x000000
785
object[arrayPos0].box1.xvel = -0x10000
786
object[arrayPos0].box1.yvel = 0x00000
787
788
object[arrayPos0].box2.x = 0x400000
789
object[arrayPos0].box2.y = 0x400000
790
object[arrayPos0].box2.xvel = 0x00000
791
object[arrayPos0].box2.yvel = -0x10000
792
793
object[arrayPos0].box3.x = -0x400000
794
object[arrayPos0].box3.y = 0x400000
795
object[arrayPos0].box3.xvel = 0x10000
796
object[arrayPos0].box3.yvel = 0x00000
797
798
object[arrayPos0].box1.state = MOVINGCRATE_CCW_LEFT
799
object[arrayPos0].box2.state = MOVINGCRATE_CCW_UP
800
object[arrayPos0].box3.state = MOVINGCRATE_CCW_RIGHT
801
end if
802
next
803
804
SetTableValue(TypeName[Moving Crates], DebugMode_ObjCount, DebugMode_TypesTable)
805
SetTableValue(MovingCrates_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
806
SetTableValue(MovingCrates_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
807
DebugMode_ObjCount++
808
end event
809
810
811
// ========================
812
// Editor Events
813
// ========================
814
815
event RSDKEdit
816
if editor.returnVariable == true
817
switch editor.variableID
818
case EDIT_VAR_PROPVAL // property value
819
checkResult = object.propertyValue
820
break
821
822
case 0 // rotateDir
823
checkResult = object.propertyValue
824
break
825
826
end switch
827
else
828
switch editor.variableID
829
case EDIT_VAR_PROPVAL // property value
830
object.propertyValue = editor.variableValue
831
break
832
833
case 0 // rotateDir
834
object.propertyValue = editor.variableValue
835
break
836
837
end switch
838
end if
839
end event
840
841
842
event RSDKDraw
843
// Draw box 1
844
temp0 = object.xpos
845
temp1 = object.ypos
846
temp0 += 0x000000 // object.box1.x
847
temp1 += 0x000000 // object.box1.y
848
DrawSpriteXY(0, temp0, temp1)
849
850
// Then box 2
851
temp0 = object.xpos
852
temp1 = object.ypos
853
temp0 += 0x400000 // object.box2.x
854
temp1 += 0x400000 // object.box2.y
855
DrawSpriteXY(0, temp0, temp1)
856
857
// And finally, box 3
858
temp0 = object.xpos
859
temp1 = object.ypos
860
temp0 -= 0x400000 // object.box3.x
861
temp1 += 0x400000 // object.box3.y
862
DrawSpriteXY(0, temp0, temp1)
863
864
if editor.showGizmos == true
865
// Draw arrows to show movement direction
866
if object.propertyValue == 0
867
// Clockwise
868
temp0 = object.xpos
869
temp1 = object.ypos
870
temp0 += 0x000000 // object.box1.x
871
temp1 += 0x000000 // object.box1.y
872
temp2 = temp0
873
temp2 += 0x400000 // To the right
874
DrawArrow(temp0, temp1, temp2, temp1, 0xFF, 0xFF, 0xFF)
875
876
temp0 = object.xpos
877
temp1 = object.ypos
878
temp0 += 0x400000 // object.box2.x
879
temp1 += 0x400000 // object.box2.y
880
temp2 = temp0
881
temp2 -= 0x400000 // To the left
882
DrawArrow(temp0, temp1, temp2, temp1, 0xFF, 0xFF, 0xFF)
883
884
temp0 = object.xpos
885
temp1 = object.ypos
886
temp0 -= 0x400000 // object.box3.x
887
temp1 += 0x400000 // object.box3.y
888
temp2 = temp1
889
temp2 -= 0x400000 // Upwards
890
DrawArrow(temp0, temp1, temp0, temp2, 0xFF, 0xFF, 0xFF)
891
break
892
else
893
// CCW
894
temp0 = object.xpos
895
temp1 = object.ypos
896
temp0 += 0x000000 // object.box1.x
897
temp1 += 0x000000 // object.box1.y
898
temp2 = temp0
899
temp2 -= 0x400000 // To the left
900
DrawArrow(temp0, temp1, temp2, temp1, 0xFF, 0xFF, 0xFF)
901
902
temp0 = object.xpos
903
temp1 = object.ypos
904
temp0 += 0x400000 // object.box2.x
905
temp1 += 0x400000 // object.box2.y
906
temp2 = temp1
907
temp2 -= 0x400000 // Upwards
908
DrawArrow(temp0, temp1, temp0, temp2, 0xFF, 0xFF, 0xFF)
909
910
temp0 = object.xpos
911
temp1 = object.ypos
912
temp0 -= 0x400000 // object.box3.x
913
temp1 += 0x400000 // object.box3.y
914
temp2 = temp0
915
temp2 += 0x400000 // To the right
916
DrawArrow(temp0, temp1, temp2, temp1, 0xFF, 0xFF, 0xFF)
917
end if
918
end if
919
end event
920
921
922
event RSDKLoad
923
CheckCurrentStageFolder("Zone06")
924
if checkResult == true
925
LoadSpriteSheet("MCZ/Objects.gif")
926
SpriteFrame(-32, -32, 64, 64, 136, 1)
927
else
928
LoadSpriteSheet("MBZ/Objects.gif")
929
SpriteFrame(-32, -32, 64, 64, 797, 697)
930
end if
931
932
AddEditorVariable("rotateDir")
933
SetActiveVariable("rotateDir")
934
AddEnumVariable("Clockwise", 0)
935
AddEnumVariable("Counter-Clockwise", 1)
936
937
// A few crates have their direction attribute set too, reflecting how it was in the original Sonic 2,
938
// but that value doesn't matter in this remake
939
end event
940
941