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.
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.
Here are a big list of approaches:
http://gamedev.stackexchange.com/questi ... -a-2d-game
http://www.gamedev.net/topic/630940-how ... eneration/
http://www.somethinghitme.com/2013/11/1 ... placement/
Also this plugin will come in handy
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.
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.
width = 100
noise_scaling = 1
for x from 0 to width-1
for y from 0 to height-1
So your perlin noise at every point would be:
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:isiwr3f9]width = 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[/code:isiwr3f9]
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.
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.
Develop games in your browser. Powerful, performant & highly capable.
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 set at (array.curX, array.curY) to this.curValue>0
With that it's just one material. For two you could do
--- array set at (array.curX, array.curY) to round(max(this.curValue*2))
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.
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":
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.
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.
Well to check if a certain tile at say x,y has air above it you can do this:
Array at (x,y-1) = 0
So to do it for everything do this:
Array: for each xy
Array current value >0
--- create tile
------- Array at curx,cury-1 = 0
------------ make tile grass covered
R0J0hound im having an issue with figuring out if the cell is empty because if my cell is equal to 0 and my animation frames adjust to the value of the array.
dirt = 0
grass covered = 7
If an empty cell is equal to 0 that is giving me an issue because if it is empty it will always make the sprite that occupies that cell Frame 0
Instead of setting the cells to just animation frames you'll need a value for empty cells, so you know whether or not to create a tile there. 0 is the best value for that since 0 is the default cell value and cells outside the array are always zero. You could store the animationFrame+1 so 0 would be empty and then you could set the animation frame to array.at(x,y)-1 so 0 in the array would be frame 0.
Sorry for bringing up an old post, but I was searching to see if Construct had a certain capability when I came upon this thread, and thought it would be relevant.
Is it possible to generate smooth terrain in construct? Such as in Tiny Wings -
Dynamic generation aside, my first approach was simply to draw the whole level as a sprite, but I quickly learned that method is not viable due to memory constraints when creating levels of any significant size. Ref: https://www.scirra.com/blog/112/remembe ... our-memory. However for smooth non repeating seamless surfaces, tile maps don't really work.
My next idea was to generate terrain as described in this thread, except with single pixel sprites. However, without anti-aliasing, the result was still far from smooth. It would also create thousands of objects on screen which I would assume cause a huge performance hit.
I've created similar in vector based applications like Flash, but the solution to this in Construct is so far eluding me.
Edit: Found your Canvas plugin plugin-canvas_t64239?&hilit=canvas. Can't believe I hadn't utilized this before... it looks like this is what I needed. I guess I'll see what I can come up with after experimenting and learning how to use it.