How can i make Hills within my world generation array?

Get help using Construct 2

Post » Sat Dec 06, 2014 2:52 pm

[img][IMG]http://i976.photobucket.com/albums/ae242/emoneydatruth/Capture_zps2f4de633.jpg[/img][/img]

I was wondering how to manipulate my array to create hills, I understand how to generate flat lands but im looking to get a more natural terrain feel. My code is in the link, It just need some advice to lead me in the right direction.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,368

Post » Sat Dec 06, 2014 4:44 pm

Anything on this subject would be awesome to hear from someone, I really am starting to like array terrain generation i just cant wrap my head around making more natural hills and cave systems.
Thank you for reading this everyone.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,368

Post » Sat Dec 06, 2014 6:36 pm

B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Sat Dec 06, 2014 6:56 pm

@R0J0hound thanks for posting this! One thing that kinda bugs me about the addon is the tutorial/demo only has one line of code inside. Its not really explaining how to make things happen.
Unless you are pretty knowledgable about this stuff or have went to school its going to be hard to understand that.
How could i use that addon with my array? or with that addon do i even need an array to generate my tiles now? it seems like the plugin will generate your tiles aswell but please correct me if im wrong,i love arrays but there is so much i need to ask and learn.

I read 2 of the articles you posted and i really understand it alot better than a year ago when i just started but i still need to ask this. I was rasied on construct 2 and with the event system set up the way it is ive learned differently and have come a custom to learning through visual means,With that said i want to ask how i can take the info from different engines or other people in general into construct? Looking at code to me is alittle off since i am used to the event based system.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,368

Post » Sat Dec 06, 2014 8:10 pm

Well I only know what I read about it and it isn't really something you learn in a school.

Basically the plugin allows you to make perlin or simplex noise (look them up to see what they look like). The plugin uses a "seed" for the randomness so with the same seed noisejs.perlin2(0.5, 0.1) for instance will always give the same value, whereas c2's random() will give a different value every time.

Now from what I've read and messing with the plugin this is some info about the expressions.
noisejs.perlin2(x, y) returns a value from -1 to 1.
The example capx translates that to a value from 0 to 100 for opacity. You could just as well set it to 100 or 0 by comparing if the value of noisejs.perlin2 is greater than 0. That would give blocks or no blocks instead of smooth noise.
The parameters x and y should be non integers to give differing values. That is why the example divides loopindex("x") and y by 10 in the expression. I guess that can be thought of as a scaling factor. If you use just integers you'll get just 0 returned.

Now that we've got some of the low level stuff out of the way the idea to create hills instead of just blobs is by combining perlin noise with something else. This link shows to combine the perlin noise with a vertical gradient to get the hills. After that the rest of the info loses me, probably because it's for some noise library.

Ok to use that let's do what the example capx does and loop over all the squares. This can be done any way you want whether with an array or no. It makes little difference.
Code: Select all
width = 100
height =100
noise_scaling = 1

for x from 0 to width-1
for y from 0 to height-1
---- solid?


So your perlin noise at every point would be:
noisejs.perlin2(x/width, y/height)
or with scaling noisejs.perlin2(x/width*noise_scaling, y/height*noise_scaling)

We also only want block or no block instead of shades of blocks so we can just place a block if the perlin noise is greater than 0. It would then look like this:

Code: Select all
width = 100
height =100
noise_scaling = 1

for x from 0 to width-1
for y from 0 to height-1
noisejs.perlin2(x/width*noise_scaling, y/height*noise_scaling) > 0
--- create block


So far so good but that just gives blobs everywhere. A solution is to add a vertical gradient to it.
This can do it: lerp(-1, 1, y/height). It will give -1 for the top 0 for the center and 1 for the bottom. So you expression is now
noisejs.perlin2(x/width*noise_scaling, y/height*noise_scaling) + lerp(-1, 1, y/height)> 0
Which will give more or less hills centered vertically.

There's probably more you can do such as shift it up and down by adding a number but the general thing to do is fiddle with the numbers and experiment until you get something you like.
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Mon Dec 08, 2014 8:51 am

@R0j0hound Thank you for going in depth with your response, The details you have given are great but i think im lacking the basic principles on how to use this addon inside of construct 2. I followed your guide to the best of my understanding but im not comprehending this right, my perception is a bit off.Perlin noise is imo the best choice.

I really like what im seeing from this addon but i really can not afford to sit back and spend alot of time trying to implement something that there is very limited information about on the scirra forums.

Like my main question states, Is it possible to make this happen with my array? I think i would be better suited to try it with my array generation since i can understand how to use the array alittle better than Perlin Noise.

Thank you for helping me thus far with the info i need, It really helps to have people like you on these forums thanks again R0j0hound.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,368

Post » Mon Dec 08, 2014 5:36 pm

Doing it with an array is just as easy. The only difference really is you're setting a value to the array instead of creating the object right away. You could do it in two passes but really it's basically the same as above.

array for each xy
--- array set at (array.curX, array.curY) to noisejs.perlin2(this.curx/this.width*noise_scaling, this.cury/this.height*noise_scaling) + lerp(-1, 1, this.cury/this.height)

array for each xy
--- array set at (array.curX, array.curY) to this.curValue>0

With that it's just one material. For two you could do

array for each xy
--- array set at (array.curX, array.curY) to round(max(this.curValue*2))
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Mon Dec 08, 2014 6:33 pm

@R0j0hound Your first exspression has gotten me alittle confused and i dont see myself learning Perlin Noise without alot more insight but i think i understand the other 2. What is confusing me the most is when you say Material.. When you say Material do you mean Sprites?

Also when i would set my array.curX,array.curY to curValue>0 nothing is happening at all, Its just making the values what they already were in the first place.
This seems like its very easy im just not seeing things how you are seeing them. I have everything else down when it comes to generating a flatland.I spent 2 and a half days trying to come up with something that would work for me. Ive went back to construct classic and even looked at posts from 2011 but none are straight forward about this information, There are more than a dozen ways to make this happen and im having a hard time trying to figure out the most basic.

I do not know how to make this happen at all, what you are telling me i understand but i do not know how to place it inside construct 2 for it to work as its supposed to. does this expression replace my very first For Each Event? Or my For Each Event right before i create my blocks?
I tried both and still am getting the same outcome. This code is very delicate to me since i have spent alot of time trying to memorize what does what and how it does what it does.

Im changing alot of values inside my CapX because i have different sprites that spawn the deeper you go underground thats why im really lost. I dont know why i cant see what you see.




This link below shown me alot but still does not go into depth about how to make the ground different heights/Hills or even elevation changes.
https://dl.dropboxusercontent.com/u/581 ... ration.pdf

This one i cant remake because its different how you set this up with construct 2
https://dl.dropboxusercontent.com/u/581 ... al.doc.pdf

The pdf files are from years ago and its all i found that teachs people like me how to do this stuff from the ground up in a very detailed fashion. You still can not step by step these tutorials in C2 i tried and failed.
The issue is im getting slices of info when i need the whole pie, It would be awesome to find a pdf on how to do this in C2, Most (But Not All) people use C2 because they lack skills in some sort of area of game development and its almost a must that there would be some kind of write up on how to use the array for generation in the most basic of ways. Im sorry for venting alittle bit in this post, Ive wasted alot of time on my own trying to figure this out i just dont want it to be for nothing. Thanks a ton R0j0hound i might have already given up if it wasnt for your posts! I really mean that.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,368

Post » Mon Dec 08, 2014 10:58 pm

By material I mean rock/dirt/air/etc... In the array it would be just an integer like 0 for air, 1 for dirt, 2 for rock...
But to be simple you can do 0-air and 1-dirt.

The attached capx has almost every kind of terrain generation I could think of. At the very least it gives something to play with. Basically any sort of generation will be an equation and you then fiddle with the numbers to get different effects.

Most of it isn't very complicated, not even the equations, although they can look busy. I'll break down one of them, the "dual sine":
Code: Select all
(2+rnd1)*sin((2.1+rnd2)*360*Array.CurX/40+33*rnd3)+(3+rnd4)*sin((1.5+rnd5)*360*Array.CurX/40)+15

Basically this is two sine waves added together. The general form of a sine equation is:
y = amplitude * sin(frequency * x + offset)
When two or more sine equations (with different amplitude, frequency and/or offset ) are added together you get an interesting smooth curve. All the numbers are pretty much arbitrary except for 15 which is centering it vertically in the array. The only other values that are somewhat important are the ones that define the amplitude such as (2+rnd1) or (3+rnd4), which I picked to make sure the hills don't get too high or low. As it is it has a vertical range of 14.
You do not have the required permissions to view the files attached to this post.
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Tue Dec 09, 2014 4:43 am

@R0j0hound Thank You!! This is exactly what i needed to see. how you have set your terrain generation up is not how i would of thought to set this up.
The logic you used is way past my lvl right now but i will learn it through.
Dual sine is what im going to use, You have sold me on that! I never knew that the sine could be used in this way and like you said the expression looks more complicated than it really is. Thanks for explaining all off this to me R0j0hound.Im going to further examine your file and try to learn it alittle better aswell.

This is by far the ultimate terrain generation for construct 2, R0j0hound do you want me to upload the capX to the Main capX Tutorial Section?
I think alot of users could benefit from your help here.

I have one last question about arrays if you still have time, The question is in regards to Arrays and Animation Frames.
as you seen inside my original photo i have figured out how to set animation frames according to the X,Y positions inside the array but what if i wanted it to be alittle more dynamic?

For example i generate my ground tiles within the array first then i set my animation frames underground to the respective stones/ores i need which is so far so good but my issue is this, How can i check if my upper most ground sprite is exsposed to AIR? What i tried to do was place logic inside my project that checked if a sprite inside my array was exsposed to air and if this was true i would change that sprite to a grass covered ground tile.
I know how to check things at Offset but how would i go about doing that inside the array? This is the only true way to dictate and manipulate what goes on within the array and have things change in a natural fashion.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,368

Next

Return to How do I....?

Who is online

Users browsing this forum: ksiads, marc254, marcinkowski, mtnboy22, Rable and 5 guests