2
\$\begingroup\$

Im not sure there is a going to be a simple answer for this question but Ill ask anyway. I am programming an endless scrolling game where the player's character is constantly "falling." As they fall they dodge pinecones. I want the program to randomly generate pinecones (which it does right now); however, I need a way to check that there is enough space between pinecones so that the player's path is never accidentally blocked.

Simply programming a minimum distance between pinecones isn't hard. The problem is that I want to allow some cones to be right next to each other, but still check to make sure there is space between others for the player to safely dodge pinecones. Basically, I do not want an equal amount of space between each pinecone all the time.

I've considered making a grid pattern that the pinecone spacing must abide by, but Im having trouble comparing spaces on the grid so that while some cones are allowed to be next to each other, others are not. If the question is unclear let me know and Ill try to explain better and include pictures or something.

\$\endgroup\$
  • \$\begingroup\$ Thanks! I just finished setting a minimum distance between pinecones and now am free to add a second layer. \$\endgroup\$ – Joel G Apr 27 '14 at 18:17
  • \$\begingroup\$ As an alternative to the minimum distance approach you could use a route planning algorithm to check if the proposed pinecone addition leaves a valid route, a modified A* might work with going up having infinite cost but it shouldn't be too difficult to roll your own. The danger would be creating 2 long paths, only one of which actually gets you to the end. \$\endgroup\$ – Richard Tingle Apr 28 '14 at 9:21
2
\$\begingroup\$

You can split this into two stages:

Firstly generate some pinecones with such minimum distance between them that you need:

enter image description here

On second stage add some pinecones next to those placed already:

enter image description here

That way you will have have some single pinecones and some pinecones clumps, but all of those will be separated well apart.

You can tweak 1st stage to use slightly bigger distance than minimum allowed, to let 2nd stage have room to add pinecones. Or check on 2nd stage to make sure no newly added pinecones will be making the gaps too small.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.