Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  creating a random path  (Read 3132 times)
0 Members and 1 Guest are viewing this topic.
Offline h3ckboy

JGO Coder

Medals: 5

« Posted 2010-04-04 06:44:50 »

hey fellow JGOers,

I have been working on a tower defence, and it is going along quite well. Right now though, I am trying to have an option for randomly generated levels, this is so that the play is not restricted to the few levels included.

I have already tried this, the way I did it, was that I would create a spot, and then create an adjacent spot on an adjacent spot until there were no more spaces left, but this just left it in an infinite loop.

so basically, I am sure that there are some guys out there who done something like this b4, u dont even have to share your code, just could u tell me how you did it?
Offline CommanderKeith
« Reply #1 - Posted 2010-04-04 07:41:36 »

If you've got a list of tiles, just go through and fill them until you're at the end.

For ideas on more complex methods like random maze generation, I found this pretty useful:

Offline h3ckboy

JGO Coder

Medals: 5

« Reply #2 - Posted 2010-04-04 08:15:32 »

thanks for replying,

for the first, do you mean like I was saying??

for the second, I had already seen stuff like that, but it isnt what I want, cause it creates a lot of extra paths as well, this is much simpler
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #3 - Posted 2010-04-04 08:25:29 »

Something like this perhaps?
Offline h3ckboy

JGO Coder

Medals: 5

« Reply #4 - Posted 2010-04-04 08:30:53 »

I dont think that is quite what I am going for.

I will post a screen later, but right now I am abou to walk out the door.

basically what I am going for is a single path, and it generates the path, not the spaces blocking the path, and there are no side paths, just a random path from point a to point b, just think of like bloons(its a TD), it has a path going from the start tot he end, that is what I am going for, just randomly generated.
Offline Wildern

Junior Devvie

« Reply #5 - Posted 2010-04-05 01:41:20 »

Sounds like you just need to work on your heuristics.
You don't want a completely random walk, you want to guide it a bit.
Basically, pick a random starting position along one side.
Pick a direction to be facing.
Then, your choices are to walk forward and add to the path, or turn.
You can't do two turns in a row.
You can only turn after walking for at least two.
You can't walk onto the existing path.
If you get into a case where you cannot perform a legal move and you have not reached the goal point on the other side, you need to discard the path and start over

You can adjust the weight of the random between walking and turning to get lots of straight segments or lots of twisty segments.
Offline h3ckboy

JGO Coder

Medals: 5

« Reply #6 - Posted 2010-04-05 06:23:19 »

ok, thank you. that is very helpful Smiley.

so basically, I would just got through it with loops and have a few ints/boleans along wiht random ints to determine what to do next?
Pages: [1]
  ignore  |  Print  

EgonOlsen (75 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (256 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!