Construct 2 Random Terrain Generator



ok everyone I am James with app crash course and today I will show you how to create a random terrain generator just as you see here and let's watch what the guy here is gonna do okay okay I did not am animate the actual character for sake of time this is just to demonstrate a random terrain generator and please excuse the lag eNOS of my computer during the screen capture but all of this is a random terrain and I'm going to show you how we did this using constructive so we've got nice hills and rocks and trees dips cuts and valleys and as you can see if you look into the top right corner over here I'm using 760 rocks right now 381 rocks with the Ivy on it and 201 trees in the background so if you're familiar with the construct 2 software you know that you can very well animate your own characters and have various obstacles pop-up coin collections or whatever you want to do you can use any of the sprites that you wish to generate the terrain I'm using rocks here but you can use whatever you would like to use using the formula that I'm going to show you here in a minute and so you can see it is completely random all over the place up down nooks crannies everything so let's get on it let's see what we're doing here okay in your constructive project this is all I have the canvas layout is 800 by 600 I have a kill sprite on the left end of the screen and some creator sprites on the right end of the screen and this is where the magic is happening okay right over here off the edge of the screen somewhere around just over a thousand pixels I have a box with a sign behavior the sign behavior is at every period point 5 this box spawned a terrain rock right next to it halfway overlapping I have another sign box with a period of one second so I got point five in one second and I just copied and pasted these and I changed the variances in the period okay so then right directly under this one I have one that does one second and under this one I have one that does 0.5 so I have 0.5 and 1 I have 1 and 0.5 here so that is just dictating the movement of the sprites so I'm going to drag these over here onto the screen so that you can actually watch the magic here ok I think I had this somewhere right here in the event sheet what I have done is when my arrow key is down which I'm using a keyboard now you can convert this over into app touchscreen if you're familiar with the constructor software then you know how to do that if you are not at the end of this tutorial I will show you a link to my app crash course class where I give full instruction on a complete app build from start to finish using construct two and I explain everything all of the functionality of the software so let's get into this what we're doing here now keyboard writte arrow is down as a sub event the first one I have my sprite to spawning the first rock on a layer called rocks looking for my let's pull this back a little bit there we go okay so sprite is gonna spawn this one it's gonna spawn a rock it's going to set the rock to a random angle and then weight point three seconds and sub event after that it's going to spawn the rock with the grass on it set the angle to a random 360 wait another point three seconds under that it's going to move right on into spawning another one of these original rocks with no grass setting the angle and then I'm going to trigger once while this is happening I'm going to spawn a tree so what 1/2 here happening is two rocks a grass rock and a tree being set when the key is down every 10 seconds I change the magnitude of the sprites from a random 100 pixels to a random 300 pixels so somewhere in the vicinity of here and 300 pixels every 10 seconds the magnitude changes so that means it's going to go way up in the air or way down low but the sine movement itself keeps the rocks bouncing around so let's see if we can see this happening off the edge of the screen here and you see my sign sprites over here these actually start generating rocks in a random pattern see creating the terrain and all this happens off the edge of the screen and then spawning random rocks random generated turns corners in trees I think you just cut stuff but yeah doing some funky stuff here now there we go but anyway you get the idea and it only works when the button is down or when the character is moving you can sure you can change that yourself 510 to 6200 keep your eye on how much data we're using here because it is being destroyed once it runs off the back edge of the screen so the numbers are going to fluctuate but this isn't nothing that construct 2 can't handle they very versatile software I mean it's having no problem creating this this terrain here if these sprites make it off the back end I have a kill switch anytime the rock is overlapping the kill box we destroy it same with this one this one this one the trees the grass I didn't add grass I had actually removed the grass but you can add anything into this mix and this is what you get you kill it off when it hits the back end quickly I'm going to show you how we make these sprites and I'll move across the screen it's a keyboard function also when the keyboard is down or whatever you motion you choose we're going to move the rock a speed variable pixels at angle 180 degrees which is a direct left movement up here I had global numbers speed equals 14 and did a variable because I was playing with the speed on how fast I wanted it to go and then I just used the speed as a variable here for the distance so then that way I could just change it really quickly and see what I want to do without changing all of these at once so also what else did I want to show you okay this moves them to the left miscellaneous I have the guy in where he doesn't actually cross the center of the screen the center of the screen is 400 so if his X variable passes 400 we just stopped him right there and that keeps him from passing over the center of the screen and running up against the edge of the wall over here he stops here and he doesn't go any further than that and he can go backwards but I won't let him go any further because it would just make for some really crappy gameplay if he ran past the screen and was bumping up against the wall so that's how I did that also one more thing is this is all done using the platform functions plugins behaviors the guy has a platform bound to layout so that he doesn't go this way or that way by instance if this was if I didn't have that failsafe he would be able to jump off the edge of the screen or this way as well so I bounced a layout scroll to so that when he does go up in the air when the mountain gets really high you can go up there with it and this screen follows him and the platform function and then the rocks the rocks are just solid solid behavior actually that's right the rock would be grass on it it's not a solid it's just there for looks that way it actually gives some depth to the game he's only actually stepping on these these are solid this is not a physics game if this was physics with this many elements on the screen you would never be able to keep up with it but since it is platform and solid he can step and run across those rocks and they run across the screen has no problem generating and they're destroyed on the other side on the start of the layout I randomly did repeated 10/10 of the grass rocks changed the angles made some trees and then I did again a 50 times again as a sub event so I created another rock and a change the angle to random angles now this being 50 times underneath this repeat 10 is actually 50 times 10 is how many we're making so that means 50 times repeated 10 times so that gives a very very broad selection of rocks here that way they didn't have any holes or gaps in it this looks like solid ground make sure I didn't miss anything changing the magnitude every 10 seconds and then destroying them and that is it a complete terrain generator in under 30 events for more information you can visit app crash course comm if you want to take the full course on how to create a game mobile app Android app is what I do this is a course that I give on you to May and there is a link on your screen thanks everyone for watching and I will see you soon you

11 Replies to “Construct 2 Random Terrain Generator

  1. Hey guys! For my fellow construct 2 users I offer 2.00 a month hosting packages! You can now have your own domain for all your games!
    http://carolinacloudtech.com/accounts/cart.php

  2. un comentario en espaƱol salvaje a aparecido!

    – Putin hace movimiento spam!

    ajvfajivohvgogveƱhgh

    – es muy efectivo

    -Putin se emociono

    -emocionar causo retraso

    -Putin se golpeo en los huevos

    -Gope critico

    -Putin murio :c.

    – el comentario suvio a nivel estupido xD

Leave a Reply

Your email address will not be published. Required fields are marked *