Wondering about how to approach this…
Say I want the player to be able to climb up ladders, and use that to climb on top of otherwise solid platforms.
So far I’ve got:
- The ladder would be positioned on top of the solid map tile and extend down to the ground or wherever.
- The ladder could be made of ladder sections that should probably be the same size as the map tiles maybe or maybe not.
- If the player is in contact with a ladder tile, then pressing up should cause the player to move upwards, now without checking collisions between itself and the map.
- Not being in contact with a ladder tile would break the effect and reactivate map collisions and gravity etc.
- This way I imagine it would be possible to climb straight up from the bottom of the ladder, through the solid platform and then resume normal activity as soon as the top of the platform is reached and the ladder is cleared by the bottom of the player collision box.
Now, in order to accomplish that, I figure:
- Give the player a flag such as onLadder. That could be set to indicate the player should not be affected by gravity and be able to go up etc.
- Set the flag when the player is colliding with a ladder tile and the player presses up, then going out of contact with ladder tiles would unset it, as well as pressing down when there’s solid ground below.
Ok, fine, but one part I’m not too sure on is how I should determine that the player is at a ladder?..
I guess the collision detection between the player and ladders should happen somewhere in the gameplay state’s logic, but then when it’s determined that the player is touching a ladder, how should I handle getting that across to the player object?
I suppose I could use another atLadder flag, but then we’re getting a lot of flags here… I would also then possibly need something like aboveLadder for when the player is on a platform, not touching a ladder, but there’s a ladder directly below on the tile underneath.
That seems kinda messy but I suppose it would work.
OR…
Should I do something where, on pressing up or down, the player object in some way queries whether or not there’s a ladder below/touching?
That does seem to make sense, given that action is only ever taken if the player actually wishes to go up or down rather than it being something that happens every time they collide.
I suppose that means keeping a list of ladders somehow in the level map object that the player can query when required. Though I’m not sure how exactly that should be organized.
Do I have the right idea?
EDIT: In fact, is it worth for each map tile keeping a list of all the stationary entities (or perhaps even moving ones…) found on that tile? I suppose that would make collision detection quite quick if you just had to check what was on specific tiles, but is it worth the hassle/overhead?