[Example] Procedurally Generated World

Post your Construct-made creations!

Post » Thu Jan 13, 2011 8:52 pm

UPDATE:
-replaced sprites, added shrubs, added bg sprites to give the "cave" feel to it.
-the download link below has been replaced
-currently working on making larger worlds using multiple layouts.
----------------------------------------------------------------------------------------
Here's an example of procedural generation using Perlin Noise. Some screenshots-


Here's the cap file-
[url:1awd9spn]http://dl.dropbox.com/u/5811650/Blizzard/pertilegen%20v0.3.cap[/url:1awd9spn]

The caveman sprite is from the Asemblee Art Assets. The remaining art was done by Steven.
Link-[url:1awd9spn]http://www.scirra.com/forum/viewtopic.php?f=23&t=7128[/url:1awd9spn]

Thanks to 'newt' for introducing me to the Perlin Noise plugin(it's actually his .cap file on which I've been working)
B
9
S
3
G
3
Posts: 366
Reputation: 2,301

Post » Thu Jan 13, 2011 9:01 pm

actualy i like the tileset and especialy the caveman dude :) it kind a.... nostalgic ^^
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Fri Jan 14, 2011 6:23 pm

I like it, hope you'll continue improving it. To create water, there is good R0J0hound's example
viewtopic.php?f=2&t=8050
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Sat Jan 15, 2011 2:23 am

[quote:38d0opvc]The current problems are-
Inability to generate large worlds.
Cannot implement fluids(lakes etc)
Saving and loading.(trees cannot be saved as there is no info about them in the array)[/quote:38d0opvc]

To get a large world you can set perlin to a larger size... say 100 x 100, then set your loop to 50 to 100 for another layout.... using the same seed.

Not sure what your looking for in terms of fluids, but the cap shows one possibility while showing a possible optimization using one sprite set to different frames.
[url:38d0opvc]http://dl.dropbox.com/u/666516/perlincraft.cap[/url:38d0opvc]
Keep in mind you've only used the positive values in the noise. There are a few things you can do with the negative as well.

As far as trees... All I can think of is making an array of all the created sprites, and then saving, and loading it as an external array.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sat Jan 15, 2011 2:44 am

[quote:1y69p798]To get a large world you can set perlin to a larger size... say 100 x 100, then set your loop to 50 to 100 for another layout.... using the same seed.
[/quote:1y69p798]
that could help, but is there any other way like drawing the sprites only when it is in the given distance range from the player? that way I won't have to switch layouts

[quote:1y69p798]Keep in mind you've only used the positive values in the noise. There are a few things you can do with the negative as well.[/quote:1y69p798]
can perlin noise generate negative values too? I thought that it generated values between 0 and the max value.

[quote:1y69p798]As far as trees... All I can think of is making an array of all the created sprites, and then saving, and loading it as an external array.[/quote:1y69p798]
thanks that would certainly help. :)
B
9
S
3
G
3
Posts: 366
Reputation: 2,301

Post » Sat Jan 15, 2011 6:26 am

Nice example.

For the world size just keep in mind that the perlin's size is independent from any other sizes. You can create a virtual huge world (by setting the width and height of the perlin noise) and then use certain methods to draw the world's current section, like the one newt explained. But there is no limitation (You already experienced this, because in your example you lookup the perlin table at positions outside the perlin's size. It is set to 30x30, but you look up to 50). Just set a "sight-range" half the units of one screen. Then when moving lookup the perlin at sight-range and draw the appropiate sprites (or delete them if they are out of sight). In your example one perlin unit equals one sprite, and one sprite is 32x32 pixel. For one screen (your window is 640x480) that means 20x15 perlin units, and so you would look at your player's unit +/- 10 horizontal and +/- 8 vertical.

perlin noise is generated around zero on both sides, negative and positive. If you set 4 you will get a value between -4 and +4

For the trees: Why not make multiple use of values? For example, if you would use integers from 0 to 100, you could define that 50 represents grass, while 51 represents grass with a tree on top, and so on.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Jan 15, 2011 11:17 am

[quote="tulamide":3ud3g966]
For the trees: Why not make multiple use of values? For example, if you would use integers from 0 to 100, you could define that 50 represents grass, while 51 represents grass with a tree on top, and so on.[/quote:3ud3g966]

Aha... trees solved
[code:3ud3g966]+ System: int(PerlinNoise.GetNoiseAt(LoopIndex("x"), LoopIndex("y")-1)) Equal to -1
-> System: Create object tree on layer 1 at (mud.X-16, mud.Y)[/code:3ud3g966]

^Link updated
[url:3ud3g966]http://dl.dropbox.com/u/666516/perlincraft.cap[/url:3ud3g966]
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sat Jan 15, 2011 12:43 pm

man I want play so badly with those cap files but can't, bloody exams are going on so can't do much. :(
I'll probably develop this in to some sort of game, not now...maybe after march.

[quote:20s52cue]perlin noise is generated around zero on both sides, negative and positive. If you set 4 you will get a value between -4 and +4

For the trees: Why not make multiple use of values? For example, if you would use integers from 0 to 100, you could define that 50 represents grass, while 51 represents grass with a tree on top, and so on.[/quote:20s52cue]
great idea, this way i could generate some pretty good looking variations like just grass, grass with a flower or grass with tree.

[quote:20s52cue]^Link updated
http://dl.dropbox.com/u/666516/perlincraft.cap[/quote:20s52cue]
thanks man,but i haven't downloaded the cap though, I don't want to ruin the fun of learning how to do this on my own. Hope you don't mind :)
B
9
S
3
G
3
Posts: 366
Reputation: 2,301

Post » Sat Jan 15, 2011 1:45 pm

No prob.
Since your in a learning mood.....
You can also take a "slice" of the noise, or get the data from a single axis.

[url:2rpmci3y]http://dl.dropbox.com/u/666516/sea.cap[/url:2rpmci3y]
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sun Jan 16, 2011 10:03 am

[quote="newt":2nszpcuj]No prob.
Since your in a learning mood.....
You can also take a "slice" of the noise, or get the data from a single axis.

[url:2nszpcuj]http://dl.dropbox.com/u/666516/sea.cap[/url:2nszpcuj][/quote:2nszpcuj]
Cool idea!
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Next

Return to Your Creations

Who is online

Users browsing this forum: No registered users and 2 guests