Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Climbing Ladders in a Platformer  (Read 3411 times)
0 Members and 1 Guest are viewing this topic.
Offline SeanSeanston

Senior Newbie





« Posted 2012-03-23 20:36:52 »

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?
Offline 65K
« Reply #1 - Posted 2012-03-24 07:19:38 »

I would set up a state machine for this.
And store additional information about the nature of each tile in the tile map, for switching between states.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Offline SeanSeanston

Senior Newbie





« Reply #2 - Posted 2012-03-24 16:03:45 »

Yeah, seems like I should definitely add something to the Tiles, otherwise it won't be easy to use the player's position to quickly detect ladders.

Wondering now though how exactly.

If ladders aren't going to always be aligned with Tiles (and why not), then I'll need to do more than find out just if a Tile has a ladder on it.
So what I'm thinking there is... give the Tile class a Ladder reference which would be null if it has no ladder overlapping it.

Though is that wasteful? Having a ladder reference when most Tiles won't have any? And then what about the future? Maybe Tiles will have other special objects on them that might need some kind of special treatment like ladders.

So, would it be a good idea then, to instead have some sort of list of these special Entities that could be found on Tiles?
Maybe something like... a map keyed by a string, for example "LADDER", that held Entity objects (of which Ladder is a subclass in my game) so it would be easy to find if there was a Ladder on a Tile, and then get its exact position. Suppose it would be a map of Entity lists really since there might conceivably be more than 1 Ladder overlapping a Tile.

Does that sound like a good design? Trying not to overthink this and end up with some over-engineered mess that tries to account for every possible situation and every possible future development... but it's hard not to let your mind wander persecutioncomplex
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 65K
« Reply #3 - Posted 2012-03-24 18:06:10 »

I use a simple integer bit field for classifying tiles: one bit for floor tiles, one for walls, for closed doors, open doors, etc.
Fast to check and can be automatically derived from a Tiled tile map.

So for your case I would roughly do something like this:
- create 3 sorts of ladder tiles: bottom, middle, top
- a collision with bottom ladder tile, switches into climbing-ladder-state
- after climbing up and reaching a middle-ladder tile, horizontal input events are ignored
- finally a collision with ladder-top allows to leave the ladder and switch into standard running state again

Probably no need for ladder objects, in my game I have door objects because they have their own state (open or closed).

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Offline SeanSeanston

Senior Newbie





« Reply #4 - Posted 2012-03-24 18:36:37 »

So for your case I would roughly do something like this:
- create 3 sorts of ladder tiles: bottom, middle, top
- a collision with bottom ladder tile, switches into climbing-ladder-state
- after climbing up and reaching a middle-ladder tile, horizontal input events are ignored
- finally a collision with ladder-top allows to leave the ladder and switch into standard running state again

I'd kind of think though that probably only 1 type of ladder tile would be necessary. Of course, it depends on how you'd want to handle ladders exactly... but it seems reasonable that you might allow jumping up to a ladder tile and pressing up to grab on. As for leaving the ladder, while I haven't got that far yet, I was thinking that if being on a ladder tile lets the player move up, then you could just let it allow the player to go up as far as until they're no longer in contact with the ladder at which point they're no longer be under the ladder's effect and just fall onto the platform or carry on as normal.
We'll see how that goes though.

Probably no need for ladder objects, in my game I have door objects because they have their own state (open or closed).

Only thing is though, should ladders really be tiles at all? If they're their own objects, then you can lay them over existing tiles and let the tile underneath show through with transparency which would probably look better than having a special top ladder tile that would break the continuity with the varying different looks of platform tile you might have.

It's a very minor and personal choice depending on how one wants to implement it though I guess.
Offline 65K
« Reply #5 - Posted 2012-03-24 18:48:28 »

Only thing is though, should ladders really be tiles at all? If they're their own objects, then you can lay them over existing tiles and let the tile underneath show through with transparency which would probably look better than having a special top ladder tile that would break the continuity with the varying different looks of platform tile you might have.
Yes, possible. Wouldn't change that much, mainly looking for entity-entity collisions then instead of tile-tile.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (45 views)
2018-11-16 13:46:03

hadezbladez (50 views)
2018-11-16 13:41:33

hadezbladez (35 views)
2018-11-16 13:35:35

hadezbladez (20 views)
2018-11-16 13:32:03

EgonOlsen (1902 views)
2018-06-10 19:43:48

EgonOlsen (1937 views)
2018-06-10 19:43:44

EgonOlsen (1286 views)
2018-06-10 19:43:20

DesertCoockie (1726 views)
2018-05-13 18:23:11

nelsongames (1412 views)
2018-04-24 18:15:36

nelsongames (2043 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!