Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (623) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Passable terrain paths algorithm?  (Read 3609 times) 0 Members and 1 Guest are viewing this topic.
appel

JGO Wizard

Medals: 69
Projects: 4

I always win!

 « Posted 2005-12-21 20:07:28 »

I'm making a game where the map is like 2048x2048, and each tile is about 16x16.
What I want to do is to have an random algorithm define what tiles are passable, and the rest are as default non-passable.

But I don't just want to define any random tiles as passable, I want them all to be connected to each other. Example:

How do I do this?

Check out the 4K competition @ www.java4k.com
DzzD
 « Reply #1 - Posted 2005-12-21 20:33:47 »

maybe you can do that way

first you choose a starting pos x,y and set it to "P" then for each "P" pos you randomly select a neighbord and set it to "P" (if possible) and so on

EDIT: you can also randomly decide to do nothing for a  P , this will reduce the numbre of P

Bruno

appel

JGO Wizard

Medals: 69
Projects: 4

I always win!

 « Reply #2 - Posted 2005-12-22 05:38:00 »

I was thinking more on the lines of creating a graph with random vertices in it (nicely distributed over the map), and then connect all the vertices with at least 1 edge (so they're all connected). Then I could simply "walk" the edge between the vertices and mark all the tiles the edge "touches" as passable.

But I don't know how to implement that, or if it's even a good solution to my problem.

Check out the 4K competition @ www.java4k.com
arne

Senior Devvie

money is the worst drug- we should not let it rule

 « Reply #3 - Posted 2005-12-22 08:35:04 »

and then connect all the vertices with at least 1 edge (so they're all connected).

Nah - that doesn't have to work necessarily. You could also get loads of seperated subgraphs.

I think DzzD's way is the best for you. Maybe you could also add a variable that specifies how probably the path changes its direction and so on.

:: JOODE :: Xith3d :: OdeJava ::
JAW

Senior Devvie

Medals: 2

 « Reply #4 - Posted 2006-06-08 17:50:14 »

It depends a little on what kind of map you want to have. A labyrinth differs from a cave, and so on. Do you want it more closed or open? More straight lines and 90° turns or more fuzzy?

You could do a general algorithm which uses parameters. A parameter for wide or thin passable terrain, a parameter for more or less frequent turns in direction, a parameter for big or small changes in direction...

Two ways I could imagine:
1) You set a random starting position and start to "dig". You just define adjacent fields as passable based on some probability. You can use some restrictions for each field to check for constraints. For example you dont set a field passable if it would make the area too wide or if it would make a connection between two passable areas you dont want to connect.

2) First create random paths in your terrain, all with a width of 1. You can make more or less turns, longer or shorter paths, slight or great changes in directions. This gives you a path skeleton. Then widen the paths on your demand. If you want areas connected by small paths, select some fields on the paths and widen that area only. If you want wide winding paths, widen all fields for a small ammount.

-JAW
darkprophet

Senior Devvie

 « Reply #5 - Posted 2006-06-12 11:06:32 »

If you used voronoi diagrams, you define "feature points" loop through the pixels, sort the nearest features from the current pixel and have coeffecient multipliers for each distance on.... An equation says a thousand words:

currentPixel = constant1 * nearestDistance + constant2* secondNearestDistance + constant3 * thirdNearestDistance...

Ofcourse, for performance reasons, i suggest you only need to use the first and second nearest distances, because you can take advantage of that if the first and second nearest distances are very very similar you end up (with the correct coeffecients) is a shallow (or high, depending on the coeffecients) point where pixels have a closely matching . Say if the first coeffecient was positive and the second coeffecient was negative, you would end up near 0 with equal distances.

So then, loop again through the pixels and only make the ones below a certain threshold passable and the rest, nonpassable. It gives a nice, organic feel to map if thats what you wanted.

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 BurntPizza (28 views) 2015-04-23 03:42:11 theagentd (32 views) 2015-04-22 16:23:07 Riven (45 views) 2015-04-16 10:48:47 Duke0200 (56 views) 2015-04-16 01:59:01 Fairy Tailz (40 views) 2015-04-14 20:13:12 Riven (42 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (63 views) 2015-04-10 00:51:04 BurntPizza (64 views) 2015-04-06 22:06:58 ags1 (65 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 16x wessles 15x kingroka123 11x alwex 11x 65K 11x Rayvolution 8x kevglass 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x ra4king 7x Ecumene 7x KevinWorkman 6x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org