Up to 4 NPC Tiles on one screen without using monsters (Tested [4.1.5])

Post Reply
User avatar
chronicleroflegends
Posts: 180
Joined: Thu Sep 06, 2018 3:51 am

Up to 4 NPC Tiles on one screen without using monsters (Tested [4.1.5])

Post by chronicleroflegends » Thu Feb 14, 2019 12:57 am

Here is a script I made that lets you use the NPC ENGAGE tile to show any of the 4 text entries, not just the first one.

Should be useful to anybody wanting to add more text to their game, without using up monsters as NPCS.

EDIT: I made an error when I posted. You do not replace your NPC engage tile script with this one. This is an INPUT script, you put it on the button you use to
activate/read/talk to npc.

Code: Select all

;; MODIFIED ACTIVATE TEXTBOX SCRIPT
;; BY CHRONICLER OF LEGENDS
;; Allows the NPC tile to use all 4 text entries in a group instead of just the first.
;;
;; Monster NPC placement takes priority over Tile NPC.
;; So for example, if you want a monster in the bottom left corner to have text entry 2, you can still place that
;; NPC as monster 2 and it will work.
;;
;; REQUIREMENTS:
;; 2 Constants:
;; NPCTILE_HSPLIT - horizontal position (in decimal) on screen to divide between left and right side
;; NPCTILE_VSPLIT - vertical position (in decimal) on screen to divide top and bottom.
;; OPTIONAL:
;; If you want it to more accurately check players position, add these constants, and set them to roughly center of your player object:
;; PLR_HCENTEROFFSET - How many pixels from the left players center is
;; PLR_VCENTEROFFSET - How many pixels from the top players center is
;; if you do not use them, be sure to comment out the lines below where they are added.
;; 
;; HOW IT WORKS:
;; You can place Monster NPCS anywhere on the screen like normal, that behavior is unchanged.
;; For NPC Tiles, Whether you place them in your top left, top right, bottom left, or bottom right sections of the
;; screen determines which text entry in the text group they will display.

;;   1  ||  2
;;      ||
;;  ==========
;;      ||
;;   3  ||  4

;; ===============================================================================================================

;;; This script is designed to work with a button press or release event.
;;; The latter part of the code could be used at any time with any 
;;; conditional that could be turned off after firing if you wanted to draw
;;; a textbox that was not in conjunction with a button press.

;;; It will look at the screen's text group and use what is in the variable textVar as an index.
;;; If textVar is 0, it will activate the first text string in the currently loaded string group for the screen.
;;; If textVar is 1, it will activate the second text string.  Etc etc etc.
      
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PART 1: Determine if the text box is already drawn          
;; Especially when using button commands to activate a textbox, we want the first push
;; to activate it, while the second push begins the deactivate process.
;; Bit 4 determines if the box is currently drawn to screen or if there is no box
;; on screen, which tells the game whether to start the box-draw, or start the
;; restoration of nametable draw.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        LDA textboxHandler
        AND #%00010000               
        BEQ checkToTurnTheTextboxOn ;; start textbox
        ;; start nametable restoration
        ;; first, disable input:
        LDA gameHandler
        ORA #%00100000
        STA gameHandler
        ;; Then zero out offsets in case they are not set to zero.
        LDA #$00
        STA updateNT_offset
        STA updateNT_H_offset
        STA updateNT_V_offset
        ;;; flipping bit 7 starts the textbox code on next frame.
        ;;; Also flipping bit 3 puts it in "restore nametable" mode.
        LDA #%10001000
        STA textboxHandler
        ;;; Return from subroutine - textbox is now being
        ;;; overwritten by nametable data.
        RTS
       
    checkToTurnTheTextboxOn:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PART 2: Check for NPC collision
;; In most standard NPC cases, you want to check an npc_collision flag
;; to see if you are colliding with an NPC or not.  This flag gets set in the
;; Object collision scripts if the object you are colliding with an object tagged
;; as an NPC. 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;       
        LDA npc_collision
        BEQ doneWithTextboxToggle ;; if it is zero, skip turning on textbox.
        
;; Decide which text entry to use
        ;;Where is the player?
        LDY player1_object ;Get the player object in Y
        LDA Object_x_hi,y ;Get the player's horizontal position
        ADC #PLR_HCENTEROFFSET ; COMMENT THIS OUT IF YOU DONT WANT THE OFFSET
        STA temp
        LDA Object_y_hi,y ;Get the player's horizontal position
        ADC #PLR_VCENTEROFFSET ; COMMENT THIS OUT IF YOU DONT WANT THE OFFSET
        STA temp1
        
        ;;Left or Right side of screen
        LDA temp ;Get the player's position
        CMP #NPCTILE_HSPLIT
        BCC npcIsOnLeftSide
        JMP npcIsOnRightSide
        
    npcIsOnLeftSide:
        ;; Top or bottom of screen?
        LDA temp1
        CMP #NPCTILE_VSPLIT
        BCC npcIsTopLeft
        LDA #$02    ;; Bottom Left, third text entry
        STA textVar
        JMP skipNpcLocationCheck
        
    npcIsOnRightSide:
        ;; Top or bottom of screen?
        LDA temp1
        CMP #NPCTILE_VSPLIT
        BCC npcIsTopRight
        LDA #$03    ;; Bottom Right, fourth text entry
        STA textVar
        JMP skipNpcLocationCheck
        
    npcIsTopLeft:
        LDA #$00    ;; Top Left, first text entry
        STA textVar
        JMP skipNpcLocationCheck
        
    npcIsTopRight:
        LDA #$01    ;; Top Right, Second text entry
        STA textVar
    
    skipNpcLocationCheck:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PART 3: Turn on textbox.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; if it is already in the process of loading, do not turn it on.
        LDA textboxHandler
        AND #%10000000
        BNE doneWithTextboxToggle
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; Disable input while textbox is loading.
        LDA gameHandler
        ORA #%00100000
        STA gameHandler
    turnTheTextboxOn:
        ;; Flipping this bit starts the textbox drawing process.
        LDA #%10000000
        STA textboxHandler
        
    doneWithTextboxToggle:
    ;; if this was used with an input, it needs to return from the subroutine.
        RTS
    
    RTS
Last edited by chronicleroflegends on Thu Feb 14, 2019 8:28 pm, edited 1 time in total.
~Do you believe in legends? ~
My Games: Nix: The Paradox Relic
User avatar
jsherman
Posts: 296
Joined: Sun Apr 22, 2018 11:25 am
Location: Cleveland OH

Re: Up to 4 NPC Tiles on one screen without using monsters (Tested [4.1.5])

Post by jsherman » Thu Feb 14, 2019 1:05 am

Clever!
"Turtle Rescue" updates can be found here: viewtopic.php?f=13&t=112
For more in-depth updates, please follow GossipTurtle on Twitter! https://twitter.com/TurtleRescueNES
User avatar
BentPawGames
Posts: 162
Joined: Wed Jan 16, 2019 10:29 pm

Re: Up to 4 NPC Tiles on one screen without using monsters (Tested [4.1.5])

Post by BentPawGames » Thu Feb 14, 2019 7:21 am

Handy! thank you!
User avatar
dale_coop
Posts: 3486
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Up to 4 NPC Tiles on one screen without using monsters (Tested [4.1.5])

Post by dale_coop » Thu Feb 14, 2019 10:35 am

Nice script! Sounds very useful <3
Thank you, chronicleoflegends!
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
Post Reply