-
Notifications
You must be signed in to change notification settings - Fork 0
/
char-sonic.lua
1128 lines (956 loc) · 36.8 KB
/
char-sonic.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- File that handles Sonic's stuff.
-- The moves. (There's a whole buncha them.)
ACT_SONIC_IDLE =
allocate_mario_action(ACT_GROUP_STATIONARY | ACT_FLAG_IDLE | ACT_FLAG_ALLOW_FIRST_PERSON | ACT_FLAG_PAUSE_EXIT)
ACT_SONIC_LYING_DOWN =
allocate_mario_action(ACT_GROUP_STATIONARY | ACT_FLAG_ALLOW_FIRST_PERSON | ACT_FLAG_PAUSE_EXIT)
ACT_SONIC_WALKING = allocate_mario_action(ACT_GROUP_MOVING | ACT_FLAG_MOVING)
ACT_SONIC_JUMP =
allocate_mario_action(
ACT_GROUP_AIRBORNE | ACT_FLAG_MOVING | ACT_FLAG_ATTACKING | ACT_FLAG_AIR | ACT_FLAG_CONTROL_JUMP_HEIGHT |
ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION | ACT_FLAG_SHORT_HITBOX)
ACT_SONIC_HOLD_JUMP =
allocate_mario_action(
ACT_GROUP_AIRBORNE | ACT_FLAG_MOVING | ACT_FLAG_AIR | ACT_FLAG_CONTROL_JUMP_HEIGHT)
ACT_SPINDASH =
allocate_mario_action(ACT_GROUP_STATIONARY | ACT_FLAG_STATIONARY | ACT_FLAG_ATTACKING | ACT_FLAG_INVULNERABLE | ACT_FLAG_SHORT_HITBOX)
ACT_SONIC_ROLL =
allocate_mario_action(ACT_GROUP_MOVING | ACT_FLAG_MOVING | ACT_FLAG_ATTACKING | ACT_FLAG_BUTT_OR_STOMACH_SLIDE | ACT_FLAG_SHORT_HITBOX)
ACT_SONIC_FREEFALL =
allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_MOVING | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_SONIC_EAGLE =
allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_SONIC_WINDMILL_KICK =
allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_DROPDASH =
allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION | ACT_FLAG_SHORT_HITBOX)
ACT_AIRDASH = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_SHORT_HITBOX)
ACT_BOUND_JUMP =
allocate_mario_action(
ACT_GROUP_AIRBORNE | ACT_FLAG_MOVING | ACT_FLAG_ATTACKING | ACT_FLAG_AIR |
ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION | ACT_FLAG_SHORT_HITBOX)
ACT_BOUND_POUND =
allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_BOUND_POUND_LAND =
allocate_mario_action(ACT_GROUP_MOVING | ACT_FLAG_MOVING | ACT_FLAG_ATTACKING)
-- Action functions
function act_spindash(m)
local e = gMarioStateExtras[m.playerIndex]
local slopeAngle = atan2s(m.floor.normal.z, m.floor.normal.x)
local MAXDASH = 15
local MINDASH = 8
-- Spindash revving.
if m.actionTimer == 0 then
play_character_sound(m, CHAR_SOUND_YAH_WAH_HOO)
audio_sample_play(SOUND_SONIC_SPIN, m.pos, 1)
e.dashspeed = 0
e.moveAngle = m.faceAngle.y
end
-- Direction changing.
if (m.input & INPUT_NONZERO_ANALOG) ~= 0 then
e.moveAngle = m.intendedYaw
end
-- Dash limit.
if e.dashspeed < MINDASH then
e.dashspeed = MINDASH
elseif e.dashspeed > MAXDASH then
e.dashspeed = MAXDASH
m.particleFlags = m.particleFlags | PARTICLE_SPARKLES
end
-- Animations.
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
set_anim_to_frame(m, e.animFrame)
if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
e.animFrame = e.animFrame - m.marioObj.header.gfx.animInfo.curAnim.loopEnd
end
-- Dash release.
if (m.controller.buttonDown & B_BUTTON) == 0 then
m.faceAngle.y = e.moveAngle
if m.forwardVel < 60 then
mario_set_forward_vel(m, e.dashspeed * 8)
elseif m.forwardVel < 140 then
mario_set_forward_vel(m, m.forwardVel + e.dashspeed * 2)
else
mario_set_forward_vel(m, m.forwardVel + 1)
end
audio_sample_play(SOUND_SONIC_DASH, m.pos, 1)
return set_mario_action(m, ACT_SONIC_ROLL, 0)
elseif (m.controller.buttonDown & A_BUTTON) ~= 0 then
return set_mario_action(m, ACT_JUMP, 0)
end
-- Physics 'n stuff
if m.playerIndex == 0 then
if mario_check_object_grab(m) ~= 0 then
return true
end
end
local stepResult = perform_ground_step(m)
if stepResult == GROUND_STEP_LEFT_GROUND then
return set_mario_action(m, ACT_FREEFALL, 0)
end
apply_slope_decel(m, 0.5)
if m.vel.x ~= 0 or m.vel.z ~= 0 then
m.faceAngle.y = atan2s(m.vel.z, m.vel.x)
elseif m.vel.x == 0 and m.vel.z == 0 then
m.faceAngle.y = e.moveAngle
end
e.animFrame = e.animFrame + (e.dashspeed / 4)
m.actionTimer = m.actionTimer + 1
e.dashspeed = e.dashspeed + 0.5
m.marioObj.header.gfx.angle.y = e.moveAngle
return 0
end
function act_sonic_roll(m)
local e = gMarioStateExtras[m.playerIndex]
if m.actionTimer == 0 then
e.rotAngle = 0x000
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
return do_sonic_jump(m)
end
if (m.controller.buttonPressed & B_BUTTON) ~= 0 then
set_mario_action(m, e.walkAction, 0)
end
if m.playerIndex == 0 then
if mario_check_object_grab(m) ~= 0 then
mario_grab_used_object(m)
if m.interactObj.behavior == get_behavior_from_id(id_bhvBowser) then
m.marioBodyState.grabPos = GRAB_POS_BOWSER
return 1
elseif m.interactObj.oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO ~= 0 then
return 0
else
set_mario_action(m, ACT_HOLD_BUTT_SLIDE, 0)
m.marioBodyState.grabPos = GRAB_POS_LIGHT_OBJ
return 1
end
end
end
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
local stepResult = perform_ground_step(m)
if stepResult == GROUND_STEP_NONE then
if mario_floor_is_slope(m) ~= 0 or mario_floor_is_steep(m) ~= 0 then
sonic_apply_slope_accel(m)
else
mario_set_forward_vel(m, approach_f32(m.forwardVel, 0, 1, 1))
end
if m.forwardVel < 0 then
m.faceAngle.y = atan2s(m.vel.z, m.vel.x)
mario_set_forward_vel(m, math.abs(m.forwardVel))
end
m.faceAngle.y = m.intendedYaw - approach_s32(convert_s16(m.intendedYaw - m.faceAngle.y), 0, 0x1000, 0x1000)
elseif stepResult == GROUND_STEP_HIT_WALL then
if m.forwardVel > 70 then
mario_set_forward_vel(m, -16.0)
m.particleFlags = m.particleFlags | PARTICLE_VERTICAL_STAR
return set_mario_action(m, ACT_GROUND_BONK, 0)
else
return set_mario_action(m, ACT_SONIC_IDLE, 0)
end
elseif stepResult == GROUND_STEP_LEFT_GROUND then
set_mario_action(m, ACT_SONIC_JUMP, 0)
end
if math.abs(m.forwardVel) < 10 then
set_mario_action(m, ACT_WALKING, 0)
end
e.rotAngle = e.rotAngle + (0x50 * m.forwardVel)
if e.rotAngle > 0x9000 then
e.rotAngle = e.rotAngle - 0x9000
end
set_anim_to_frame(m, 10 * e.rotAngle / 0x9000)
align_with_floor_but_better(m)
m.actionTimer = m.actionTimer + 1
return 0
end
function act_sonic_jump(m)
local e = gMarioStateExtras[m.playerIndex]
local spinSpeed = 0
if m.actionTimer == 0 then
e.rotAngle = 0x000
end
if m.actionTimer == 0 then
play_character_sound_if_no_flag(m, CHAR_SOUND_YAH_WAH_HOO, MARIO_ACTION_SOUND_PLAYED)
end
local stepResult =
sonic_common_air_action_step(
m,
ACT_FREEFALL_LAND,
MARIO_ANIM_FORWARD_SPINNING,
AIR_STEP_CHECK_LEDGE_GRAB | AIR_STEP_CHECK_HANG,
true,
true
)
if (m.controller.buttonPressed & B_BUTTON) ~= 0 then
return sonic_air_attacks(m)
end
if (m.input & INPUT_Z_PRESSED) ~= 0 then
return set_mario_action(m, ACT_BOUND_POUND, 0)
end
if m.forwardVel > 50 then
spinSpeed = m.forwardVel
else
spinSpeed = 50
end
e.rotAngle = e.rotAngle + (0x50 * spinSpeed)
if e.rotAngle > 0x9000 then
e.rotAngle = e.rotAngle - 0x9000
end
set_anim_to_frame(m, 10 * e.rotAngle / 0x9000)
m.actionTimer = m.actionTimer + 1
end
function act_sonic_hold_jump(m)
if (m.marioObj.oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) ~= 0 then
return drop_and_set_mario_action(m, ACT_FREEFALL, 0)
end
if (m.input & INPUT_B_PRESSED) ~= 0 and m.heldObj ~= nil and (m.heldObj.oInteractionSubtype & INT_SUBTYPE_HOLDABLE_NPC) == 0 then
m.heldObj.oForwardVel = 0
return set_mario_action(m, ACT_AIR_THROW, 0)
end
if (m.input & INPUT_Z_PRESSED) ~= 0 then
return drop_and_set_mario_action(m, ACT_BOUND_POUND, 0)
end
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0)
sonic_common_air_action_step(m, ACT_HOLD_JUMP_LAND, MARIO_ANIM_JUMP_WITH_LIGHT_OBJ,
AIR_STEP_CHECK_LEDGE_GRAB, true, true)
return 0
end
function act_dropdash(m)
local e = gMarioStateExtras[m.playerIndex]
if m.actionTimer == 0 then
e.animFrame = 0
e.dashspeed = 6
end
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
e.animFrame = e.animFrame + 3
if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
e.animFrame = e.animFrame - m.marioObj.header.gfx.animInfo.curAnim.loopEnd
end
set_anim_to_frame(m, e.animFrame)
local stepResult =
sonic_common_air_action_step(
m,
ACT_SONIC_ROLL,
MARIO_ANIM_FORWARD_SPINNING,
AIR_STEP_CHECK_LEDGE_GRAB,
true,
false
)
if stepResult == AIR_STEP_LANDED then
audio_sample_play(SOUND_SONIC_DASH, m.pos, 1)
spawn_non_sync_object(
id_bhvSpinDust,
E_MODEL_SMOKE,
m.pos.x,
m.pos.y,
m.pos.z,
function(o)
end
)
mario_set_forward_vel(m, m.forwardVel + 30)
elseif stepResult == AIR_STEP_HIT_WALL then
e.wallClimbed = 1
mario_set_forward_vel(m, 0)
m.particleFlags = m.particleFlags | PARTICLE_DUST | PARTICLE_MIST_CIRCLE
set_mario_action(m, ACT_TRIPLE_JUMP, 0)
if e.lastforwardVel < 70 then
m.vel.y = 70
elseif e.lastforwardVel > 120 then
m.vel.y = 120
else
m.vel.y = e.lastforwardVel
end
end
if (m.controller.buttonDown & B_BUTTON) == 0 then
if e.airdashed == 0 then
play_sound(SOUND_ACTION_FLYING_FAST, m.marioObj.header.gfx.cameraToObject)
play_character_sound(m, CHAR_SOUND_YAHOO_WAHA_YIPPEE)
set_mario_action(m, ACT_AIRDASH, 0)
else
m.action = ACT_SONIC_JUMP
end
end
if m.forwardVel > 50 then
spinSpeed = m.forwardVel
else
spinSpeed = 50
end
m.actionTimer = m.actionTimer + 1
end
function act_airdash(m)
local e = gMarioStateExtras[m.playerIndex]
e.airdashed = 1
local stepResult = perform_air_step(m, 0)
if stepResult == AIR_STEP_HIT_WALL then
mario_set_forward_vel(m, -16.0)
m.vel.y = 40
m.particleFlags = m.particleFlags | PARTICLE_VERTICAL_STAR
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0)
elseif stepResult == AIR_STEP_LANDED then
set_mario_action(m, ACT_SONIC_WALKING, 0)
end
if m.actionTimer > 10 then
if (m.flags & MARIO_WING_CAP) ~= 0 then
return set_mario_action(m, ACT_FLYING, 1)
else
return set_mario_action(m, ACT_FREEFALL, 0)
end
else
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
set_anim_to_frame(m, e.animFrame)
if m.forwardVel < 75 then
mario_set_forward_vel(m, 75)
else
mario_set_forward_vel(m, m.forwardVel)
end
if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
e.animFrame = e.animFrame - m.marioObj.header.gfx.animInfo.curAnim.loopEnd
end
if m.action ~= ACT_FLYING then
m.vel.y = 0
end
e.animFrame = e.animFrame + 2
m.particleFlags = m.particleFlags | PARTICLE_SPARKLES
end
m.actionTimer = m.actionTimer + 1
return 0
end
function act_sonic_walking(m)
local e = gMarioStateExtras[m.playerIndex]
local startYaw = m.faceAngle.x
m.actionState = 0
update_sonic_walking_speed(m)
local stepResult = perform_ground_step(m)
if stepResult == GROUND_STEP_LEFT_GROUND then
set_mario_action(m, ACT_FREEFALL, 0)
set_mario_animation(m, MARIO_ANIM_GENERAL_FALL)
elseif stepResult == GROUND_STEP_NONE then
if m.heldObj ~= nil then
set_mario_anim_with_accel(m, MARIO_ANIM_WALK_WITH_LIGHT_OBJ, m.forwardVel * 0x4000)
play_step_sound(m, 12, 62)
else
sonic_gen_anim_and_audio_for_walk(m, 20, 48)
end
if (m.intendedMag - m.forwardVel) > 16 then
set_mario_particle_flags(m, PARTICLE_DUST, false)
end
elseif stepResult == GROUND_STEP_HIT_WALL then
if m.heldObj == nil then
push_or_sidle_wall(m, m.pos)
else
if m.forwardVel > 5 then mario_set_forward_vel(m, 5) end
end
m.actionTimer = 0
end
check_ledge_climb_down(m)
tilt_body_walking(m, startYaw)
if should_begin_sliding(m) ~= 0 then
if m.heldObj == nil then
return set_mario_action(m, ACT_BEGIN_SLIDING, 0)
else
return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0)
end
end
if (m.input & INPUT_Z_PRESSED) ~= 0 then
return drop_and_set_mario_action(m, ACT_CROUCH_SLIDE, 0)
end
if (m.input & INPUT_FIRST_PERSON) ~= 0 then
return begin_braking_action(m)
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
return do_sonic_jump(m)
end
if (m.input & INPUT_B_PRESSED) ~= 0 then
if m.heldObj ~= nil then
set_mario_action(m, ACT_THROWING, 0)
else
if (m.controller.buttonDown & A_BUTTON) ~= 0 then
set_mario_action(m, ACT_JUMP_KICK, 0)
else
e.moveAngle = m.faceAngle.y
return set_mario_action(m, ACT_SPINDASH, 0)
end
end
end
if (m.input & INPUT_ZERO_MOVEMENT) ~= 0 then
mario_set_forward_vel(m, approach_f32(m.forwardVel, 0, 3, 3))
if math.abs(m.forwardVel) < 2 then
if m.heldObj ~= nil then
return set_mario_action(m, ACT_HOLD_IDLE, 0)
else
return set_mario_action(m, ACT_IDLE, 0)
end
end
end
if analog_stick_held_back(m) ~= 0 and m.heldObj == nil then
m.faceAngle.y = m.intendedYaw + 0x8000
return set_mario_action(m, ACT_TURNING_AROUND, 0)
end
return 0
end
function act_bound_jump(m)
local e = gMarioStateExtras[m.playerIndex]
if (m.input & INPUT_Z_PRESSED) ~= 0 then
return set_mario_action(m, ACT_BOUND_POUND, 0)
end
if (m.input & INPUT_B_PRESSED) ~= 0 then
sonic_air_attacks(m)
end
sonic_common_air_action_step(m, ACT_TRIPLE_JUMP_LAND, MARIO_ANIM_FORWARD_SPINNING, AIR_STEP_CHECK_HANG, false, true)
set_anim_to_frame(m, e.animFrame)
if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
e.animFrame = e.animFrame - m.marioObj.header.gfx.animInfo.curAnim.loopEnd
end
e.animFrame = e.animFrame + 1
m.actionTimer = m.actionTimer + 1
return 0
end
function act_bound_pound(m)
local e = gMarioStateExtras[m.playerIndex]
local soundRng = math.random(1,2)
if soundRng == 1 then
play_character_sound_if_no_flag(m, CHAR_SOUND_YAH_WAH_HOO, MARIO_ACTION_SOUND_PLAYED)
else
play_character_sound_if_no_flag(m, CHAR_SOUND_HOOHOO, MARIO_ACTION_SOUND_PLAYED)
end
m.vel.y = -100.0
m.particleFlags = m.particleFlags | PARTICLE_SPARKLES
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
set_anim_to_frame(m, e.animFrame)
if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
e.animFrame = e.animFrame - m.marioObj.header.gfx.animInfo.curAnim.loopEnd
end
e.animFrame = e.animFrame + 2
local stepResult = perform_air_step(m, 0)
sonic_update_air(m)
if stepResult == AIR_STEP_LANDED then
m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE | PARTICLE_HORIZONTAL_STAR
play_sound(SOUND_GENERAL_SHORT_POUND3, m.marioObj.header.gfx.cameraToObject)
m.squishTimer = 5
set_mario_action(m, ACT_BOUND_POUND_LAND, 1)
end
m.peakHeight = m.pos.y
m.actionTimer = m.actionTimer + 1
return 0
end
function act_bound_pound_land(m)
local e = gMarioStateExtras[m.playerIndex]
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
set_anim_to_frame(m, e.animFrame)
e.animFrame = e.animFrame + 2
local stepResult = perform_ground_step(m)
if stepResult == GROUND_STEP_LEFT_GROUND then
set_mario_action(m, ACT_BOUND_POUND, 0)
end
-- A debuff so that players can't just bounce up slides.
if (m.input & INPUT_ABOVE_SLIDE) ~= 0 then
return set_mario_action(m, ACT_BUTT_SLIDE, 0)
end
if (m.input & INPUT_UNKNOWN_10) ~= 0 then
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0)
end
set_mario_action(m, ACT_BOUND_JUMP, 1)
end
function act_sonic_freefall(m)
local animation = 0
local landAction = 0
if (m.input & INPUT_B_PRESSED) ~= 0 then
sonic_air_attacks(m)
end
if (m.input & INPUT_Z_PRESSED) ~= 0 then
return drop_and_set_mario_action(m, ACT_BOUND_POUND, 0)
end
if m.heldObj == nil then
if m.actionArg == 0 then
animation = MARIO_ANIM_GENERAL_FALL
elseif m.actionArg == 1 then
animation = MARIO_ANIM_FALL_FROM_SLIDE
elseif m.actionArg == 2 then
animation = MARIO_ANIM_FALL_FROM_SLIDE_KICK
end
landAction = ACT_FREEFALL_LAND
else
animation = MARIO_ANIM_FALL_WITH_LIGHT_OBJ
landAction = ACT_HOLD_FREEFALL_LAND
end
sonic_common_air_action_step(m, landAction, animation, AIR_STEP_CHECK_LEDGE_GRAB, true, true)
return 0
end
function act_sonic_idle(m)
stationary_ground_step(m)
if (m.quicksandDepth > 30.0) then
return set_mario_action(m, ACT_IN_QUICKSAND, 0)
end
if (m.input & INPUT_IN_POISON_GAS) ~= 0 then
return set_mario_action(m, ACT_COUGHING, 0)
end
if ((m.actionArg & 1) == 0 and m.health < 0x300) then
return set_mario_action(m, ACT_PANTING, 0)
end
if check_common_idle_cancels(m) ~= 0 then
return 1
end
if (m.actionArg & 1) ~= 0 then
set_mario_animation(m, MARIO_ANIM_STAND_AGAINST_WALL)
else
if m.actionState == 0 then
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT)
if is_anim_at_end(m) ~= 0 then
m.actionState = m.actionState + 1
end
elseif m.actionState == 1 then
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_RIGHT)
if is_anim_at_end(m) ~= 0 then
m.actionState = m.actionState + 1
end
elseif m.actionState == 2 then
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_CENTER)
if is_anim_at_end(m) ~= 0 then
if m.actionTimer > math.random(10, 15) * 30 then
m.actionTimer = 0
if ((m.area.terrainType & TERRAIN_MASK) == TERRAIN_SNOW) then
m.actionState = 5
else
m.actionState = 3
end
else
m.actionState = 0
end
end
elseif m.actionState == 3 then
set_mario_animation(m, MARIO_ANIM_START_SLEEP_IDLE)
smlua_anim_util_set_animation(m.marioObj, "SONIC_IMPATIENT_START")
if is_anim_past_end(m) ~= 0 then
m.actionState = 4
end
elseif m.actionState == 4 then
set_mario_animation(m, MARIO_ANIM_START_SLEEP_SCRATCH)
m.marioBodyState.eyeState = 18
smlua_anim_util_set_animation(m.marioObj, "SONIC_IMPATIENT")
play_step_sound(m, 15, 15)
if is_anim_past_frame(m, 20) ~= 0 then
if m.actionTimer > math.random(20, 30) * 30 then
m.actionState = 6
end
end
elseif m.actionState == 5 then
set_mario_animation(m, MARIO_ANIM_START_SLEEP_YAWN)
smlua_anim_util_set_animation(m.marioObj, "SONIC_SNEEZE")
if m.marioObj.header.gfx.animInfo.animFrame < 8 then
m.marioBodyState.eyeState = 14
elseif m.marioObj.header.gfx.animInfo.animFrame < 12 then
m.marioBodyState.eyeState = 15
else
m.marioBodyState.eyeState = 13
end
if is_anim_past_end(m) ~= 0 then
m.actionState = 0
end
elseif m.actionState == 6 then
set_mario_animation(m, MARIO_ANIM_START_SLEEP_SITTING)
m.marioBodyState.eyeState = 18
smlua_anim_util_set_animation(m.marioObj, "SONIC_IMPATIENT2_START")
if is_anim_past_end(m) ~= 0 then
set_mario_action(m, ACT_SONIC_LYING_DOWN, 0)
end
end
end
m.actionTimer = m.actionTimer + 1
return 0
end
function act_sonic_lying_down(m)
local e = gMarioStateExtras[m.playerIndex]
local animFrame = m.marioObj.header.gfx.animInfo.animFrame
stationary_ground_step(m)
if (m.quicksandDepth > 30.0) then
return set_mario_action(m, ACT_IN_QUICKSAND, 0)
end
if (m.input & INPUT_NONZERO_ANALOG) ~= 0 then
m.actionState = 1
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
return do_sonic_jump(m)
end
if (m.input & INPUT_B_PRESSED) ~= 0 then
if (m.input & INPUT_A_DOWN) ~= 0 then
set_mario_action(m, ACT_JUMP_KICK, 0)
else
e.moveAngle = m.faceAngle.y
return set_mario_action(m, ACT_SPINDASH, 0)
end
end
if m.actionState == 0 then
m.marioBodyState.eyeState = 18
set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT)
smlua_anim_util_set_animation(m.marioObj, "SONIC_IMPATIENT2")
play_step_sound(m, 15, 15)
--if is_anim_past_frame(m, 20) ~= 0 then
-- if m.actionTimer > math.random(40, 50) * 30 then
-- e.animFrame = 8
-- m.actionState = 2
-- end
--end
elseif m.actionState == 1 then
--stop_custom_character_sound(m, CHAR_SOUND_SNORING1)
--stop_custom_character_sound(m, CHAR_SOUND_SNORING2)
set_mario_animation(m, MARIO_ANIM_WAKE_FROM_LYING)
smlua_anim_util_set_animation(m.marioObj, "SONIC_IMPATIENT2_END")
if (is_anim_past_frame(m, 9) ~= 0 and (m.input & INPUT_NONZERO_ANALOG) ~= 0)
or is_anim_past_end(m) ~= 0 then
set_mario_action(m, ACT_SONIC_IDLE, 0)
end
elseif m.actionState == 2 then
m.marioBodyState.eyeState = 16
set_mario_animation(m, MARIO_ANIM_SLEEP_LYING)
smlua_anim_util_set_animation(m.marioObj, "SONIC_SLEEPING")
set_anim_to_frame(m, e.animFrame)
if (e.animFrame == 2) then
play_character_sound(m, CHAR_SOUND_SNORING2)
end
if (e.animFrame == 25) then
play_character_sound(m, CHAR_SOUND_SNORING1)
end
e.animFrame = e.animFrame + 1
if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
e.animFrame = 0
end
end
m.actionTimer = m.actionTimer + 1
return 0
end
function act_sonic_eagle(m)
local e = gMarioStateExtras[m.playerIndex]
local animFrame = m.marioObj.header.gfx.animInfo.animFrame
if (m.actionState == 0) then
play_character_sound_if_no_flag(m, CHAR_SOUND_PUNCH_HOO, MARIO_ACTION_SOUND_PLAYED)
m.marioObj.header.gfx.animInfo.animID = -1
set_mario_animation(m, MARIO_ANIM_AIR_KICK)
smlua_anim_util_set_animation(m.marioObj, "SONIC_EAGLE")
m.actionState = 1
end
if (m.controller.buttonPressed & Z_TRIG) ~= 0 and m.actionTimer > 4 then
set_mario_action(m, ACT_BOUND_POUND, 0)
end
if (animFrame == 0) then
m.marioBodyState.punchState = (2 << 6) | 6
end
if (animFrame >= 0 and animFrame < 8) then
m.flags = m.flags | MARIO_KICKING
end
sonic_update_air(m)
m.faceAngle.y = m.intendedYaw - approach_s32(convert_s16(m.intendedYaw - m.faceAngle.y), 0, 0x1000, 0x1000)
if m.forwardVel < 0 and analog_stick_held_back(m) ~= 0 then
m.faceAngle.y = atan2s(m.vel.z, m.vel.x)
mario_set_forward_vel(m, math.abs(m.forwardVel))
end
if m.faceAngle.y ~= m.intendedYaw and m.forwardVel > 32 then
mario_set_forward_vel(m, approach_f32(m.forwardVel, 0, m.forwardVel/16, m.forwardVel/16))
else
mario_set_forward_vel(m, m.forwardVel)
end
local stepResult = perform_air_step(m, 0)
if stepResult == AIR_STEP_LANDED then
if check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB) == 0 then
if m.forwardVel ~= 0 then
set_mario_action(m, e.walkAction, 0)
else
set_mario_action(m, ACT_FREEFALL_LAND, 0)
end
end
elseif stepResult == AIR_STEP_HIT_WALL then
mario_set_forward_vel(m, 0.0)
end
m.actionTimer = m.actionTimer + 1
return 0
end
function act_sonic_windmill_kick(m)
local e = gMarioStateExtras[m.playerIndex]
if m.actionTimer == 0 then
play_character_sound_if_no_flag(m, CHAR_SOUND_PUNCH_HOO, MARIO_ACTION_SOUND_PLAYED)
e.rotAngle = m.faceAngle.y
end
m.marioBodyState.eyeState = MARIO_EYES_LOOK_RIGHT
if (m.input & INPUT_Z_PRESSED) ~= 0 then
return set_mario_action(m, ACT_GROUND_POUND, 0)
end
if (m.input & INPUT_NONZERO_ANALOG) ~= 0 then
mario_set_forward_vel(m, math.abs(m.forwardVel))
end
if math.abs(m.forwardVel) >= 10 then
m.faceAngle.y = m.intendedYaw - approach_s32(convert_s16(m.intendedYaw - m.faceAngle.y), 0, 0x600, 0x600)
else
m.faceAngle.y = m.intendedYaw
end
if m.faceAngle.y ~= m.intendedYaw and m.forwardVel > 32 then
mario_set_forward_vel(m, approach_f32(m.forwardVel, 0, m.forwardVel/16, m.forwardVel/16))
else
mario_set_forward_vel(m, m.forwardVel)
end
local stepResult = perform_air_step(m, 0)
sonic_update_air(m)
set_mario_animation(m, MARIO_ANIM_SLIDE_KICK)
smlua_anim_util_set_animation(m.marioObj, "SONIC_WINDMILL_KICK")
if stepResult == AIR_STEP_HIT_WALL and m.wall ~= nil then
m.particleFlags = m.particleFlags | PARTICLE_VERTICAL_STAR
play_sound(SOUND_ACTION_BOUNCE_OFF_OBJECT, m.marioObj.header.gfx.cameraToObject)
cur_obj_shake_screen(SHAKE_POS_SMALL)
wall_bounce(m)
if m.forwardVel < 5 then
mario_set_forward_vel(m, 5)
else
mario_set_forward_vel(m, math.abs(m.forwardVel))
end
elseif stepResult == AIR_STEP_LANDED then
if m.vel.x ~= 0 or m.vel.z ~= 0 then
m.faceAngle.y = atan2s(m.vel.z, m.vel.x)
end
if (check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB) == 0) then
if m.forwardVel ~= 0 then
set_mario_action(m, e.walkAction, 0)
else
set_mario_action(m, ACT_FREEFALL_LAND, 0)
end
end
end
e.rotAngle = e.rotAngle + 0x3000
m.marioObj.header.gfx.angle.y = e.rotAngle
if (e.rotAngle) % 0x7 == 0 then
play_sound(SOUND_ACTION_TWIRL, m.marioObj.header.gfx.cameraToObject)
end
--m.flags = m.flags | MARIO_KICKING
m.actionTimer = m.actionTimer + 1
return 0
end
-- Hooks.
function sonic_on_set_action(m)
local e = gMarioStateExtras[m.playerIndex]
if (m.action == ACT_PUNCHING and m.actionArg ~= 9) or m.action == ACT_MOVE_PUNCHING then
m.vel.y = 0
if (m.input & INPUT_A_DOWN) ~= 0 then
set_mario_action(m, ACT_JUMP_KICK, 0)
else
e.moveAngle = m.faceAngle.y
set_mario_action(m, ACT_SPINDASH, 0)
end
end
if m.action == ACT_HOLD_WALKING then
m.action = e.walkAction
end
if m.action == ACT_SLIDE_KICK then
set_mario_action(m, ACT_SONIC_WINDMILL_KICK, 0)
end
if m.action == ACT_SONIC_WINDMILL_KICK then
m.vel.y = 25
if m.forwardVel < 50 then mario_set_forward_vel(m, 50) end
end
if m.action == ACT_DIVE then
return sonic_air_attacks(m)
end
if m.action == ACT_FREEFALL_LAND then
return set_mario_action(m, ACT_DOUBLE_JUMP_LAND, 0)
end
if m.action == ACT_FREEFALL then
m.action = ACT_SONIC_FREEFALL
end
if m.action == ACT_JUMP_KICK then
m.action = ACT_SONIC_EAGLE
end
if m.action == ACT_BOUND_JUMP then
m.vel.y = 65.0
end
local jumpActions = {
[ACT_JUMP] = true,
[ACT_DOUBLE_JUMP] = true,
[ACT_LONG_JUMP] = true,
[ACT_FLYING_TRIPLE_JUMP] = true,
[ACT_HOLD_JUMP] = true,
[ACT_STEEP_JUMP] = true
}
if jumpActions[m.action] then
return do_sonic_jump(m)
end
if m.action == ACT_GROUND_POUND then
return set_mario_action(m, ACT_BOUND_POUND, 0)
end
end
local airBonkActions = {
[ACT_QUICKSAND_DEATH] = true,
[ACT_GRABBED] = true,
[ACT_SHOCKED] = true,
[ACT_GETTING_BLOWN] = true,
[ACT_HARD_BACKWARD_AIR_KB] = true,
[ACT_BACKWARD_AIR_KB] = true,
[ACT_SOFT_BACKWARD_GROUND_KB] = true,
[ACT_HARD_FORWARD_AIR_KB] = true,
[ACT_FORWARD_AIR_KB] = true,
[ACT_SOFT_FORWARD_GROUND_KB] = true,
[ACT_THROWN_FORWARD] = true,
[ACT_THROWN_BACKWARD] = true,
[ACT_DEATH_EXIT] = true
}
function sonic_update(m)
local e = gMarioStateExtras[m.playerIndex]
sonic_walking_door_check(m)
sonic_check_wall_kick(m)
-- Stats.
e.walkAction = ACT_SONIC_WALKING
e.movingSpeed = 64.0
e.movingSpeedSlow = 48.0
e.jumpHeight = 40
e.jumpHeightMultiplier = 0.2
local reloadActions = {
[ACT_CLIMBING_POLE] = true,
[ACT_WALL_KICK_AIR] = true
}
if m.pos.y == m.floorHeight or reloadActions[m.action] then
e.airdashed = 0
e.wallClimbed = 0
end
-- Basically delays Sonic fall damage.
if m.pos.y == m.floorHeight or m.vel.y >= -5 then
e.peakHeightDelay = 0
end
if e.peakHeightDelay < 30 then
m.peakHeight = m.pos.y
e.peakHeightDelay = e.peakHeightDelay + 1
end
if m.action == ACT_SOFT_BONK then
m.actionTimer = m.actionTimer + 1
end
if m.action == ACT_TURNING_AROUND then
apply_slope_decel(m, 6)
end
if m.action ~= ACT_GROUND_POUND_LAND then
e.lastforwardVel = m.forwardVel
end
--if m.marioObj.header.gfx.animInfo.animID == 79 then
-- m.marioObj.header.gfx.disableAutomaticShadowPos = true
--end
-- Animations 'n stuff.
if (m.flags & MARIO_METAL_CAP) ~= 0 then
m.marioBodyState.eyeState = 1
end
if m.action == ACT_PANTING then
m.marioBodyState.eyeState = 17
end
if m.marioObj.header.gfx.animInfo.animID == MARIO_ANIM_STAR_DANCE then
smlua_anim_util_set_animation(m.marioObj, "SONIC_STAR_DANCE")
if m.marioObj.header.gfx.animInfo.animFrame < 18 then
m.marioBodyState.eyeState = 12
elseif m.marioObj.header.gfx.animInfo.animFrame < 46 then
m.marioBodyState.eyeState = 11
else
m.marioBodyState.eyeState = 9
end
end
if m.marioObj.header.gfx.animInfo.animID == MARIO_ANIM_SKID_ON_GROUND then