# Better Random Terrain via Midpoint Displacement

Show us your completed creations made in Construct 2

### » Sun Apr 28, 2013 4:57 am

Have you been using Yann's? His method uses those sin/cos equations to locate
the neighbor to check, while mine will check based on set variables in the if/then loops you're talking about. They both do the same thing, but his is more graceful, and I really like how he did it. Mine is a very straightforward approach, but uses a lot of actions.

If you've been going off of his example, I would say to stick with his.
It sounds like you have been, so keep doing that! Mine was more intended for an example of one way to implement it and show it could be done, but I'm not a super wizard so it uses more events than it should. Then Yann made it into, in my view, a proper implementation for a game with more control over the generation and is overall a cleaner and efficient method. He did an awesome job making it better with his optimizations and I learned quite a bit from it, so thanks Yann!

Lastly, I put that disclaimer into mine because it's an example and not very efficient. More specifically, where you pointed out, it will create EVERY tile in the "lvl" array. This is fine when it's in a small scale, like how it is now you shouldn't get more than 7-8,000 tiles/objects in your layout. But if you go larger than that, like say to a terraria sized level, you're going to get tile counts to the millions. Just a small sized level in terraria is 4300x1200, or 5,160,000 potential tiles. You're not going to want to create all of those tiles, it'll bog and become unplayable. You'll want to implement some way to only have a set amount of tiles in your layout at once, such as what's going to be seen in your game window. I've got something already made that I can make an example from and show you if you want.

Best of luck with your game!
B
12
S
2
G
4
Posts: 44
Reputation: 2,389

### » Mon Apr 29, 2013 1:34 am

[QUOTE=Intrepid]I put that disclaimer into mine because it's an example and not very efficient. More specifically, where you pointed out, it will create EVERY tile in the "lvl" array.[/QUOTE]

I guess I was using Yann's version of this to base mine on. It uses the mathematical tile selection method instead. Like you said, less actions.

And yeah that's what I thought you meant regarding the "every tile" comment. In my current implementation I have anywhere between 1500 to 2500 tiles depending on the randomization. I'm also using the optimization where any non-edge blocks turn off their solid behaviour. And, i'm carving out caves to decrease block counts (and they're cool, lol). Between these tweaks, I get an average framerate of 30 or so in a browser, 60 on pc executable. I'm using some gameplay mechanics to explain the smaller slice of the world you get to explore.

But, I also allow the player to warp in and out of areas, and you're put in a "new" randomized area each time. Funny thing is, the block counts aren't killing me, it's AI. All I need to do is add a small number of bunnies (my test AI) with platforming behaviour and it starts bogging down. I'm not sure if it's their platforming or animations, but probably the former. Dammit, they look so cute jumping around and finding their way out of holes. And they blow up real good.

I'm very close to posting an early version of my project online (site, not capx), i'll link it here once I do. Thanks for the reply.Venivididormi2013-04-29 01:37:35
B
8
S
2
Posts: 63
Reputation: 1,223

### » Thu May 09, 2013 12:06 am

Finally got a dropbox account, here's a pc build. This is a self-extracting .rar file.

https://www.dropbox.com/s/5cgbiwk34i8o774/EngineDemo_SE.exe

Features:
-Home screen where you can get healed and warp to new locations
-Alien overlord who follows you around giving orders (for future plot exposition and tasks) and does the healing
-Randomized game world where you can use a variety of tools
-Player can request a portal back to the home screen
-Player will automatically be warped back and healed if they are going to die
-Player can take damage from bombs or drowning in water
-Chests which contain jewels and/or health pickups
-Jewels provide XP which level the player up
-Bunnies! (they like grenades, really they do)
-Use pick to mine 3 resources: dirt, iron, gold (can't craft anything with it yet lol)
-Lights can be placed and reveal the terrain (requires webgl capable system) and use a different sprite depending on how they're placed
-Bombs can be placed to destroy terrain or lights/bunnies/trees.

It's not a currently a commercial project, so i'm using placeholder assets from a variety of sources like braid, terraria, tmnt, etc. It's also very simple, not much to do but run around and kill bunnies, mine, build ladder bridges etc. and level up. It's basically just an engine demo/test like the name suggests.

Let me know what kind of framerates you get, and whether the lighting works for you (and if so what you think of it).     Venivididormi2013-05-22 03:18:26
B
8
S
2
Posts: 63
Reputation: 1,223

### » Tue May 21, 2013 9:54 am

No feedback?
B
8
S
2
Posts: 63
Reputation: 1,223

### » Tue May 21, 2013 7:44 pm

Sorry there, been really busy lately. I remember trying to test it, but there were errors when I tried to extract it. Can you try repackaging it?
Also, you might get some better visibility if you create a thread for it over in My Creations. More people seeing it, more people trying it :)
Anyway, I'll try again tonight, and redownload it.
B
12
S
2
G
4
Posts: 44
Reputation: 2,389

### » Wed May 22, 2013 3:17 am

[QUOTE=Intrepid] Sorry there, been really busy lately. I remember trying to test it, but there were errors when I tried to extract it. Can you try repackaging it?
Also, you might get some better visibility if you create a thread for it over in My Creations. More people seeing it, more people trying it :)
Anyway, I'll try again tonight, and redownload it.[/QUOTE]

Lol, I just realized why you got an error. The file inside the .exe had the same name as the .exe so it caused an overwrite error.

Try this instead (updated original post as well):

https://www.dropbox.com/s/5cgbiwk34i8o774/EngineDemo_SE.exe

And yeah, I think I might create a seperate thread eventually. Anyhow thanks for taking a look.Venivididormi2013-05-22 03:20:14
B
8
S
2
Posts: 63
Reputation: 1,223

### » Sat May 25, 2013 4:46 am

I got to take a look at it, works well and plays smoothly. I did get a bit confused when I was at the top of the level and it was all dark. I am curious how you did the lighting though, how did you implement that?
I hope you keep going with it, I'll be looking out for the thread :)
B
12
S
2
G
4
Posts: 44
Reputation: 2,389

### » Sat May 25, 2013 8:43 pm

[QUOTE=Intrepid] I got to take a look at it, works well and plays smoothly. I did get a bit confused when I was at the top of the level and it was all dark. I am curious how you did the lighting though, how did you implement that?
I hope you keep going with it, I'll be looking out for the thread :)[/QUOTE]

Thanks. :)

When you're at the top/spawn point there's supposed to be a light that spawns next to you, need to look into what broke that.

The lighting is my favourite part, it was fun figuring it out. Essentially every block/prop in the world has a brightness value. Every time it needs to be recalculated I find the nearest light to each block/prop and use distance to calculate brightness. It's then "baked" and I don't need to recalculate lights again until something specific happens like breaking a block, placing a light, etc. As well, since it only uses the nearest light to calculate, adding more lights doesn't slow the game down.

Despite the fact that it runs well and looks good, i'm considering switching to the method shown in the construct example files (using blending). My lighting method only works if you support webgl, which I don't like.Venivididormi2013-05-25 20:51:53
B
8
S
2
Posts: 63
Reputation: 1,223

### » Sun Jun 30, 2013 11:11 pm

[QUOTE=Intrepid] Have you been using Yann's? His method uses those sin/cos equations to locate
the neighbor to check, while mine will check based on set variables in the if/then loops you're talking about. They both do the same thing, but his is more graceful, and I really like how he did it. Mine is a very straightforward approach, but uses a lot of actions.

If you've been going off of his example, I would say to stick with his.
It sounds like you have been, so keep doing that! Mine was more intended for an example of one way to implement it and show it could be done, but I'm not a super wizard so it uses more events than it should. Then Yann made it into, in my view, a proper implementation for a game with more control over the generation and is overall a cleaner and efficient method. He did an awesome job making it better with his optimizations and I learned quite a bit from it, so thanks Yann!

Lastly, I put that disclaimer into mine because it's an example and not very efficient. More specifically, where you pointed out, it will create EVERY tile in the "lvl" array. This is fine when it's in a small scale, like how it is now you shouldn't get more than 7-8,000 tiles/objects in your layout. But if you go larger than that, like say to a terraria sized level, you're going to get tile counts to the millions. Just a small sized level in terraria is 4300x1200, or 5,160,000 potential tiles. You're not going to want to create all of those tiles, it'll bog and become unplayable. You'll want to implement some way to only have a set amount of tiles in your layout at once, such as what's going to be seen in your game window. I've got something already made that I can make an example from and show you if you want.

Best of luck with your game!
[/QUOTE]

I would love to see the example of only having a set amount of tiles in your game window at once.If this is possible i could do things i never thought possible with construct 2. Im making a terraria/Minecraft style of sandbox game.
GMO FOOD = DEATH
B
24
S
9
G
5
Posts: 567
Reputation: 6,428

### » Sat Aug 03, 2013 7:23 am

How can I make a tree generator for this?

Its just an example, I would need to use some similar code to spawn trees, chests, mobs, and so on,
so if I want, for example, that 1 on 50 blocks (top block) got a tree,
how can I code that?

I thought it would be easy as it has a grass generator for the top blocks,
but after an hour trying I couldn't do it :/
B
6
S
1
Posts: 67
Reputation: 636

PreviousNext

Return to Completed Creations

### Who is online

Users browsing this forum: NickyKitty007 and 0 guests