[4.5.6] Ice Physics (meant for LR Platformers)

Logana

Well-known member
The collision screen you showed me isn't using any ice physics tiles.
Could you just please copy and paste your code from the handle physics.asm file, since when ever or how ever I paste the part in you tell me to it completely corrupts my games physics
 

Logana

Well-known member
So this is meant for the LR Platformers, but I think it might work with others. This was an adaptation of a script Dale wrote in an earlier version that no longer worked. I had to tweak some things and write some simple codes in other places. I'm honestly surprised it worked lol.



STEP 1:
First Open up your game settings and go to the User Variable Tab. Click the Add button at the top and then click on the new Variable and name it "onIce" Be sure to leave the value at 0.

While we're in here we will also Go to Project Lavels > Tile Types and Click Tile 13. Rename it to something like Ice or Slippery.

Step 2:
Next we need to make a new .ASM file to apply to our Tile 13. Go to your NESmaker folder then go to Routines > Base_4_5 > Game > Subroutines

Here we will create a new Text file. Open it up and paste the following code inside of it.

Code:
;; set the ice bit:
    LDA #$01
    STA onIce

Once you've pasted it go to File > Save as and save the file as IceTiles.asm

Step 3:
Go back into your game settings and go to the Script Settings Tab. Scroll all the way down to your Tile Types folder. No we will go to Tile 13. (or whatever tile you want,) and click on it and hit the Change button. Paste this into the Script path and then close the game settings.



Step 4:
Now we need to paste some code. We going to edit the doHandlePhysics_PlatformBase.asm file. To to scripts > Defined Scripts > Game > SubRoutines > Handle Physics.

Now we're going to go to line 126 and paste in this bit of code.

Code:
        ;; object is on ice?
        LDA onIce
        AND #$01
        BEQ +
        LDA #$08    ;;<<-- Change this to anything between maybe 5-10 to get decent ice physics. 8 is pretty solid.
        JMP ++
        +
        LDA ObjectAccAmount,y
        ++
        STA myAcc
        JMP +doneWithAccFetch




That's it, you should have functional ice tiles. A few things to note.

1.) Place the slippery tile ABOVE the solid tiles that you want to be slippery. You could make the ice tile itself solid, but I haven't figured out how. Pasting the Solid tile code into the ice tile code makes this weird sticky tile that's kind of interesting.

2.) The physics aren't perfect. Jumping completely cancels out the forward momentum. I'm not quite sure how to fix this yet. Maybe someone else can figure it out.

3.) I don't know if this works on other Modules, so you'll likely have to try and adapt it for yourself.


Update:
1. It doesn't work in Adventure Modules.

2.) You can carry out your horizontal momentum if you stack the slippery tiles even higher up in the air (at least as high as your jump height)
Basically the way you told us to paste in that code into line 126 of the handle physics broke for me, I really need you to please paste the version you have or else my game will be stuck in limbo where the character is forever stuck
 

TakuikaNinja

Active member
I decided to test this out and found a few issues:
- The collision on the first screen breaks when adding "onIce" as a user variable. I added it to zero page RAM instead and it works fine.
- The way you check if "onIce" is set is sub-optimal. You can do a BEQ after loading a variable to check if it is zero.
This is what the code should look like at lines 126~144 of doHandlePhysics_PlatformBase.asm after the change:
Code:
        ;; object is on ice?
        LDA onIce
        BEQ +
        LDA #$08    ;;Change this to anything between maybe 5-10 to get decent ice physics. 8 is pretty solid.
        STA myAcc
        JMP +doneWithAccFetch
        +
        STA myAcc+1 ;; we know A is zero
        LDA ObjectAccAmount,y
        CMP #$FF
        BNE +notMaxedAccAmount
            LDA myMaxSpeed
            STA myAcc
            LDA myMaxSpeed+1
            STA myAcc+1
            JMP +doneWithAccFetch
        +notMaxedAccAmount
        STA myAcc
    +doneWithAccFetch

- There needs to be a way to reset "onIce", otherwise the player will be stuck with ice physics. A good place to do this would be when the collision detection determines that we are not on a solid tile (i.e. a blank tile).
This is what the code at lines 596~598 of doHandlePhysics_PlatformBase.asm should look like after all the changes (including the one above) have been made:

Code:
+notSolid:
    LDA #$00 ;; reset the ice physics
    STA onIce

I've attached the complete script in case people are not sure what to change.

Proof:
1609826265373.png



Hope that helps!
 

Attachments

  • doHandlePhysics_PlatformBase_Ice.zip
    4.2 KB · Views: 16
Top Bottom