Breakable "Trigger Tile" Solution

tbizzle

Well-known member
Here is my solution for a breakable tile that once you break it and leave the screen, it will remain gone. Other breakable tiles will reappear after you leave the screen and come back, it won't be "triggered" and stay gone. So here is what we shall do:

Step 1: Enable Monster Bits into your project by following this tutorial: https://www.nesmakers.com/index.php?threads/4-5-9-adding-monster-bits-back-in.7682/#post-42944

Step 2: We need to create a "breakable Block". For this we will use a monster and we will make it 16x16 pixels. No need to give it any animation or AI steps, but give it a full 16x16 bounding box and make it look like a block you'd like to break. Also we will check its monster flag to "NPC".

Step 3: Next we need to go into "doHandleObjectCollisions.asm". Right around line 83, right underneath this bit of code

Code:
LDA Object_status,x
AND #%10000000
BNE +isActive
JMP +skipCollision
    +isActive:

Insert this bit of code:

Code:
LDY Object_type,x
LDA MonsterBits,y
AND #%00000100 ;;;;This bit is the top "check box/bit" for monster bits
BEQ NES
LDA Object_flags,x
AND #%10001000
JMP moooo
    NES:

Now underneath this bit of code at around line 92:

Code:
LDA Object_flags,x
AND #%00001000

Insert this last little line of code:

Code:
moooo:

Now go to your breakable NPC tile and check its monster bits box to observe player weapon collision:
Monster Animation Info 3_22_2024 3_53_06 AM.png

Next lets make this NPC breakable object not have text abilities either. To do this go to the "doDrawBox.asm" file. Right underneath this line of code at line 1

Code:
doDrawBox:

Insert this bit of code:

Code:
LDY Object_type,x
    LDA MonsterBits,y
    AND #%00000010 ;;;;This bit is the top "check box/bit" for monster bits
    BEQ poot55
    RTS
    poot55:

Now let us go back to our breakable NPC object and check this monster bit:
Monster Animation Info 3_22_2024 4_00_11 AM.png

Now the NPC object will not be able to bring up NPC text. It will just act as a solid block, when collided with by a player weapon will be destroyed! Now to give it a destroy animation and trigger the screen so it stays destroyed when you leave the screen and come back. To do this go to "doHandleHurtMonster.asm". Right after

Code:
DestroyObject

insert this bit of code:

Code:
LDA Object_flags,x
AND #%10000000
BEQ kid           
CreateObjectOnScreen tempA, tempB, #$0F, #$00, tempD
TriggerScreen screenType       
JMP +doSkipHurtingThisObject
    kid:

Now the Breakable NPC object will reamain broken when you leave, then return back to the screen!

I hope you find this useful! Enjoy!
 
Last edited:

tbizzle

Well-known member
There is one thing that is off. The Breakable Block object when placed in a row, is one pixel lower than actual tiles. @dale_coop do you know if there is anywhere in the code where a monster's placement on the screen can be adjusted by a single pixel???? So that they will all line up evenly?
Mesen - game 3_22_2024 5_38_13 AM.png
 

dale_coop

Moderator
Staff member
There is one thing that is off. The Breakable Block object when placed in a row, is one pixel lower than actual tiles. @dale_coop do you know if there is anywhere in the code where a monster's placement on the screen can be adjusted by a single pixel???? So that they will all line up evenly?
View attachment 8064

It's done in the load screen data script.
(and if during scrolling, another code is in the handle camera script).
 

tbizzle

Well-known member
Here is the fix for The NPC object being one pixel off:

 
Top Bottom