# Ball jumping algorithm

I'm still starting out anf i'm making a 2d game where a ball which jumps through different blocks. The ball jumps a fixed height when i place the blocks that the ball should dodge i place them randomly so let's say 0 4 8 11 17 so the distance between two blocks is not always the same my problem is that i cant find a way to do algorithm for a systematic way to determine how hard is this level so if i made a sequence 0 6 11 19 21 i try it to see how difficult is it.. i want a way so that the blocks positions are determined in a way where i could know how difficult it is and that it is possible to pass this level. It is know the height the ball reaches as well as the time he ball moves in the x-direction as well as the time it takes to jump and get back to its original position..

• What have you tried and why isn't that working for you? StackExchange isn't a code writing service :) Nov 20, 2016 at 23:16
• I using trial and error i dont need written code just the idea of how to solve it Nov 20, 2016 at 23:17
• In which case, your question is far too broad and unclear. You might find that simply making your question clearer answers that for yourself. Nov 20, 2016 at 23:20
• It's mainly unclear... Nov 21, 2016 at 3:23

I have a suggestion.

Design short segments of block configurations (maybe a sequence of 4 to 10 blocks). Make several configurations (maybe 30) and play with them in game until you are clear on which configurations provide the most challenging arrangement and which the least (you'll probably have some idea as you design them). As you play, you'll start to see what makes the arrangements the most challenging. This may give you an idea of how to programmatically generate hard levels. But I think a more design oriented approach would work well.

So after you have your sequences made you can rank them by difficulty or just categorize them into 5 difficulty levels. Now you have the building blocks to intelligently and programmatically construct levels of specified difficulty. An easy level may randomly assemble 15 sequences of block arrangements from the 1,2, and 3 level difficulty group. A hard level would grab only from the level 12,13,14 groups.

This is a modular approach gives you design control. It can be your genius that develops a specific challenging arrangement. The player may begins to recognize this arrangement and learn the correct sequence of inputs to clear that segment. That is an advantage in my view. Players like to feel like they are learning and mastering the game. If you just have the code generate everything randomly, they may come across a sequence that makes their heart race and palms sweat and they may fail it, but be eager to try thy sequence again, but because it was made randomly, they may never ever see it again. In that moment they will wish that you had made the levels modular so they could master that sequence. This is just my opinion of course. But as a designer, won't you want to be responsible for specific devilish and devious block sequences? It will give your levels character, even if the order or frequency of the block sequences is left to a randomizer in your code.

If I did not understand your problem wrongly, you want a method to generate a level(blocks' position) based on the difficulty - by level or user selection.

Splitting the answer into two parts:

1. In order to determine if a level can possibly be completed, it is just simple calculation of values you already have. Two blocks cannot be so close to each other that an immediate just after landing from the previous jump(due to a block) cannot clear the next block. And if a jump can clear multiple blocks, there cannot be more blocks together than what a single jump can clear.
2. The difficulty of a reaction game like what you described is affected by two factors - distance between two blocks and randomness of the pattern of jump required to clear the blocks. So if you want to generate the levels randomly instead of a fixed design, the decreasing the average distance between each blocks while increasing the range of distance between each block will generally make each level harder.

If you want more details than what I have provided, I suggest you try what I have suggested and ask a more specific question about which parts you could not get.