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.
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:
Or like your image, depending on what parameters you use. There's C source available here.
No comments:
Post a Comment