/
npcs.s
executable file
·1486 lines (1181 loc) · 25.7 KB
/
npcs.s
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
; NPCs
;
; This code uses the DP register to select which NPC is processed.
.include "game.h"
.include "npcs.h"
.include "elevators.h"
.include "routines/math.h"
.include "routines/block.h"
.include "routines/metasprite.h"
.include "routines/random.h"
MODULE Npcs
.struct NpcStruct
;; Current state of the elevator
state .word
;; The side of the screen the NPC is on.
;; If 0, then on left, if $FF or 1 on right
leftSideOnZero .byte
;; The current floor the NPC is on
floor .byte
;; The current floor the NPC wants to go to
targetFloor .byte
;; Position
;; Signed 16.8 fractional integer
xPos .res 3
yPos .res 3
;; Frame counter for animations
;; word because it is used in 16 bit Mode.
animationCounter .byte
;; The direction the NPC is facing
;; If 0, then on left, if 1 on right
facingLeftOnZero .byte
;; chatacter's frame
;; 0 = stand, 1 = walk, 2 = wait
frame .byte
;; Current feelings
;; (normal, stressed, angry)
feelings .byte
;; Timeout to next feeling change
feelingsTimeout .word
;; MetaSprite charAttr diff pointer
spriteCharAttr .word
;; Location of the MetaSprite Table.
spriteFrameTablePtr .addr
;; MetaSprite Frame Location
spriteFramePtr .word
;; NPC directkly in front of this one. 0 If at head of line
nextNpcInLine .addr
;; Frame timer for enter/exit elevator state
stateTimer .byte
.endstruct
.segment "SHADOW"
STRUCT npcs, NpcStruct, N_NPCS
;; A pointer to the next free NPC
ADDR nextFreeNpcPtr
;; A frame countdown to the next NPC sprite
SINT16 countdownToNextNpc
;; Subtracted from each `npc.feelingsTimeout` every frame
;; Increases every point, adds difficulty curve
SINT16 feelingsSpeed
;; Strike Animation variables
;;; animation frame number (as a muliple of 2)
ADDR strike_frame
;;; current frame number
BYTE strike_frameTimeout
;;; The NPC the strike is for
WORD strike_npc
;;; If 0 then hide NPCs arrow
BYTE strike_hideArrowsOnZero
.rodata
LABEL NpcStateTable
.addr 0
.addr ContinueWalkToElevator
.addr ContinueEnterElevator
.addr ContinueWaitDoorClose
.addr ContinueLimbo
.addr ContinueWaitDoorOpen
.addr ContinueExitElevator
.addr ContinueWalkOffscreen
.code
.A8
.I16
ROUTINE Init
;; ::BUGFIX previous games NPCs still visible ::
;; ::: Have ABSOLUTELY NO CLUE why the old code didn't work. ::
;; ::: Just gave up after 20 mins and clear all the memory assosiated with NPCs ::
MemClear npcs
LDX #NPC_FEELINGS_SPEED
STX feelingsSpeed
LDX #1
STX countdownToNextNpc
RTS
; inline routine that draws the NPC to the screen
; dp = npc
.macro Process_DrawNpc
.endmacro
.A8
.I16
ROUTINE DrawSprites
; for dp in npcs
; if dp.state != NPC_DEAD && dp.state != NPC_LIMBO
; MetaSprite__ProcessMetaSprite_Y(npc.xpos, npc.ypos, npc.spriteCharAttr, npc.spriteFramePtr)
PHD
REP #$30
.A16
LDA #npcs
REPEAT
TCD
.assert NPC_DEAD = 0, error, "NPC_DEAD != 0"
LDX NpcStruct::state
IF_NOT_ZERO
LDX NpcStruct::state
CPX #NPC_LIMBO
IF_NE
SEP #$20
.A8
LDY NpcStruct::xPos + 1
STY MetaSprite__xPos
LDY NpcStruct::yPos + 1
STY MetaSprite__yPos
LDY NpcStruct::spriteCharAttr
LDX NpcStruct::spriteFramePtr
JSR MetaSprite__ProcessMetaSprite_Y
REP #$30
ENDIF
.A16
ENDIF
TDC
ADD #.sizeof(NpcStruct)
CMP #npcs + N_NPCS * .sizeof(NpcStruct)
UNTIL_GE
SEP #$20
.A8
PLD
RTS
.A8
.I16
ROUTINE Process
; for dp in npcs
; if dp.state == NPC_DEAD
; nextFreeNpcPtr = dp
; else
; NpcStateTable[dp.state](dp)
;
; if --countdownToNextNpc == 0
; Spawn()
; contdownToNextNpc = random(MIN_SPAWN_COUNTDOWN, MAX_SPAWN_COUNTDOWN)
PHD
REP #$30
.A16
.I16
LDA #npcs
REPEAT
TCD
.assert NPC_DEAD = 0, error, "NPC_DEAD != 0"
LDX NpcStruct::state
IF_ZERO
STA nextFreeNpcPtr
ELSE
SEP #$20
.A8
JSR (.loword(NpcStateTable), X)
REP #$30
ENDIF
.A16
TDC
ADD #.sizeof(NpcStruct)
CMP #npcs + N_NPCS * .sizeof(NpcStruct)
UNTIL_GE
.A16
DEC countdownToNextNpc
SEP #$20
.A8
IF_ZERO
; subtraction overflow
JSR Spawn
LDX #MIN_SPAWN_COUNTDOWN
LDY #MAX_SPAWN_COUNTDOWN
JSR Random__Rnd_U16X_U16Y
STY countdownToNextNpc
ENDIF
PLD
RTS
; A = elevator floor
; X = npc
.A8
.I16
ROUTINE OccupiedElevatorDoorOpening
; x->yPos = floor * ELEVATOR_FLOOR_COLUMN_SPACING * 8 + NPC_ELEVATOR_YPOS
; x->state = NPC_WAIT_DOOR_OPEN
PHX
TAY
LDX #ELEVATOR_FLOOR_COLUMN_SPACING * 8
JSR Math__Multiply_U8Y_U8X_UY
TYA
ADD #NPC_ELEVATOR_YPOS
PLX
STA a:NpcStruct::yPos + 1, X
LDA #NPC_WAIT_DOOR_OPEN
STA a:NpcStruct::state, X
RTS
; A = elevator floor
; X = npc
.A8
.I16
ROUTINE OccupiedElevatorOpen
; npc = X
; if npc.targetFloor == elevatorFloor
; SetExitElevator()
; else
; SetWrongFloor()
PHD
PHA
REP #$30
.A16
TXA
TCD
SEP #$20
.A8
PLA
CMP NpcStruct::targetFloor
IF_EQ
JSR SetExitElevator
ELSE
JSR SetWrongFloor
ENDIF
PLD
RTS
; OUTPUT DP = new NPC
.A8
.I16
ROUTINE Spawn
; if !nextFreeNpc
; return
;
; npc = nextFreeNpcPtr
; nextFreeNpcPtr = 0
;
;
; npc.floor = Random_Rnd(4)
; npc.targetFloor = (npc.floor + Random_Rnd(3) + 1) AND 3
;
; npc.leftSideOnZero = Random_Rnd(2)
; npc.facingLeftOnZero = npc.leftSideOnZero
; if leftSideOnZero == 0
; npc.xPos = NPC_LEFT_XSTART
; else
; npc.xPos = NPC_RIGHT_XSTART
; npc.yPos = npc.floor * ELEVATOR_FLOOR_COLUMN_SPACING * 8 + NPC_YSTART
; npc.animationCounter = NPC_MOVE_FRAME_DELAY
; npc.frame = 0
; npc.feelings = 0
; npc.feelingsTimeout = NPC_FEELINGS_TIMEOUT
;
; ::TODO more than 1 sprite::
; npc.spriteCharAttr = businessManCharAttr
; npc.spriteTablePtr = MetaSprite_businessMan
; CalculateSpriteFramePtr()
;
; // determine the next sprite in line
; y = 0 // best so far.
; for x in npcs
; if x->state == NPC_WALK_TO_ELEVATOR && x->side == npc.side && x->floor == npc.floor
; if y == 0
; y = x
; else if leftSideOnZero == 0
; if x->xPos < y->xPos
; y = x
; else
; if x->xPos >= y->xPos
; y = x
; npc.nextNpcInLine = y
;
; // set state last so it doesn't interfear with with search above.
; npc.state = NPC_WALK_TO_ELEVATOR
REP #$30
.A16
LDA nextFreeNpcPtr
IF_ZERO
SEP #$20
RTS
ENDIF
TCD
STZ nextFreeNpcPtr
SEP #$20
.A8
.assert N_FLOORS = 4, error, "Bad value"
JSR Random__Rnd_4
STA NpcStruct::floor
JSR Random__Rnd_3
SEC
ADC NpcStruct::floor
AND #$03
STA NpcStruct::targetFloor
JSR Random__Rnd_2
IF_NOT_ZERO
LDA #$FF
ENDIF
STA NpcStruct::leftSideOnZero
STA NpcStruct::facingLeftOnZero
LDA NpcStruct::leftSideOnZero
IF_ZERO
LDY #.loword(NPC_LEFT_XSTART)
ELSE
LDY #.loword(NPC_RIGHT_XSTART)
ENDIF
STY NpcStruct::xPos + 1
STZ NpcStruct::xPos
LDX #ELEVATOR_FLOOR_COLUMN_SPACING * 8
LDY NpcStruct::floor
JSR Math__Multiply_U8Y_U8X_UY
TYA
ADD #NPC_YSTART
STA NpcStruct::yPos + 1
STZ NpcStruct::yPos + 2
STZ NpcStruct::yPos + 0
LDA #NPC_MOVE_FRAME_DELAY
STA NpcStruct::animationCounter
STZ NpcStruct::frame
STZ NpcStruct::feelings
LDY #NPC_FEELINGS_TIMEOUT
STY NpcStruct::feelingsTimeout
; ::TODO random NPC sprite::
LDY Npcs_SpriteCharAttr
STY NpcStruct::spriteCharAttr
LDX Npcs_SpriteFrameTablePtr
STX NpcStruct::spriteFrameTablePtr
JSR CalculateSpriteFramePtr
; determine next sprite in line
; ::SHOULDO update `structure.inc` so this is neater::
; ::: (possibly ELSE_IF <check code> IF_* , AND_IF <check code> IF_* ?)::
LDY #0
LDX #npcs
REPEAT
.A8
LDA a:NpcStruct::state, x
CMP #NPC_WALK_TO_ELEVATOR
IF_EQ
LDA a:NpcStruct::leftSideOnZero, X
CMP NpcStruct::leftSideOnZero
IF_EQ
LDA a:NpcStruct::floor, X
CMP NpcStruct::floor
IF_EQ
CPY #0
IF_EQ
TXY
ELSE
LDA a:NpcStruct::leftSideOnZero, X
REP #$20
.A16
IF_ZERO
; on left
LDA a:NpcStruct::xPos + 1, X
CMP a:NpcStruct::xPos + 1, Y
IF_SLT
TXY
ENDIF
ELSE
; on right
LDA a:NpcStruct::xPos + 1, X
CMP a:NpcStruct::xPos + 1, Y
IF_SGE
TXY
ENDIF
ENDIF
SEP #$20
.A8
ENDIF
ENDIF
ENDIF
ENDIF
REP #$30
.A16
TXA
ADD #.sizeof(NpcStruct)
TAX
SEP #$20
.A8
CPX #npcs + N_NPCS * .sizeof(NpcStruct)
UNTIL_GE
STY NpcStruct::nextNpcInLine
LDY #NPC_WALK_TO_ELEVATOR
STY NpcStruct::state
RTS
; DP = npc
.A8
.I16
ROUTINE ContinueWalkToElevator
; if npc.leftSideOnZero == 0
; nextNpcInLine = npc.nextNpcInLine
; if nextNpcInLine != 0 && nextNpcInLine->state != NPC_WALK_TO_ELEVATOR
; // now at the front of line
; npc.nextNpcInLine = 0
; if npc.nextNpcInLine == 0 || npc.xPos + NPC_LINE_SPACING < nextNpcInLine.xPos
; // no NPC directly in front of us
; if npc.xPos < NPC_LEFT_WAIT_POS
; npc.xPos += NPC_WALK_SPEED
; ProcessWalkAnimation()
; return
; else
; c = Elevators__NpcEnterElevator(npc, npc.floor, npc.leftSideOnZero)
; if c
; SetEnterElevator()
; else
; // on right side
; nextNpcInLine = npc.nextNpcInLine
; if nextNpcInLine != 0 && nextNpcInLine->state != NPC_WALK_TO_ELEVATOR
; // now at the front of line
; npc.nextNpcInLine = 0
; if npc.nextNpcInLine == 0 || npc.xPos - NPC_LINE_SPACING > nextNpcInLine.xPos
; // no NPC directly in front of us
; if npc.xPos > NPC_RIGHT_WAIT_POS
; npc.xPos -= NPC_WALK_SPEED
; ProcessWalkAnimation()
; return
; else
; c = Elevators__NpcEnterElevator(npc, npc.floor, npc.leftSideOnZero)
; if c
; SetEnterElevator()
;
; WaitingInLine()
LDA NpcStruct::leftSideOnZero
IF_ZERO
; Check if in line
LDX NpcStruct::nextNpcInLine
BEQ ContinueWalkToElevator_SkipLeftLineCheck
; Check if in the NPC in front of us has left the line
LDY a:NpcStruct::state, X
CPY #NPC_WALK_TO_ELEVATOR
IF_NE
LDX #0
STX NpcStruct::nextNpcInLine
BRA ContinueWalkToElevator_SkipLeftLineCheck
ENDIF
REP #$30
.A16
; remember xPos is a 16.8 fractional integer
LDA NpcStruct::xPos + 1
ADD #NPC_LINE_SPACING
CMP a:NpcStruct::xPos + 1, X
IF_SLT
ContinueWalkToElevator_SkipLeftLineCheck:
REP #$30
.A16
; There is no other NPC directly in front of us.
LDA NpcStruct::xPos + 1
CMP #NPC_LEFT_WAIT_XPOS
IF_SLT
LDA NpcStruct::xPos
ADD #NPC_WALK_SPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
ADC #0
STA NpcStruct::xPos + 2
JMP ProcessWalkAnimation
ENDIF
.A16
SEP #$20
CLC
.A8
LDA NpcStruct::floor
JSR Elevators__NpcEnterElevator
IF_C_SET
JMP SetEnterElevator
ENDIF
ENDIF
SEP #$20
.A8
ELSE
; on right side
; Check if in line
LDX NpcStruct::nextNpcInLine
BEQ ContinueWalkToElevator_SkipRightLineCheck
; Check if in the NPC in front of us has left the line
LDY a:NpcStruct::state, X
CPY #NPC_WALK_TO_ELEVATOR
IF_NE
LDX #0
STX NpcStruct::nextNpcInLine
BRA ContinueWalkToElevator_SkipRightLineCheck
ENDIF
REP #$30
.A16
; remember xPos is a 16.8 fractional integer
LDA NpcStruct::xPos + 1
SUB #NPC_LINE_SPACING + 1
CMP a:NpcStruct::xPos + 1, X
IF_SGE
ContinueWalkToElevator_SkipRightLineCheck:
REP #$30
.A16
; There is no other NPC directly in front of us.
LDA NpcStruct::xPos + 1
CMP #NPC_RIGHT_WAIT_XPOS + 1
IF_SGE
LDA NpcStruct::xPos
SUB #NPC_WALK_SPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
SBC #0
STA NpcStruct::xPos + 2
JMP ProcessWalkAnimation
ENDIF
.A16
SEP #$21 ; c set if on right
.A8
LDA NpcStruct::floor
JSR Elevators__NpcEnterElevator
IF_C_SET
JMP SetEnterElevator
ENDIF
ENDIF
SEP #$20
.A8
ENDIF
.assert * = WaitingInLine, lderror, "Bad Flow"
; DP = npc
.A8
.I16
ROUTINE WaitingInLine
; // waiting
; if npc.feelings != NPC_FEELING_FIGHTING
; npc.feelingsTimeout -= feelingsSpeed
; if npc.feelingsTimeout < 0
; npc.feelings++
; npc.feelingTimeout = NPC_FEELINGS_TIMEOUT
; CalculateSpriteFramePtr()
; else
; if npc.nextNpcInLine
; SetFighting()
JSR ProcessWaitAnimation
LDA NpcStruct::feelings
CMP #NPC_FEELINGS_FIGHTING
IF_NE
REP #$30
.A16
LDA NpcStruct::feelingsTimeout
SUB feelingsSpeed
STA NpcStruct::feelingsTimeout
SEP #$20
.A8
IF_C_CLEAR
; subtraction underflow
INC NpcStruct::feelings
LDY #NPC_FEELINGS_TIMEOUT
STY NpcStruct::feelingsTimeout
JMP CalculateSpriteFramePtr
ENDIF
ELSE
LDX NpcStruct::nextNpcInLine
IF_NOT_ZERO
JMP SetFighting
ENDIF
ENDIF
RTS
; DP = npc
.A8
.I16
ROUTINE SetEnterElevator
; npc.state = NPC_EXIT_ELEVATOR
; npc.stateTimer = NPC_ENTER_ELEVATOR_FRAMES
; npc.DrawArrows()
LDX #NPC_ENTER_ELEVATOR
STX NpcStruct::state
LDA #NPC_ENTER_ELEVATOR_FRAMES
STA NpcStruct::stateTimer
JMP DrawArrows
; DP = npc
.A8
.I16
ROUTINE ContinueEnterElevator
; if --npc.stateTimer == 0
; SetWaitDoorClose()
; else
; if npc.leftSideOnZero == 0
; npc.xPos += NPC_ENTER_ELEVATOR_XSPEED
; else
; npc.xPos -= NPC_ENTER_ELEVATOR_XSPEED
; npc.yPos -= NPC_ENTER_ELEVATOR_YSPEED
; ProcessWalkAnimation()
DEC NpcStruct::stateTimer
BEQ SetWaitDoorClose
LDA NpcStruct::leftSideOnZero
IF_ZERO
; left
REP #$30
.A16
LDA NpcStruct::xPos
ADD #NPC_ENTER_ELEVATOR_XSPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
ADC #0
STA NpcStruct::xPos + 2
ELSE
; right
REP #$30
.A16
LDA NpcStruct::xPos
SUB #NPC_ENTER_ELEVATOR_XSPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
SBC #0
STA NpcStruct::xPos + 2
ENDIF
REP #$30
.A16
LDA NpcStruct::yPos
SUB #NPC_ENTER_ELEVATOR_YSPEED
STA NpcStruct::yPos
SEP #$20
.A8
LDA NpcStruct::yPos + 2
SBC #0
STA NpcStruct::yPos + 2
JMP ProcessWalkAnimation
; DP = npc
.A8
.I16
ROUTINE SetWaitDoorClose
; npc.state = NPC_WAIT_DOOR_CLOSE
; set npc.spriteCharAttr Order to 2 (behind doors)
; npc.facingLeftOnZero = !npc.leftSideOnZero
; npc.frame = 0
; npc.feelingsTimeout = 0xFFFF
; CalculateSpriteFramePtr()
;
; Elevators__NpcInsideElevator(npc, npc.leftSideOnZero)
LDX #NPC_WAIT_DOOR_CLOSE
STX NpcStruct::state
; Change Order of MetaSprite so it is behind elevator doors
LDA NpcStruct::spriteCharAttr + 1
AND #.lobyte(~OAM_ATTR_ORDER_MASK)
ORA #1 << OAM_ATTR_ORDER_SHIFT
STA NpcStruct::spriteCharAttr + 1
LDA NpcStruct::leftSideOnZero
EOR #$FF
STA NpcStruct::facingLeftOnZero
STZ NpcStruct::frame
LDY #$FFFF
STY NpcStruct::feelingsTimeout
JSR CalculateSpriteFramePtr
LDA NpcStruct::leftSideOnZero
ASL
JMP Elevators__NpcInsideElevator
; DP = npc
.A8
.I16
ROUTINE ContinueWaitDoorClose
JMP WaitingInLine
; DP = npc
.A8
.I16
ROUTINE ContinueWaitDoorOpen
ROUTINE ContinueLimbo
RTS
; A = floor
; DP = npc
.A8
.I16
ROUTINE SetExitElevator
; x->state = NPC_EXIT_ELEVATOR
; x->stateTimer = NPC_EXIT_ELEVATOR_FRAMES
; x->animationCounter = 1
; set x->spriteCharAttr Order to 3 (in front of everything)
; npc.ClearArrows()
LDA #NPC_EXIT_ELEVATOR
STA NpcStruct::state
LDA #NPC_EXIT_ELEVATOR_FRAMES
STA NpcStruct::stateTimer
LDA #1
STA NpcStruct::animationCounter
; Make sprite in front of everything.
LDA NpcStruct::spriteCharAttr + 1
ORA #3 << OAM_ATTR_ORDER_SHIFT
STA NpcStruct::spriteCharAttr + 1
JMP ClearArrows
; DP = npc
.A8
.I16
ROUTINE ContinueExitElevator
; if --npc.stateTimer == 0
; SetWalkOffscreen()
; else
; if npc.leftSideOnZero == 0
; npc.xPos -= NPC_EXIT_ELEVATOR_XSPEED
; else
; npc.xPos += NPC_EXIT_ELEVATOR_XSPEED
; npc.yPos += NPC_EXIT_ELEVATOR_YSPEED
; ProcessWalkAnimation()
DEC NpcStruct::stateTimer
BEQ SetWalkOffscreen
LDA NpcStruct::leftSideOnZero
IF_ZERO
REP #$30
.A16
LDA NpcStruct::xPos
SUB #NPC_EXIT_ELEVATOR_XSPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
SBC #0
STA NpcStruct::xPos + 2
ELSE
REP #$30
.A16
LDA NpcStruct::xPos
ADD #NPC_EXIT_ELEVATOR_XSPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
ADC #0
STA NpcStruct::xPos + 2
ENDIF
REP #$30
.A16
LDA NpcStruct::yPos
ADD #NPC_EXIT_ELEVATOR_YSPEED
STA NpcStruct::yPos
SEP #$20
.A8
LDA NpcStruct::yPos + 2
ADD #0
STA NpcStruct::yPos + 2
JMP ProcessWalkAnimation
; DP = npc
.A8
.I16
ROUTINE SetWalkOffscreen
LDX #NPC_WALK_OFFSCREEN
STX NpcStruct::state
RTS
.A8
.I16
ROUTINE ContinueWalkOffscreen
; if npc.leftSideOnZero == 0
; // on left side, walking right
; if npc.xPos >= NPC_LEFT_OFFSCREEN_XPOS
; npc.xPos -= NPC_WALK_OFFSCREEN_SPEED
; ProcessWalkAnimation()
; return
; else
; NpcOffscreen()
; else
; // on right side, walking left
; if npc.xPos < NPC_RIGHT_OFFSCREEN_XPOS
; npc.xPos += NPC_WALK_OFFSCREEN_SPEED
; ProcessWalkAnimation()
; return
; else
; NpcOffscreen()
LDA NpcStruct::leftSideOnZero
IF_ZERO
REP #$30
.A16
LDA NpcStruct::xPos + 1
CMP #.loword(NPC_LEFT_OFFSCREEN_XPOS)
IF_SGE
LDA NpcStruct::xPos
SUB #NPC_WALK_OFFSCREEN_SPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
SBC #0
STA NpcStruct::xPos + 2
JMP ProcessWalkAnimation
ENDIF
.A16
SEP #$20
.A8
BRA NpcOffscreen
ELSE
REP #$30
.A16
LDA NpcStruct::xPos + 1
CMP #.loword(NPC_RIGHT_OFFSCREEN_XPOS + 1)
IF_SLT
LDA NpcStruct::xPos
ADD #NPC_WALK_OFFSCREEN_SPEED
STA NpcStruct::xPos
SEP #$20
.A8
LDA NpcStruct::xPos + 2
ADC #0
STA NpcStruct::xPos + 2
JMP ProcessWalkAnimation
ENDIF
.A16
SEP #$20
.A8
BRA NpcOffscreen
ENDIF
; DP = npc
.A8