4.5.9 Metroidvania and Platformer Slopes

Knietfeld

Member
Alright, I'm here to share how I made slopes work in 4.5.9. This method makes slopes that you can run up and down, jump off of, jump through from below, and they fully interact with Objects other than the player such as enemies and NPCs.

In my current project (Rick Starfield, which I am still working on very slowly) I'd already heavily adapted the physics subroutine to suit my needs so I downloaded a fresh copy of NESMaker, followed the beginner tutorial for the metroidvania module until the point I had the character moving around onscreen and then I started messing with the scripts. So this should work for nearly anyone who started their project that way.

To make slopes we only need to make changes to three scripts: doHandlePhysics_PlatformBase.asm, doHandleTileCollisions_PlatformBase.asm, and jump_throughPlat.asm.

Because these scripts are shared across (I think) all of the platformer based modules, my slopes method should work for any platformer or metroidvania game.

I've attached my edited scripts and I'll briefly explain how to place them in your game for beginners or people who may have forgotten how. But if you've already edited any of these scripts you won't want to simply replace the scripts you've modified so I've heavily commented the code I wrote so hopefully any intermediate to advanced users can figure out what's going on and cut and paste and modify parts to suit their needs (just look for the parts that say my initials, "kn" to signify parts I added. Also I generally code in lower case opcodes and Joe uses upper case so that might tell you who wrote what unless I copy pasted his work). I was planning on showing how you can make more gradual slopes in addition to the 45 degree ones already set up in the code, but I just want to get this post out there. If some people have trouble trying to get that figured out on their own I can help out in the comments. I've also attached a supplemental code file that, if you can figure out where to put the pieces, can point you in the right direction to making your own slopes.

So here we go.

Trading out the original scripts with the new slope scripts

The forum wouldn't let me attach .asm files. So the attached files at the bottom are .txt files. All you have to do to make them .asm files is open them from your downloads folder in any text editor and from the File menu, click SAVE AS and at the end of the file name type ".asm".
You can save them in any of your NESMaker folders, but I suggest saving them in the same folder as the files I've adapted them from. That means, save doHandlePhysics_PlatformBase_WithSlopes and doHandleTileCollisions_PlatformBase_WithSlopes, to (your NESMaker folder)\NESmaker_4_5_x\GameEngineData\Routines\BASE_4_5\Game\MOD_PlatformerBase\Subroutines. And save jump_throughPlat_WithSlopes to (your NESMaker folder)\NESmaker_4_5_x\GameEngineData\Routines\BASE_4_5\Game\MOD_PlatformerBase\Inputs.

Now, in your NESMaker project, open ProjectSettings/Script Settings and scroll to the bottom where in the Sub Routines folder you will find Handle Physics and Handle Tile Collisions. Select the script you want to trade out and use the box to the right to navigate to the folder where you put the new physics and tile collisions scripts and double click the file you want to trade it with.

Swap out scripts.png

In the Project bar, click "Scripts", then "Input Scripts" and select the new jump script. Then using the Input Editor Set up the new jump exactly like the old one but with the new script. And make sure to right click and remove the old jump input.

InputEditor.png

That's it for scripts. You now have all the code you need for slopes to work in your game. So...

Making slopes work in your game

Obviously you'll want to make some graphics for slopes. I'll leave that up to you.

You'll also want to go to Project Settings/Project Labels/Tile Types and change Tile11 and Tile 12. I made my names for the tiles "Tile11 0B - o0" and "Tile12 0C - 0o." The o0 and 0o look generally like the sloped floor tiles to me which was easier for me than using words.

The scripts I've attached only make two types of slopes and they are hardcoded to Tile 11 and Tile 12. To change which tiles it uses is super simple. In the Physics Subroutine change the 0c and 0b in lines 537, 541, 563, and 567 to whatever tile type number you are using and change the four checks for those slopes in the jump code to reflect your new tile type numbers as well. Lines 41,43,89, and 91.

So once you've got slope graphics and names that work for you you can start putting slopes in your game.

You can have different effects depending how you arrange your slope tiles. It's probably easier to just show a picture of my slopes with collisions.

Slope Collisions.png

Does that make enough sense? In this example the grey tiles are jumpthrough tiles and the purple are solid. Like this video.
View: https://youtu.be/kSLUKDPBwr0

The slope tiles are basically jumpthrough tiles. You can always jump through from below.
If you want to jump through the tile then you also probably want to run under it without automatically going up the slope, so you just leave that bottom tile 00. If you put 0B or 0C right at the base it works fine to run up but if you run left into 0B or right into 0C it makes the player bounce around weirdly. So, if you want your slope to be solid, and you just run up it when you approach it from the right side, you just put solid tiles under/next to the slope.

Are there any drawbacks to this method of slopes?

Well, naturally, doing a couple more collision checks and doing extra code takes more memory and processing time in each frame. Though I don't think this is much, it does these checks for every object that uses normal physics every frame, so it could slow things down a little bit.

One thing to note - the only bit of code I added to doHandleTileCollisions tells it to skip checking for solid tiles on the bottom corners of the bounding box if the object is touching a slope tile. This is necessary to allow the object to successfully step from slope to solid floor at the top of the slope. So if your object's height is more than 16 pixels (and I think many would be) you wouldn't want to put a single solid tile for the player to run into right at the top or bottom of the slope or else the object will glitch to the top of it when it registers collision. It's easy to design around. Either add another solid tile above that one so the top corners of your object hit the wall, or just don't put single tiles at the top or bottom of slopes.

NoSingleSolidTile.png

Any other oddities I noticed that I thought, "oh, I should warn about that in my tutorial" I ended up fixing by the time I was comfortable posting this. So if you find things you have problems with please let me know. I'm happy to help when I have the time.

That's it! Good Luck! Have Fun! I hope this helps to make your game even more awesome.

[09/05/21 EDIT: @tbizzle brought to my attention some glitches I introduced involving ladder functionality. I edited the physics script and fixed that, and while I was at it I fixed the seam collision glitch in a way similar to the tutorial by @TakuikaNinja. The new doHandlePhysics script has replaced the old one right here in the attached files. Sorry for the frustration the old version might have caused. I'm still happy to help if anyone else has trouble integrating this into their game plan.]
 

Attachments

  • doHandleTileCollisions_PlatformBase_WithSlopes.txt
    5.5 KB · Views: 118
  • jump_throughPlat_WithSlopes.txt
    4.5 KB · Views: 116
  • Slopes_tutorial_OtherExamples.txt
    2.2 KB · Views: 94
  • doHandlePhysics_PlatformBase_WithSlopes.txt
    20.2 KB · Views: 109
Last edited:

Craigery

Active member
I don't suppose this translates very well to the Adventure module? I tried adding your custom sections to doHandleTileCollisions and doHandlePhysics, but it crashes when I step on the tiles. I omitted the code referencing Jumps, but obviously I don't understand it well enough. Any help would be appreciated.
 

Attachments

  • doHandlePhysics_Slopes.txt
    20.6 KB · Views: 4
  • doHandleTileCollisions_Slopes.txt
    6.8 KB · Views: 3

JamesNES

Well-known member
I don't suppose this translates very well to the Adventure module? I tried adding your custom sections to doHandleTileCollisions and doHandlePhysics, but it crashes when I step on the tiles. I omitted the code referencing Jumps, but obviously I don't understand it well enough. Any help would be appreciated.

If you hit me up in the Discord @jimbojames I can help you get it working in the adventure module. It's way simple compared to platformers
 

Knietfeld

Member
I don't suppose this translates very well to the Adventure module? I tried adding your custom sections to doHandleTileCollisions and doHandlePhysics, but it crashes when I step on the tiles. I omitted the code referencing Jumps, but obviously I don't understand it well enough. Any help would be appreciated.
Sorry, this was based off the platformer physics script and wouldn't work to replace any others probably. The platformer module uses gravity and I think my code relies on the gravity code. I haven't messed with the adventure module much but I think JamesNES is right. It's more simple. I don't know if the method I used would be best for it but it'd be interesting to look into.
I hadn't even thought about angled walls being useful in an adventure game. But now that I think of it, A Link to the Past did that sometimes and that made the terrain seem more organic.
 

tbizzle

Well-known member
Very nice presentation @Knietfeld! A newbie like me understood it! But it just didn't work out in my game. Every time I got to the top of a ladder tile my main character started bouncing up and down out of control, and also something in the asm turned random tiles in my game null-walkable and my guy would just fall through the floor here and there, lol. I would love to figure it out still! Maybe next game when everything in the code is nice and fresh.
 

Knietfeld

Member
@tbizzle, I'm sorry it didn't work for you. I don't know what could be causing those issues. Maybe I'll revisit this code sometime. I'll let you know if I find anything. Thanks for telling me!
 
Alright, I'm here to share how I made slopes work in 4.5.9. This method makes slopes that you can run up and down, jump off of, jump through from below, and they fully interact with Objects other than the player such as enemies and NPCs.

In my current project (Rick Starfield, which I am still working on very slowly) I'd already heavily adapted the physics subroutine to suit my needs so I downloaded a fresh copy of NESMaker, followed the beginner tutorial for the metroidvania module until the point I had the character moving around onscreen and then I started messing with the scripts. So this should work for nearly anyone who started their project that way.

To make slopes we only need to make changes to three scripts: doHandlePhysics_PlatformBase.asm, doHandleTileCollisions_PlatformBase.asm, and jump_throughPlat.asm.

Because these scripts are shared across (I think) all of the platformer based modules, my slopes method should work for any platformer or metroidvania game.

I've attached my edited scripts and I'll briefly explain how to place them in your game for beginners or people who may have forgotten how. But if you've already edited any of these scripts you won't want to simply replace the scripts you've modified so I've heavily commented the code I wrote so hopefully any intermediate to advanced users can figure out what's going on and cut and paste and modify parts to suit their needs (just look for the parts that say my initials, "kn" to signify parts I added. Also I generally code in lower case opcodes and Joe uses upper case so that might tell you who wrote what unless I copy pasted his work). I was planning on showing how you can make more gradual slopes in addition to the 45 degree ones already set up in the code, but I just want to get this post out there. If some people have trouble trying to get that figured out on their own I can help out in the comments. I've also attached a supplemental code file that, if you can figure out where to put the pieces, can point you in the right direction to making your own slopes.

So here we go.

Trading out the original scripts with the new slope scripts

The forum wouldn't let me attach .asm files. So the attached files at the bottom are .txt files. All you have to do to make them .asm files is open them from your downloads folder in any text editor and from the File menu, click SAVE AS and at the end of the file name type ".asm".
You can save them in any of your NESMaker folders, but I suggest saving them in the same folder as the files I've adapted them from. That means, save doHandlePhysics_PlatformBase_WithSlopes and doHandleTileCollisions_PlatformBase_WithSlopes, to (your NESMaker folder)\NESmaker_4_5_x\GameEngineData\Routines\BASE_4_5\Game\MOD_PlatformerBase\Subroutines. And save jump_throughPlat_WithSlopes to (your NESMaker folder)\NESmaker_4_5_x\GameEngineData\Routines\BASE_4_5\Game\MOD_PlatformerBase\Inputs.

Now, in your NESMaker project, open ProjectSettings/Script Settings and scroll to the bottom where in the Sub Routines folder you will find Handle Physics and Handle Tile Collisions. Select the script you want to trade out and use the box to the right to navigate to the folder where you put the new physics and tile collisions scripts and double click the file you want to trade it with.

View attachment 5099

In the Project bar, click "Scripts", then "Input Scripts" and select the new jump script. Then using the Input Editor Set up the new jump exactly like the old one but with the new script. And make sure to right click and remove the old jump input.

View attachment 5100

That's it for scripts. You now have all the code you need for slopes to work in your game. So...

Making slopes work in your game

Obviously you'll want to make some graphics for slopes. I'll leave that up to you.

You'll also want to go to Project Settings/Project Labels/Tile Types and change Tile11 and Tile 12. I made my names for the tiles "Tile11 0B - o0" and "Tile12 0C - 0o." The o0 and 0o look generally like the sloped floor tiles to me which was easier for me than using words.

The scripts I've attached only make two types of slopes and they are hardcoded to Tile 11 and Tile 12. To change which tiles it uses is super simple. In the Physics Subroutine change the 0c and 0b in lines 537, 541, 563, and 567 to whatever tile type number you are using and change the four checks for those slopes in the jump code to reflect your new tile type numbers as well. Lines 41,43,89, and 91.

So once you've got slope graphics and names that work for you you can start putting slopes in your game.

You can have different effects depending how you arrange your slope tiles. It's probably easier to just show a picture of my slopes with collisions.

View attachment 5101

Does that make enough sense? In this example the grey tiles are jumpthrough tiles and the purple are solid. Like this video.
View: https://youtu.be/kSLUKDPBwr0

The slope tiles are basically jumpthrough tiles. You can always jump through from below.
If you want to jump through the tile then you also probably want to run under it without automatically going up the slope, so you just leave that bottom tile 00. If you put 0B or 0C right at the base it works fine to run up but if you run left into 0B or right into 0C it makes the player bounce around weirdly. So, if you want your slope to be solid, and you just run up it when you approach it from the right side, you just put solid tiles under/next to the slope.

Are there any drawbacks to this method of slopes?

Well, naturally, doing a couple more collision checks and doing extra code takes more memory and processing time in each frame. Though I don't think this is much, it does these checks for every object that uses normal physics every frame, so it could slow things down a little bit.

One thing to note - the only bit of code I added to doHandleTileCollisions tells it to skip checking for solid tiles on the bottom corners of the bounding box if the object is touching a slope tile. This is necessary to allow the object to successfully step from slope to solid floor at the top of the slope. So if your object's height is more than 16 pixels (and I think many would be) you wouldn't want to put a single solid tile for the player to run into right at the top or bottom of the slope or else the object will glitch to the top of it when it registers collision. It's easy to design around. Either add another solid tile above that one so the top corners of your object hit the wall, or just don't put single tiles at the top or bottom of slopes.

View attachment 5103
AMAZING. VERY NICE
Any other oddities I noticed that I thought, "oh, I should warn about that in my tutorial" I ended up fixing by the time I was comfortable posting this. So if you find things you have problems with please let me know. I'm happy to help when I have the time.

That's it! Good Luck! Have Fun! I hope this helps to make your game even more awesome.

[09/05/21 EDIT: @tbizzle brought to my attention some glitches I introduced involving ladder functionality. I edited the physics script and fixed that, and while I was at it I fixed the seam collision glitch in a way similar to the tutorial by @TakuikaNinja. The new doHandlePhysics script has replaced the old one right here in the attached files. Sorry for the frustration the old version might have caused. I'm still happy to help if anyone else has trouble integrating this into their game plan.]
 
Alright, I'm here to share how I made slopes work in 4.5.9. This method makes slopes that you can run up and down, jump off of, jump through from below, and they fully interact with Objects other than the player such as enemies and NPCs.

In my current project (Rick Starfield, which I am still working on very slowly) I'd already heavily adapted the physics subroutine to suit my needs so I downloaded a fresh copy of NESMaker, followed the beginner tutorial for the metroidvania module until the point I had the character moving around onscreen and then I started messing with the scripts. So this should work for nearly anyone who started their project that way.

To make slopes we only need to make changes to three scripts: doHandlePhysics_PlatformBase.asm, doHandleTileCollisions_PlatformBase.asm, and jump_throughPlat.asm.

Because these scripts are shared across (I think) all of the platformer based modules, my slopes method should work for any platformer or metroidvania game.

I've attached my edited scripts and I'll briefly explain how to place them in your game for beginners or people who may have forgotten how. But if you've already edited any of these scripts you won't want to simply replace the scripts you've modified so I've heavily commented the code I wrote so hopefully any intermediate to advanced users can figure out what's going on and cut and paste and modify parts to suit their needs (just look for the parts that say my initials, "kn" to signify parts I added. Also I generally code in lower case opcodes and Joe uses upper case so that might tell you who wrote what unless I copy pasted his work). I was planning on showing how you can make more gradual slopes in addition to the 45 degree ones already set up in the code, but I just want to get this post out there. If some people have trouble trying to get that figured out on their own I can help out in the comments. I've also attached a supplemental code file that, if you can figure out where to put the pieces, can point you in the right direction to making your own slopes.

So here we go.

Trading out the original scripts with the new slope scripts

The forum wouldn't let me attach .asm files. So the attached files at the bottom are .txt files. All you have to do to make them .asm files is open them from your downloads folder in any text editor and from the File menu, click SAVE AS and at the end of the file name type ".asm".
You can save them in any of your NESMaker folders, but I suggest saving them in the same folder as the files I've adapted them from. That means, save doHandlePhysics_PlatformBase_WithSlopes and doHandleTileCollisions_PlatformBase_WithSlopes, to (your NESMaker folder)\NESmaker_4_5_x\GameEngineData\Routines\BASE_4_5\Game\MOD_PlatformerBase\Subroutines. And save jump_throughPlat_WithSlopes to (your NESMaker folder)\NESmaker_4_5_x\GameEngineData\Routines\BASE_4_5\Game\MOD_PlatformerBase\Inputs.

Now, in your NESMaker project, open ProjectSettings/Script Settings and scroll to the bottom where in the Sub Routines folder you will find Handle Physics and Handle Tile Collisions. Select the script you want to trade out and use the box to the right to navigate to the folder where you put the new physics and tile collisions scripts and double click the file you want to trade it with.

View attachment 5099

In the Project bar, click "Scripts", then "Input Scripts" and select the new jump script. Then using the Input Editor Set up the new jump exactly like the old one but with the new script. And make sure to right click and remove the old jump input.

View attachment 5100

That's it for scripts. You now have all the code you need for slopes to work in your game. So...

Making slopes work in your game

Obviously you'll want to make some graphics for slopes. I'll leave that up to you.

You'll also want to go to Project Settings/Project Labels/Tile Types and change Tile11 and Tile 12. I made my names for the tiles "Tile11 0B - o0" and "Tile12 0C - 0o." The o0 and 0o look generally like the sloped floor tiles to me which was easier for me than using words.

The scripts I've attached only make two types of slopes and they are hardcoded to Tile 11 and Tile 12. To change which tiles it uses is super simple. In the Physics Subroutine change the 0c and 0b in lines 537, 541, 563, and 567 to whatever tile type number you are using and change the four checks for those slopes in the jump code to reflect your new tile type numbers as well. Lines 41,43,89, and 91.

So once you've got slope graphics and names that work for you you can start putting slopes in your game.

You can have different effects depending how you arrange your slope tiles. It's probably easier to just show a picture of my slopes with collisions.

View attachment 5101

Does that make enough sense? In this example the grey tiles are jumpthrough tiles and the purple are solid. Like this video.
View: https://youtu.be/kSLUKDPBwr0

The slope tiles are basically jumpthrough tiles. You can always jump through from below.
If you want to jump through the tile then you also probably want to run under it without automatically going up the slope, so you just leave that bottom tile 00. If you put 0B or 0C right at the base it works fine to run up but if you run left into 0B or right into 0C it makes the player bounce around weirdly. So, if you want your slope to be solid, and you just run up it when you approach it from the right side, you just put solid tiles under/next to the slope.

Are there any drawbacks to this method of slopes?

Well, naturally, doing a couple more collision checks and doing extra code takes more memory and processing time in each frame. Though I don't think this is much, it does these checks for every object that uses normal physics every frame, so it could slow things down a little bit.

One thing to note - the only bit of code I added to doHandleTileCollisions tells it to skip checking for solid tiles on the bottom corners of the bounding box if the object is touching a slope tile. This is necessary to allow the object to successfully step from slope to solid floor at the top of the slope. So if your object's height is more than 16 pixels (and I think many would be) you wouldn't want to put a single solid tile for the player to run into right at the top or bottom of the slope or else the object will glitch to the top of it when it registers collision. It's easy to design around. Either add another solid tile above that one so the top corners of your object hit the wall, or just don't put single tiles at the top or bottom of slopes.

View attachment 5103

Any other oddities I noticed that I thought, "oh, I should warn about that in my tutorial" I ended up fixing by the time I was comfortable posting this. So if you find things you have problems with please let me know. I'm happy to help when I have the time.

That's it! Good Luck! Have Fun! I hope this helps to make your game even more awesome.

[09/05/21 EDIT: @tbizzle brought to my attention some glitches I introduced involving ladder functionality. I edited the physics script and fixed that, and while I was at it I fixed the seam collision glitch in a way similar to the tutorial by @TakuikaNinja. The new doHandlePhysics script has replaced the old one right here in the attached files. Sorry for the frustration the old version might have caused. I'm still happy to help if anyone else has trouble integrating this into their game plan.]
AMAZING. do you have any tutorial on youtube about scrolling version. Especially the action steps. Difficulty animating the attacks here..
 

SciNEStist

Well-known member
I finally got around to implimenting this on something I am working on, works awesome! I ran into 2 problems while running it:
1: at first I forgot to set the scripts for tiles 11 and 12 to blank, so they were executing some weird code. was my bad, but something to watch out for.
2: when running up a slope, my character would sometimes get stuck at the top by being embedded into a solid tile. To fix this, I increased the offset by 2 more pixels at line 769, so it looked like this:

Code:
        SBC #$03            ;and one more pixel
        sta temp            ;and this is where your Object will be placed if it passes the last two checks
 

alby13

New member
Overall, well done. May I suggest that when you talk about saving it to the folders you do line breaks and/or quotes/spacing so it is easier to see the folders and the files. Thank you for putting this together.


Further,
I think I noticed that the script in the picture does not have a "s" in the name and it say slope instead of the updated file which says "slopes" with the "s". Just something I noticed.
 
Last edited:

alby13

New member
I finally got around to implimenting this on something I am working on, works awesome! I ran into 2 problems while running it:
1: at first I forgot to set the scripts for tiles 11 and 12 to blank, so they were executing some weird code. was my bad, but something to watch out for.
2: when running up a slope, my character would sometimes get stuck at the top by being embedded into a solid tile. To fix this, I increased the offset by 2 more pixels at line 769, so it looked like this:

Code:
        SBC #$03            ;and one more pixel
        sta temp            ;and this is where your Object will be placed if it passes the last two checks
Thank you for adding this. To clarify for anyone new, the file being modified is "doHandlePhysics_PlatformBase_WithSlopes.asm" and it will have the .asm file extension after following the original tutorial.
 
Which script or what line could you implement the code below to make going up the slope an Input? otherwise it would ignore the tile and pass through all of slopes?
Basically adding this script would create a mock Castlevania stair effect
CPX player1_object
BNE +Notuptheslope
;; checking the gampad
LDA gamepad
AND #%01000000 ;; is the up button is pressed ?
BEQ +Inputnotpressed
 
Top Bottom