Page 1 of 1

[SOLVED] Generating platforms randomly?

Posted: Thu Jul 25, 2013 5:52 pm
by Eamonn
So, this is probably what discouraged me from LÖVE the most: I can't figure out how to generate platforms in a random fashion.

It's been 3 weeks, and I've been thinking constantly about how to make a game doodle jump. I'd know how do make it so if he touches the platform, he jumps again: You'd just see if he's on the ground, and if he is then jump. But what I can't figure out is:

• Generate the platforms constantly out of the screen's view.
• Make it so the player can move up the platform, but can't fall back down.
• How to make it so the camera only follows the player going up.

I'd assume:

1) To make it so the player dies when he touches the end of the screen, Id' make it so the camera only moves up, but when he hits the bottom of the screen(if the player's Y is equal to 0 - the player's height).

2) Just move the camera up, just make it follow the player going up(which I don't know how to do).

I can't find any code examples in any programming language on how to do this. Same goes for endless runners. The only ones are for Scratch, GameMaker, Unity and GameSalad. I hate them. You should have to code a game, no easy tools, or shortcuts or anything like that, but that's another topic for another time(to get derailed another time too ;) ). But I will say this: I am not against the people who use them, I'm against the creators of them.

Maybe it's something really obvious and I just can't think of it, and I've been holding off asking here because of that. But I think after 3 weeks or so I've thought long enough and searched long enough.

I did ask a while ago about random maze generation. I haven't gotten any farther with that, so I can't use any knowledge from that to help me :| I know how to make them spawn randomly on the X axis, but the Y axis is confusing. For the X axis, you'd just do:

Code: Select all

platform.x = math.random(0, widthOfField)
But I don't know how to make it so multiple spawn at once on the Y axis, how they go up and don't spawn below, etc etc.

Thanks! Help is appreciated(as long as it's help and no insults)!

Re: Generating platforms randomly?

Posted: Thu Jul 25, 2013 6:52 pm
by mickeyjm
I can't go into detail now because its hard typing on my iPod but I would have a variable that keeps track of the highest Y coordinate reached and have the camera track that. His would also mean for generating the platforms you go a do something like
platform.y = math.random(MAXYREACHED-someHeight,MAXYREACHED+someHeight)
I would make some height equal to half the screen height and then have the camera track so that MAXYREACHED is in the centre, that way platforms generate across he while of the visible screen

Re: Generating platforms randomly?

Posted: Thu Jul 25, 2013 9:39 pm
by Shanulu
I have a bit of code that randomly draws rectangles of random sizes in my pong game. You could replicate that with what Mickey has said above. Limit the generation of the platforms to anywhere between the bottom of the screen and exactly how high your player can jump. At least I think that'a what he was saying :)

Re: Generating platforms randomly?

Posted: Fri Jul 26, 2013 7:35 am
by Eamonn
Thanks everyone! I'll look into your pong game and maybe modify it a little. Thanks for telling me about it though! :D