Better Random Terrain via Midpoint Displacement

0 favourites
From the Asset Store
Build your map with these isometric objects and terrains
  • Thanks very much for this. I used it to learn how to use arrays in Construct2 (they made my head hurt initially), and i've now turned it into a decent terraria lite demo.

    I've got multiple block types (gold etc), placeable ladders, placeable blocks, grass that regrows over time based on certain rules, realtime lighting, etc. I got very inspired lol. Learned so much from your code. Wasn't aware of the bit technique for tile selection, thanks again. :)

    That's awesome! I"m glad you and everyone else find this helpful.

    I hope you show us your project soon!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Just posted in another thread regarding ladder usage in my game. Has a screenshot. Doesn't show too much though, just the ladder stuff.    <img src="smileys/smiley36.gif" border="0" align="middle" />

    I'll post more in this thread later as my project continues.

    Ladder FAQ Thread Link :

    scirra.com/forum/topic45310_post404704.html

  • One other thing, I found a very simple method for making tunnels and/or resource spawns during world generation. Instead of using complex math, I just made a few sprites in the shape of clumps of minerals, and a few more in the shape of tunnels (you can make a few variations and/or use rotation or scaling to make it more randomized). Then:

    1) Generate world as usual using method in this thread

    2) Place X number of each mineral/tunnel sprites in randomized positions in the world

    3) Do a hit check against all of the already spawned ground blocks

    4) Any ground blocks overlapping mineral sprites get converted to mineral blocks of appropriate type, then update block arrays accordingly

    5) Any ground blocks overlapping tunnel sprites get deleted, update array

    6) Delete all mineral and tunnel sprites

    7) Explore your world full of gold and silver deposits, and caves <img src="smileys/smiley17.gif" border="0" align="middle" />

    I also plan to use this method for creating pre-fab rooms and caves with spawned objects/props inside. Since you can add multiple registration points to sprites, you can use them to specify the spawn points for props before deleting the world creation sprites.

  • All the loops and the array.... anywhere to point me to, to understand it properly ?

    If you're still interested I can try to explain it.

    If you specifically want to understand the bitwise tile selection method, this does a really good job of explaining it.

    saltgames.com/2010/a-bitwise-method-for-applying-tilemaps

  • Lol I was writing a post explaining it, then realized the original capx had been updated since I grabbed it last. Complete rewrite, now i'm confused.    <img src="smileys/smiley36.gif" border="0" align="middle" />

    In particular the bitsolver used when destroying blocks after generation has changed a fair bit. The "repeat 4 times" X+cos(a)*16, Y+cos(a)*16 method has been replaced with a bunch of if/then loops.

    Can you explain the main changes in the project and reasons for them?

    In particular, can you explain this comment "You WILL have to change how it create tiles, as right now it will create every tile stored in the array to your specified X point."

  • 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!

  • 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.

    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. <img src="smileys/smiley2.gif" border="0" align="middle" />

    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. <img src="smileys/smiley9.gif" border="0" align="middle" />

    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.

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

    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).    <img src="smileys/smiley1.gif" border="0" align="middle" />

  • No feedback?    <img src="smileys/smiley1.gif" border="0" align="middle" />

  • 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.

  • 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.

    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):

    dropbox.com/s/5cgbiwk34i8o774/EngineDemo_SE.exe

    And yeah, I think I might create a seperate thread eventually. Anyhow thanks for taking a look.

  • 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 :)

  • 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 :)

    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.

  • 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!

    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.

  • 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 :/

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)