It will depend on how you are handling movement and physics in your game. I'm assuming based on the Mario comparison that your game is a 2D side scroller?
If you are using a statemachine for your character/movement then you simply switch state to OnLadder
or something to that effect. The state itself would handle vertical movement code to allow you to ascend the ladder but simply not contain horizontal movement code.
Granted this assumes you are using statemachines and that you only have a single one, rather than multiple concurrent state machines for different movement etc... depending on how you have this set up you would need to adapt the solution.
I'm not sure how you are handling "ladder entry" logic but if you are not using state machines then you could potentially have a boolean called on_ladder
that gets set to true
as soon as whatever logic you have for being on the ladder triggers. You can then put a condition around your movement code to say something like
if !on_ladder:
# do your normal horizontal movement code
In addition to this you could also while on the ladder set your horizontal X position to be the center of the ladder so that while you are on the ladder your position on the x axis is always the center of ladder.
So maybe something like:
if !on_ladder:
# do your normal horizontal movement code
else:
player.position.x = ladder.position.x # assumes both have their position anchored in their center rather than a corner
I'm not sure if the above will work for you or not as it will really depend on how you have the rest of your movement/collision/game logic setup, in addition I don't have any experience with tilesets yet so there might be additional caveats there but I think the basic reasoning I layout above should still generally carry over.