-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|399|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Mini Challenges -> Road node code

Posted : Sunday, 19 November 2017, 04:37
rockford

Road node code


Has anyone here created a simple road node code to create something similar to the image below?



I figured that Pakz and Jay, and maybe others, might have done this already. I want to do something similar and have a few ideas, eg -


1. Have a recursive road where it spawns a path in a number of random number of directions from the left to the right.

2. Create a series of randomly plced nodes and create random direction paths from those.

3. Fill the gaps (between the roads) with blocks and then create roads around them

4. Create the nodes randomly then check if there's a node in any direction around them and create road to join.

I'm sure that 2 and 3 are very inefficient and 1 could be improved on.

Any tips or code?
Posted : Sunday, 19 November 2017, 05:28
Jayenkai
Like in SuperMario3?..
Never attempted such a thing, but I'm willing to give it a whirl.

Gimme an hour or so.

-=-=-
''Load, Next List!''
Posted : Sunday, 19 November 2017, 05:46
rockford
It's OK Jay, I think #4 is the best route.

Create the nodes randomly, then check if there is another node within 2 spaces - if so, draw road to it. If not check 2 spaces in another direction.

Then if the ends aren't connected just make a road to the nearest road/node.

That should work. In theory.



I didn't want for anyone to rush out and create the code for me, just if you'd already done something similar.
Posted : Sunday, 19 November 2017, 06:25
Jayenkai


It's not perfect. It keeps planting "levels" in between other levels, so that you'd end up blocked..
Unless you don't specify numbers, and instead just have the world be roamable..!?


|update| BlitzMax code, btw.. Be sure to run with DebugMode as it often gets stuck in a never ending loop!! |update|

|update| Added "Failure" so it doesn't get stuck in an endless loop |update|

-=-=-
''Load, Next List!''
Posted : Sunday, 19 November 2017, 07:37
rockford
Cheers Jay

I managed to create something a lot simpler that is ideal for my needs, although I still have to put in error checking for stray nodes, but I like your example too.



Here's the GLBasic .EXE for anyone that might want to see it in action. Press SPACE to redo map.

road_node (.zip)

Creates maps like this -



|edit| And yes, I know I could reduce the IF/THEN calls down a bit too (by using WHILE/WEND or FOR/NEXT) when creating the roads
Posted : Sunday, 19 November 2017, 08:07
Jayenkai
Kewly!

There are many roads to a road node!!!

-=-=-
''Load, Next List!''
Posted : Sunday, 19 November 2017, 08:11
rockford
Indeed

There are only so many ways to skin a cat*, but if the cat is made of code then it's infinite.

* Seriously, who wants to skin a cat nowadays, other than some sicko?
Posted : Sunday, 19 November 2017, 08:43
Pakz
That is a lot simpler then what I would've been able to come up with