Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Passable terrain paths algorithm?  (Read 3365 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Posted 2005-12-21 21: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
Check out GAMADU (my own site) @ http://gamadu.com/
Offline DzzD
« Reply #1 - Posted 2005-12-21 21: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

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #2 - Posted 2005-12-22 06: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
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arne

Senior Member




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


« Reply #3 - Posted 2005-12-22 09: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 ::
Offline JAW

Senior Member


Medals: 2



« Reply #4 - Posted 2006-06-08 19: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
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #5 - Posted 2006-06-12 13: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!