Sunday, May 19, 2019

javascript - How do I generate terrain like that of Scorched Earth?



I'm a web developer and I am keen to start writing my own games.


For familiarity, I've chosen JavaScript and canvas element for now.


I want to generate some terrain like that in Scorched Earth.


Scorched Earth


My first attempt made me realise I couldn't just randomise the y value; there had to be some sanity in the peaks and troughs.


I have Googled around a bit, but either I can't find something simple enough for me or I am using the wrong keywords.


Can you please show me what sort of algorithm I would use to generate something in the example, keeping in mind that I am completely new to games programming (since making Breakout in 2003 with Visual Basic anyway)?



Answer



The midpoint displacement algorithm is exactly what you want.


That link can generate something like this:



enter image description here


Or like your image, depending on what parameters you use. There's C source available here.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...