NPC tile problem when monsters or powers on screen

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

NPC tile problem when monsters or powers on screen

Post by chronicleroflegends » Wed Apr 17, 2019 1:41 am

Been having this issue for a while, and was wondering if anybody may have encountered it/had a solution.

We have two main ways of triggering a text box:
NPC tiles and NPC monsters.
Both activate if you are touching them and press the appropriate input button.

The problem I am having is this:
NPC monsters can be activated no matter what as long as you collide with them.
NPC tiles only seem to set the npc_collision flag if all monsters and gameobjects (like powerups) are destroyed/don't exist except for the player.

Any idea why this would be the case?
It looks like the code setting the flag is the same in both.
All the check does in the activate text box input script is check to make sure that box_collision is not zero.
~Do you believe in legends? ~
My Games: Nix: The Paradox Relic
User avatar
chronicleroflegends
Posts: 185
Joined: Thu Sep 06, 2018 3:51 am

Re: NPC tile problem when monsters or powers on screen

Post by chronicleroflegends » Wed May 22, 2019 7:48 pm

OK!

I finally tracked down the cause of this issue. This is due to default engine behavior, so I thought I would share the fix so others could use it.

The concept:
The reason this happens, is that the tile collision script gets run for every gameobject on screen, not just the player.
So even if the player is colliding with an NPC tile, if there is a gameobject on the screen that is not, then it immediately sets the flag back to 0.

To fix, just make this change to the top of your tile collisions script:

Code: Select all

HandleTileCollision:
    ;;;;;ASSUMES vulnerability bit 000x0000, if one, skips collision.
    ;;;;;Six collision points. 
    ;;;;;All collision points checked and registered for all objects.
    ;;;; a solid in any of the points will result in negating all others.
    
        ;;; There are 6 ram variables, collisionPoint0 - collisionPoint5.
        ;;; collisionPoint0 = top left
        ;;; collisionPoint1 = top right
        ;;; collisionPoint2 = bottom right
        ;;; collisionPoint3 = bottom left.
        ;;; collisionPoint4 = mid left
        ;;; collisionPoint5 = mid right.
    
    TXA 
    STA currentObject
    TYA
    STA tempy

    LDA currentObject ; We do not want to reset the flag if an Enemy isn't colliding with NPC while
    CMP player1_object; player is.
    BNE +
    LDA npc_collision
    AND #%00000001 ; Set TileNPC flag to zero but keep ObjectNpc flag
    ;AND #%11111101 ; original
    ;LDA #$00 ; original
    STA npc_collision
  +:
    LDA navFlag
    AND #%11111110
    STA navFlag
    ...
    ...
~Do you believe in legends? ~
My Games: Nix: The Paradox Relic
User avatar
dale_coop
Posts: 3956
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: NPC tile problem when monsters or powers on screen

Post by dale_coop » Wed May 22, 2019 8:33 pm

Sounds great! Thanks for sharing <3
-----
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