638
639draw_entities:
640 mov si, _ENTITIES_
641 mov byte cl, [_MAX_ENTITIES_]
642 .next:
643 push cx
644 push si
645
646 cmp byte [si+_STATE_], STATE_DEACTIVATED
647 jz .skip_entity
648
649 test byte [_GAME_STATE_], GSTATE_PREGAME
650 jnz .hide_player
651 test byte [_GAME_STATE_], GSTATE_POSTGAME
652 jnz .hide_player
653 jmp .skip_hide_player
654 .hide_player:
655 cmp byte [si+_ID_], ID_PLAYER
656 jz .skip_entity
657 cmp byte [si+_ID_], ID_CHEST
658 jz .skip_entity
659 .skip_hide_player:
660
662 mov ax, [si+_POS_OLD_]
663 mov cx, [si+_POS_]
664 cmp cx, ax
665 jz .in_position
666
667 xor bx, bx
668
669 cmp al, cl
670 jl .move_left
671 jg .move_right
672 cmp ah, ch
673 jl .move_down
674 jg .move_up
675
676 jmp .in_position
677
678 .move_left:
679 add bx, ENTITIES_SPEED
680 jmp .save_move
681
682 .move_right:
683 sub bx, ENTITIES_SPEED
684 jmp .save_move
685
686 .move_down:
687 add bx, 320*ENTITIES_SPEED
688 jmp .save_move
689
690 .move_up:
691 sub bx, 320*ENTITIES_SPEED
692 jmp .save_move
693
694 .save_move:
695 mov cx, [si+_POS_]
696 call conv_pos2mem
697 mov dx, di
698 add [si+_SCREEN_POS_], bx
699 mov di, [si+_SCREEN_POS_]
700 cmp dx, di
701 jnz .pos_calculated
702 mov cx, [si+_POS_]
703 mov [si+_POS_OLD_], cx
704 mov byte [si+_ANIM_], 0x0
705 cmp byte [si+_ID_], ID_PLAYER
706 jnz .skip_step_beep
707 mov bl, BEEP_STEP
708 call beep
709 .skip_step_beep:
710
711
712 .in_position:
713 call conv_pos2mem
714 .pos_calculated:
715 cmp byte [si+_STATE_], STATE_FOLLOW
716 jnz .skip_follow
717 push si
718 mov si, [_PLAYER_ENTITY_ID_]
719 mov cx, [si+_POS_]
720 mov di, [si+_SCREEN_POS_]
721 sub di, 320*14
722 pop si
723 mov word [si+_POS_], cx
724 jmp .skip_draw_shadow
725 .skip_follow:
726
727
728 .draw_shadow:
729 test byte [si+_STATE_], STATE_EXPLORING
730 jnz .skip_draw_shadow
731 cmp byte [si+_ID_], ID_PLAYER
732 jz .skip_draw_shadow
733 cmp byte [si+_ID_], ID_BRIDGE
734 jz .skip_draw_shadow
735 push si
736 push di
737 mov si, ShadowBrush
738 add di, 320*5+1
739 call draw_sprite
740 pop di
741 pop si
742 .skip_draw_shadow:
743
744 mov byte al, [si]
745 mov ah, al
746
747 shl al, 0x2
748 mov bx, BrushRefs
749 add bl, al
750 mov dx, [bx]
751
752 push dx
753
754 add al, 0x2
755 movzx bx, al
756 add di, [BrushRefs + bx]
757 mov dl, [si+_MIRROR_]
758
759 cmp ah, ID_PLAYER
760 jnz .skip_player_anim
761 mov ax, [si+_POS_]
762 cmp ax, [si+_POS_OLD_]
763 mov ah, ID_PLAYER
764 jz .skip_player_anim
765 xor byte [si+_ANIM_], 0x1
766 .skip_player_anim:
767
768 mov dh, [si+_ANIM_]
769
770 pop si
771 call draw_sprite
772
773 cmp ah, ID_PLAYER
774 jnz .skip_player_draw
775 mov si, IndieTopBrush
776 sub di, 320*4
777
778 cmp dh, 0x1
779 jnz .skip_anim_move
780 add di, 320
781 .skip_anim_move:
782
783 cmp byte [_HOLDING_ID_], 0x0
784 jz .skip_player_holding
785 mov si, IndieTop2Brush
786 .skip_player_holding:
787
788 xor dh, dh
789 call draw_sprite
790
791 cmp byte [_WEB_LOCKED_], 0
792 jz .skip_web_draw
793 mov si, WebBrush
794 add di, 320*6
795 call draw_sprite
796 .skip_web_draw:
797 .skip_player_draw:
798
799 cmp ah, ID_GOLD
800 jnz .skip_gold_draw
801 mov ax, [_GAME_TICK_]
802 add ax, cx
803 and ax, 0x4
804 cmp ax, 0x2
805 jl .skip_gold_draw
806 xor dx, dx
807 mov si, GoldBrush
808 call draw_sprite
809 .skip_gold_draw:
810
811 cmp ah, ID_CRAB
812 jnz .skip_crab
813 mov dx, 0
814 mov si, CrabClawBrush
815 add di, 8
816 call draw_sprite
817 mov dx, 1
818 sub di, 320+16
819 call draw_sprite
820 .skip_crab:
821
822 cmp ah, ID_CHEST
823 jnz .skip_chest
824 xor dx,dx
825 cmp byte [_HOLDING_ID_], ID_GOLD
826 jnz .skip_open_chest
827 mov si, ChestTopBrush
828 sub di, 320*3+8
829 call draw_sprite
830
831 mov si, ArrowBrush
832 sub di, 320*8-8
833 mov ax, [_GAME_TICK_]
834 and ax, 0x1
835 imul ax, 320*2
836 add di, ax
837 call draw_sprite
838 jmp .skip_chest
839 .skip_open_chest:
840 mov si, ChestCloseBrush
841 sub di, 320
842 call draw_sprite
843 .skip_chest:
844
845 .skip_entity:
846 pop si
847 add si, ENTITY_SIZE
848 pop cx
849 dec cx
850 jg .next
851
; screen pos in DI
; Load player position into CX (Y in CH, X in CL)
; Move above player
; Save new position to holding item
; Get brush id in AL
; Save a copy in AH
; Get brush reference table
; Shift to ref (id*2 bytes)
; Get brush data address
; Save address for SI
; offest is at next byte (+2)
; Get address to BX
; Get shift and apply to destination position
; Get brush mirror flag
; Get anination frame
; Get address
; move head down on second frame
; no mirror