-
Notifications
You must be signed in to change notification settings - Fork 817
/
map_objects.asm
3044 lines (2816 loc) · 48.2 KB
/
map_objects.asm
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
INCLUDE "data/sprites/facings.asm"
INCLUDE "data/sprites/map_objects.asm"
DeleteMapObject::
push bc
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
ld a, [hl]
push af
ld h, b
ld l, c
ld bc, OBJECT_LENGTH
xor a
call ByteFill
pop af
cp -1
jr z, .ok
bit 7, a
jr nz, .ok
call GetMapObject
ld hl, OBJECT_SPRITE
add hl, bc
ld [hl], -1
.ok
pop bc
ret
HandleObjectStep:
call CheckObjectStillVisible
ret c
call HandleStepType
call HandleObjectAction
ret
CheckObjectStillVisible:
ld hl, OBJECT_FLAGS2
add hl, bc
res OFF_SCREEN_F, [hl]
ld a, [wXCoord]
ld e, a
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
add 1
sub e
jr c, .ok
cp MAPOBJECT_SCREEN_WIDTH
jr nc, .ok
ld a, [wYCoord]
ld e, a
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
add 1
sub e
jr c, .ok
cp MAPOBJECT_SCREEN_HEIGHT
jr nc, .ok
jr .yes
.ok
ld hl, OBJECT_FLAGS2
add hl, bc
set OFF_SCREEN_F, [hl]
ld a, [wXCoord]
ld e, a
ld hl, OBJECT_INIT_X
add hl, bc
ld a, [hl]
add 1
sub e
jr c, .ok2
cp MAPOBJECT_SCREEN_WIDTH
jr nc, .ok2
ld a, [wYCoord]
ld e, a
ld hl, OBJECT_INIT_Y
add hl, bc
ld a, [hl]
add 1
sub e
jr c, .ok2
cp MAPOBJECT_SCREEN_HEIGHT
jr nc, .ok2
.yes
and a
ret
.ok2
ld hl, OBJECT_FLAGS1
add hl, bc
bit WONT_DELETE_F, [hl]
jr nz, .yes2
call DeleteMapObject
scf
ret
.yes2
ld hl, OBJECT_FLAGS2
add hl, bc
set OFF_SCREEN_F, [hl]
and a
ret
HandleStepType:
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld a, [hl]
and a
jr z, .zero
ld hl, OBJECT_FLAGS2
add hl, bc
bit FROZEN_F, [hl]
jr nz, .frozen
cp STEP_TYPE_FROM_MOVEMENT
jr z, .one
jr .ok3
.zero
call StepFunction_Reset
ld hl, OBJECT_FLAGS2
add hl, bc
bit FROZEN_F, [hl]
jr nz, .frozen
.one
call StepFunction_FromMovement
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld a, [hl]
and a
ret z
cp STEP_TYPE_FROM_MOVEMENT
ret z
.ok3
ld hl, StepTypesJumptable
rst JumpTable
ret
.frozen
ret
HandleObjectAction:
ld hl, OBJECT_FLAGS1
add hl, bc
bit INVISIBLE_F, [hl]
jr nz, SetFacingStanding
ld hl, OBJECT_FLAGS2
add hl, bc
bit OFF_SCREEN_F, [hl]
jr nz, SetFacingStanding
bit FROZEN_F, [hl]
jr nz, _CallFrozenObjectAction
; use first column (normal)
ld de, ObjectActionPairPointers
jr CallObjectAction
HandleFrozenObjectAction:
ld hl, OBJECT_FLAGS1
add hl, bc
bit INVISIBLE_F, [hl]
jr nz, SetFacingStanding
_CallFrozenObjectAction:
; use second column (frozen)
ld de, ObjectActionPairPointers + 2
jr CallObjectAction ; pointless
CallObjectAction:
ld hl, OBJECT_ACTION
add hl, bc
ld a, [hl]
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
call _hl_
ret
INCLUDE "engine/overworld/map_object_action.asm"
CopyCoordsTileToLastCoordsTile:
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
ld hl, OBJECT_LAST_MAP_X
add hl, bc
ld [hl], a
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
ld hl, OBJECT_LAST_MAP_Y
add hl, bc
ld [hl], a
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld a, [hl]
ld hl, OBJECT_LAST_TILE
add hl, bc
ld [hl], a
call SetTallGrassFlags
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld a, [hl]
call UselessAndA
ret
CopyLastCoordsToCoords:
ld hl, OBJECT_LAST_MAP_X
add hl, bc
ld a, [hl]
ld hl, OBJECT_MAP_X
add hl, bc
ld [hl], a
ld hl, OBJECT_LAST_MAP_Y
add hl, bc
ld a, [hl]
ld hl, OBJECT_MAP_Y
add hl, bc
ld [hl], a
ret
UpdateTallGrassFlags:
ld hl, OBJECT_FLAGS2
add hl, bc
bit OVERHEAD_F, [hl]
jr z, .ok
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld a, [hl]
call SetTallGrassFlags
.ok
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld a, [hl]
call UselessAndA
ret c ; never happens
ld hl, OBJECT_LAST_TILE
add hl, bc
ld a, [hl]
call UselessAndA
ret
SetTallGrassFlags:
call CheckSuperTallGrassTile
jr z, .set
call CheckGrassTile
jr c, .reset
.set
ld hl, OBJECT_FLAGS2
add hl, bc
set OVERHEAD_F, [hl]
ret
.reset
ld hl, OBJECT_FLAGS2
add hl, bc
res OVERHEAD_F, [hl]
ret
UselessAndA:
and a
ret
EndSpriteMovement:
xor a
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld [hl], a
ld hl, OBJECT_MOVEMENT_INDEX
add hl, bc
ld [hli], a
ld [hli], a ; OBJECT_STEP_INDEX
ld [hli], a ; OBJECT_1D
ld [hl], a ; OBJECT_1E
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], STANDING
ret
InitStep:
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], a
ld hl, OBJECT_FLAGS1
add hl, bc
bit FIXED_FACING_F, [hl]
jr nz, GetNextTile
add a
add a
and %00001100
ld hl, OBJECT_DIRECTION
add hl, bc
ld [hl], a
; fallthrough
GetNextTile:
call GetStepVector
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld a, d
call GetStepVectorSign
ld hl, OBJECT_LAST_MAP_X
add hl, bc
add [hl]
ld hl, OBJECT_MAP_X
add hl, bc
ld [hl], a
ld d, a
ld a, e
call GetStepVectorSign
ld hl, OBJECT_LAST_MAP_Y
add hl, bc
add [hl]
ld hl, OBJECT_MAP_Y
add hl, bc
ld [hl], a
ld e, a
push bc
call GetCoordTileCollision
pop bc
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld [hl], a
ret
AddStepVector:
call GetStepVector
ld hl, OBJECT_SPRITE_X
add hl, bc
ld a, [hl]
add d
ld [hl], a
ld hl, OBJECT_SPRITE_Y
add hl, bc
ld a, [hl]
add e
ld [hl], a
ret
GetStepVector:
; Return (x, y, duration, speed) in (d, e, a, h).
ld hl, OBJECT_WALKING
add hl, bc
ld a, [hl]
and %00001111
add a
add a
ld l, a
ld h, 0
ld de, StepVectors
add hl, de
ld d, [hl]
inc hl
ld e, [hl]
inc hl
ld a, [hli]
ld h, [hl]
ret
StepVectors:
; x, y, duration, speed
; slow
db 0, 1, 16, 1
db 0, -1, 16, 1
db -1, 0, 16, 1
db 1, 0, 16, 1
; normal
db 0, 2, 8, 2
db 0, -2, 8, 2
db -2, 0, 8, 2
db 2, 0, 8, 2
; fast
db 0, 4, 4, 4
db 0, -4, 4, 4
db -4, 0, 4, 4
db 4, 0, 4, 4
GetStepVectorSign:
add a
ret z ; 0 or 128 (-128)
ld a, 1
ret nc ; +1 to +127
ld a, -1
ret ; -127 to -1
UpdatePlayerStep:
ld hl, OBJECT_WALKING
add hl, bc
ld a, [hl]
and %00000011
ld [wPlayerStepDirection], a
call AddStepVector
ld a, [wPlayerStepVectorX]
add d
ld [wPlayerStepVectorX], a
ld a, [wPlayerStepVectorY]
add e
ld [wPlayerStepVectorY], a
ld hl, wPlayerStepFlags
set PLAYERSTEP_CONTINUE_F, [hl]
ret
GetMapObjectField: ; unreferenced
push bc
ld e, a
ld d, 0
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
ld a, [hl]
call GetMapObject
add hl, de
ld a, [hl]
pop bc
ret
RestoreDefaultMovement:
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
ld a, [hl]
cp -1
jr z, .ok
push bc
call GetMapObject
ld hl, MAPOBJECT_MOVEMENT
add hl, bc
ld a, [hl]
pop bc
ret
.ok
ld a, SPRITEMOVEDATA_STANDING_DOWN
ret
ObjectMovement_ZeroAnonJumptableIndex: ; unreferenced
ld hl, OBJECT_MOVEMENT_INDEX
add hl, bc
ld [hl], 0
ret
ObjectMovement_IncAnonJumptableIndex:
ld hl, OBJECT_MOVEMENT_INDEX
add hl, bc
inc [hl]
ret
ObjectMovement_DecAnonJumptableIndex:
ld hl, OBJECT_MOVEMENT_INDEX
add hl, bc
dec [hl]
ret
ObjectMovement_AnonJumptable:
ld hl, OBJECT_MOVEMENT_INDEX
add hl, bc
ld a, [hl]
pop hl
rst JumpTable
ret
ObjectStep_ZeroAnonJumptableIndex:
ld hl, OBJECT_STEP_INDEX
add hl, bc
ld [hl], 0
ret
ObjectStep_IncAnonJumptableIndex:
ld hl, OBJECT_STEP_INDEX
add hl, bc
inc [hl]
ret
ObjectStep_AnonJumptable:
ld hl, OBJECT_STEP_INDEX
add hl, bc
ld a, [hl]
pop hl
rst JumpTable
ret
ObjectStep_GetAnonJumptableIndex: ; unreferenced
ld hl, OBJECT_STEP_INDEX
add hl, bc
ld a, [hl]
ret
ObjectStep_SetAnonJumptableIndex: ; unreferenced
ld hl, OBJECT_STEP_INDEX
add hl, bc
ld [hl], a
ret
StepFunction_Reset:
ld hl, OBJECT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_MAP_Y
add hl, bc
ld e, [hl]
push bc
call GetCoordTileCollision
pop bc
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld [hl], a
call CopyCoordsTileToLastCoordsTile
call EndSpriteMovement
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_FROM_MOVEMENT
ret
StepFunction_FromMovement:
call ObjectStep_ZeroAnonJumptableIndex
call GetSpriteMovementFunction
ld a, [hl]
ld hl, .Pointers
rst JumpTable
ret
.Pointers:
; entries correspond to SPRITEMOVEFN_* constants (see constants/map_object_constants.asm)
table_width 2, StepFunction_FromMovement.Pointers
dw MovementFunction_Null ; 00
dw MovementFunction_RandomWalkY ; 01
dw MovementFunction_RandomWalkX ; 02
dw MovementFunction_RandomWalkXY ; 03
dw MovementFunction_RandomSpinSlow ; 04
dw MovementFunction_RandomSpinFast ; 05
dw MovementFunction_Standing ; 06
dw MovementFunction_ObeyDPad ; 07
dw MovementFunction_Indexed1 ; 08
dw MovementFunction_Indexed2 ; 09
dw MovementFunction_0a ; 0a
dw MovementFunction_0b ; 0b
dw MovementFunction_0c ; 0c
dw MovementFunction_0d ; 0d
dw MovementFunction_0e ; 0e
dw MovementFunction_Follow ; 0f
dw MovementFunction_Script ; 10
dw MovementFunction_Strength ; 11
dw MovementFunction_FollowNotExact ; 12
dw MovementFunction_Shadow ; 13
dw MovementFunction_Emote ; 14
dw MovementFunction_BigStanding ; 15
dw MovementFunction_Bouncing ; 16
dw MovementFunction_ScreenShake ; 17
dw MovementFunction_SpinClockwise ; 18
dw MovementFunction_SpinCounterclockwise ; 19
dw MovementFunction_BoulderDust ; 1a
dw MovementFunction_ShakingGrass ; 1b
assert_table_length NUM_SPRITEMOVEFN
MovementFunction_Null:
ret
MovementFunction_RandomWalkY:
call Random
ldh a, [hRandomAdd]
and %00000001
jp _RandomWalkContinue
MovementFunction_RandomWalkX:
call Random
ldh a, [hRandomAdd]
and %00000001
or %00000010
jp _RandomWalkContinue
MovementFunction_RandomWalkXY:
call Random
ldh a, [hRandomAdd]
and %00000011
jp _RandomWalkContinue
MovementFunction_RandomSpinSlow:
call Random
ldh a, [hRandomAdd]
and %00001100
ld hl, OBJECT_DIRECTION
add hl, bc
ld [hl], a
jp RandomStepDuration_Slow
MovementFunction_RandomSpinFast:
ld hl, OBJECT_DIRECTION
add hl, bc
ld a, [hl]
and %00001100
ld d, a
call Random
ldh a, [hRandomAdd]
and %00001100
cp d
jr nz, .keep
xor %00001100
.keep
ld [hl], a
jp RandomStepDuration_Fast
MovementFunction_Standing:
call CopyLastCoordsToCoords
call EndSpriteMovement
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_RESTORE
ret
MovementFunction_ObeyDPad:
ld hl, GetPlayerNextMovementIndex
jp HandleMovementData
MovementFunction_Indexed1:
ld hl, GetIndexedMovementIndex1
jp HandleMovementData
MovementFunction_Indexed2:
ld hl, GetIndexedMovementIndex2
jp HandleMovementData
MovementFunction_0a:
jp _GetMovementObject
MovementFunction_0b:
jp _GetMovementObject
MovementFunction_0c:
jp _GetMovementObject
MovementFunction_0d:
ld hl, GetPlayerNextMovementIndex
jp HandleMovementData
MovementFunction_0e:
jp _GetMovementObject
MovementFunction_Follow:
ld hl, GetFollowerNextMovementIndex
jp HandleMovementData
MovementFunction_Script:
ld hl, GetMovementIndex
jp HandleMovementData
MovementFunction_Strength:
call ObjectMovement_AnonJumptable
.anon_dw
dw .start
dw .stop
.start:
ld hl, OBJECT_TILE_COLLISION
add hl, bc
ld a, [hl]
call CheckPitTile
jr z, .on_pit
ld hl, OBJECT_FLAGS2
add hl, bc
bit BOULDER_MOVING_F, [hl]
res BOULDER_MOVING_F, [hl]
jr z, .ok
ld hl, OBJECT_RANGE
add hl, bc
ld a, [hl]
and %00000011
or 0
call InitStep
call CanObjectMoveInDirection
jr c, .ok2
ld de, SFX_STRENGTH
call PlaySFX
call SpawnStrengthBoulderDust
call UpdateTallGrassFlags
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_STRENGTH_BOULDER
ret
.ok2
call CopyLastCoordsToCoords
.ok
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], STANDING
ret
.on_pit
call ObjectMovement_IncAnonJumptableIndex
.stop:
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], STANDING
ret
MovementFunction_FollowNotExact:
ld hl, OBJECT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_MAP_Y
add hl, bc
ld e, [hl]
ld hl, OBJECT_RANGE
add hl, bc
ld a, [hl]
push bc
call GetObjectStruct
ld hl, OBJECT_WALKING
add hl, bc
ld a, [hl]
cp STANDING
jr z, .standing
ld hl, OBJECT_LAST_MAP_X
add hl, bc
ld a, [hl]
cp d
jr z, .equal
jr c, .less
ld a, 3
jr .done
.less
ld a, 2
jr .done
.equal
ld hl, OBJECT_LAST_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr z, .standing
jr c, .less2
ld a, 0
jr .done
.less2
ld a, 1
.done
ld d, a
ld hl, OBJECT_WALKING
add hl, bc
ld a, [hl]
and %00001100
or d
pop bc
jp NormalStep
.standing
pop bc
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], STANDING
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ret
MovementFunction_BigStanding:
call EndSpriteMovement
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], STANDING
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_BIG_DOLL_SYM
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_STANDING
ret
MovementFunction_Bouncing:
call EndSpriteMovement
ld hl, OBJECT_WALKING
add hl, bc
ld [hl], STANDING
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_BOUNCE
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_STANDING
ret
MovementFunction_SpinCounterclockwise:
call ObjectMovement_AnonJumptable
.anon_dw
dw _MovementSpinInit
dw _MovementSpinRepeat
dw _MovementSpinTurnLeft
MovementFunction_SpinClockwise:
call ObjectMovement_AnonJumptable
.anon_dw
dw _MovementSpinInit
dw _MovementSpinRepeat
dw _MovementSpinTurnRight
_MovementSpinInit:
call EndSpriteMovement
call ObjectMovement_IncAnonJumptableIndex
; fallthrough
_MovementSpinRepeat:
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, OBJECT_RANGE
add hl, bc
ld a, [hl]
ld a, $10
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SLEEP
call ObjectMovement_IncAnonJumptableIndex
ret
_MovementSpinTurnLeft:
ld de, .facings_counterclockwise
call _MovementSpinNextFacing
jr MovementFunction_SpinCounterclockwise
.facings_counterclockwise:
db OW_RIGHT
db OW_LEFT
db OW_DOWN
db OW_UP
_MovementSpinTurnRight:
ld de, .facings_clockwise
call _MovementSpinNextFacing
jr MovementFunction_SpinClockwise
.facings_clockwise:
db OW_LEFT
db OW_RIGHT
db OW_UP
db OW_DOWN
_MovementSpinNextFacing:
ld hl, OBJECT_DIRECTION
add hl, bc
ld a, [hl]
and %00001100
rrca
rrca
push hl
ld l, a
ld h, 0
add hl, de
ld a, [hl]
pop hl
ld [hl], a
call ObjectMovement_DecAnonJumptableIndex
ret
MovementFunction_Shadow:
call InitMovementField1dField1e
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_SHADOW
ld hl, OBJECT_STEP_DURATION
add hl, de
ld a, [hl]
inc a
add a
add 0
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_WALKING
add hl, de
ld a, [hl]
maskbits NUM_DIRECTIONS
ld d, 1 * TILE_WIDTH + 6
cp DOWN
jr z, .ok
cp UP
jr z, .ok
ld d, 1 * TILE_WIDTH + 4
.ok
ld hl, OBJECT_SPRITE_Y_OFFSET
add hl, bc
ld [hl], d
ld hl, OBJECT_SPRITE_X_OFFSET
add hl, bc
ld [hl], 0
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TRACKING_OBJECT
ret
MovementFunction_Emote:
call EndSpriteMovement
call InitMovementField1dField1e
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_EMOTE
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], 0
ld hl, OBJECT_SPRITE_Y_OFFSET
add hl, bc
ld [hl], -2 * TILE_WIDTH
ld hl, OBJECT_SPRITE_X_OFFSET
add hl, bc
ld [hl], 0
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TRACKING_OBJECT
ret
MovementFunction_BoulderDust:
call EndSpriteMovement
call InitMovementField1dField1e
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_BOULDER_DUST
ld hl, OBJECT_STEP_DURATION
add hl, de
ld a, [hl]
inc a
add a
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_WALKING
add hl, de
ld a, [hl]
and %00000011
ld e, a
ld d, 0
ld hl, .dust_coords
add hl, de
add hl, de
ld d, [hl]
inc hl
ld e, [hl]
ld hl, OBJECT_SPRITE_X_OFFSET
add hl, bc
ld [hl], d
ld hl, OBJECT_SPRITE_Y_OFFSET
add hl, bc
ld [hl], e
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TRACKING_OBJECT
ret
.dust_coords:
; x, y
db 0, -4
db 0, 8
db 6, 2
db -6, 2
MovementFunction_ShakingGrass:
call EndSpriteMovement
call InitMovementField1dField1e
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_GRASS_SHAKE
ld hl, OBJECT_STEP_DURATION
add hl, de
ld a, [hl]
add -1
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TRACKING_OBJECT
ret
InitMovementField1dField1e:
ld hl, OBJECT_RANGE
add hl, bc
ld a, [hl]
push bc
call GetObjectStruct
ld d, b
ld e, c
pop bc
ld hl, OBJECT_1D
add hl, bc
ld [hl], e
inc hl ; OBJECT_1E
ld [hl], d
ret
MovementFunction_ScreenShake:
call EndSpriteMovement