Possible [4.1] OneWayTile fix

Post Reply
User avatar
AllDarnDavey
Posts: 47
Joined: Sat Jan 12, 2019 6:16 am
Location: Seattle

Possible [4.1] OneWayTile fix

Post by AllDarnDavey » Sat Feb 23, 2019 5:22 am

I've found a bug in 4.1+ with one way platforms, it seems once you drop through a one way platform (actually just stand on one), it never gets reset and you can then drop through any solid block like they were a one way platform (and easily fall through the world). It looks like the fix isn't in the OneWayTile.asm, but actually in a_simple_jump.asm. It looks like the code to"TURN OFF STANDING ON JUMPTHROUGH PLATFORM if it is on" isn't working properly, but seems to work for me if I move it up to immediately turn off the flag after the check to branch if it's off.

Code: Select all

; a jumps
 
   LDX player1_object
   ;;; let's check for if we are standing on a jumpthrough platform,
   ;;; for which "down and jump" will jump downwards through
   ;;; comment this out if you do not want that functionality
    LDA screenFlags
    AND #%00100000 ;; does it use gravity?
    BEQ dontJump
    
   LDA Object_physics_byte,x
   AND #%00001000
   BEQ notStandingOnJumpThroughPlatform
   ;;; TURN OFF "STANDING ON JUMPTHROUGH PLATFORM" if it is on
   LDA Object_physics_byte,x
   AND #%11110111
   STA Object_physics_byte,x
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
   LDA gamepad
   AND #%00100000
   BEQ notStandingOnJumpThroughPlatform
   LDA Object_y_hi,x
   CLC
   ADC #$09
   STA Object_y_hi,x
   JMP dontJump
notStandingOnJumpThroughPlatform:
   
   LDA Object_physics_byte,x
   AND #%00000001
   BNE canJump
   LDA Object_physics_byte,x
   AND #%00000100
   BEQ dontJump
    
canJump:
    LDA #$00
    SEC
    SBC #JUMP_SPEED_LO
    STA Object_v_speed_lo,x
    LDA #$00
    SEC
    SBC #JUMP_SPEED_HI
    STA Object_v_speed_hi,x
    GetCurrentActionType player1_object
    CMP #$03 ;; attack
    BEQ +
    ChangeObjectState #$02, #$04
   +
    PlaySound #SND_JUMP
dontJump:
    RTS
Hope this helps others.
User avatar
Redherring32
Posts: 455
Joined: Sat Aug 11, 2018 2:48 pm
Location: Usa

Re: Possible [4.1] OneWayTile fix

Post by Redherring32 » Sat Feb 23, 2019 6:04 am

That's awesome, thanks for sharing. :)
My current WIP game: Shadow: An Adventure In Monochrome, you can also find me over at the Community Discord.

Open Source NES Motherboard
User avatar
Dirk
Posts: 522
Joined: Fri Mar 09, 2018 5:30 am

Re: Possible [4.1] OneWayTile fix

Post by Dirk » Tue Mar 24, 2020 4:08 pm

This works for the most part, but I found a way to break it.
Jump on one way tile and do NOT press 'down + jump'. Instead just walk off the platform and on solid ground. Now press 'down + jump'. You will fall through the solid tile like it was a one way tile.
-----
Disclaimer: English is not my first language, so mistakes are bound to happen.
User avatar
Dirk
Posts: 522
Joined: Fri Mar 09, 2018 5:30 am

Re: Possible [4.1] OneWayTile fix

Post by Dirk » Tue Mar 24, 2020 4:21 pm

Okay, I think I've found a way to fix it. The check for 'standing on jumpthrough platform' only gets performed when the jump button gets pressed. This means we can bypass this check by simply walking off a one way platform. Pressing 'down + jump' now would make the player fall through solid tiles.
To solve this I also copied the 'turn-off-standing-on-jumpthrough-platform' code to the sold tile asm file.

At first I wanted to simply move the code, but I later realized this would mean it could probably still be bypassed by walking on a tile other than a solid.
So I kept this code in a_simple_jump.asm:

Code: Select all

;;; TURN OFF "STANDING ON JUMPTHROUGH PLATFORM" if it is on
    LDA Object_physics_byte,x
    AND #%11110111
    STA Object_physics_byte,x
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I then opened Project -> Project Settings -> Script Settings, clicked on Tile Collision 01 - Routines\Basic\ModuleScripts\TileScripts\SolidBehavior.asm, clicked the Edit button and in my editor I added the previous code.

Code: Select all

;;; SOLID
;;;This is how to inform a solid collision.
;;; You can also add this to the end of
;;; any tile type if you want it to have an effect AND
;;; be treated like solid.
;;; You could also check to see if it is a non-player object,
;;; and only return solid if it's a not player.  This would
;;; cause monsters to treat things like spikes or ladder or fire
;;; as solid while the player is able to interract with it.


;;; TURN OFF "STANDING ON JUMPTHROUGH PLATFORM" if it is on
    LDA Object_physics_byte,x
    AND #%11110111
    STA Object_physics_byte,x
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    LDA #TILE_SOLID
    STA tile_solidity
    
    ;; if you want it solid, declare it at the end
Now everything seems to work for me.
I hope this fixes the issue completely :-)
-----
Disclaimer: English is not my first language, so mistakes are bound to happen.
User avatar
AllDarnDavey
Posts: 47
Joined: Sat Jan 12, 2019 6:16 am
Location: Seattle

Re: Possible [4.1] OneWayTile fix

Post by AllDarnDavey » Thu Mar 26, 2020 10:50 pm

Nice work!
I might have to dust off my old project and actually try and finish it now that I'm stuck at home. :)
Post Reply