I want to randomly generate reachable platforms on the fly for a 2D game. Right now, I am just creating platforms at random x,y positions. Only 4 platforms can exist at once, so once the 5th one is generated the 1st one is removed (fifo).
So, I want to ensure that the player can jump from his current platform to at least one other at any given time.
I was thinking of using some variant of the distance formula to calculate the location of the next platform being generated. I was hoping someone could help me out with the formula for calculating the next platforms possible x,y positions.
The player variables I am assuming will be important are speedX, speedY, and gravity.
From here, I should be able to calculate the maximum distance to plug into the distance formula.
However, I am thinking that some variation of the distance formula that contains a variable for slope would be better in my case.
I want to ensure that the player will never get stuck on a platform with no where it can jump. Also, I want to ensure that platforms aren't generated on top of each other.
Formulas/images/code are a huge plus.
Here is how jumping is currently working.
Field speedY:Float = 4 Field GRAVITY:Float = .05 Method Update:Void() If KeyDown(KEY_SPACE) And not jumping Then dy=-speedY jumping = true EndIf If jumping dy += GRAVITY local tempY:Float = y + dy y = tempy Endif End Method
Edit: I now understand that the formula is just the displacement of basic projectile motion.
Except, in my case, we don't care about cos/sin because the angle will always be the same.