Random Generated Terrain for Side Scroller

Apprentice
Posts: 7
Joined: 2009.03
Post: #1
I'm working on a new game for which I want to make a boat drive across a water terrain(to the right horizontal). I want to randomly generate the water terrain as I want to increase it's height and add in larger waves, never having the same layout. Maybe even place ramps in randomly. I'll need collision detection to make sure the boat... floats on the water (not sure how I'll do that on random terrain).

Anyway just looking to brainstorm on the best practice to accomplish this. I'm going to try out cocos2D (first time), and was thinking about using TileMaps, but have never used them before so not sure how well it applies.

Any thoughts appreciated.
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2009.05
Post: #2
Here's one possibility I've used before to generate random surfaces.

Divide it horizontally into columns - the more columns, the finer the variations in the surface you can generate. At the finest level, each column would be just one pixel wide.

Then you have an array storing the height of each column (eg, from the bottom of the screen), which you can use not only to draw from but to do the collision detection as well. If your columns are wider than one pixel, you can interpolate intermediate positions using straight line math.

You could add ramps in exactly the same way in a number of different ways - I'd probably have an array with the same number of columns as your water, but the difference being that the height is zero unless there's a ramp there. But you could also have an array the same number of columns wide that says "this column is water" or "this column is (part of) a ramp".

To scroll, all you're doing is iterating through the array and drawing each column. To scroll left, you move right in the array, or move all the array elements left and add a new one on the end.

Hope that makes sense. I'm sure it's not the only way, but it's worked for me in the past.

Regards,
Lindsay
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2009.03
Post: #3
Thanks for the thought. I think I'll do just that, it seems straight forward enough. The only draw back being is that I can't texture the water then. It will have to be a solid color or fill pattern I suppose.
Perhaps I could blit the size of the column from a large water image and see how that looks...
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2009.05
Post: #4
OldJames Wrote:Perhaps I could blit the size of the column from a large water image and see how that looks...
Another way would be to fill the entire screen with a water texture (or at least enough of the bottom of the screen that the water would never be any higher than that), then for every column, erase from the top of the screen/drawn water down to the actual top of the water. This way you'd have no texture repetition or joins Smile

L.
Quote this message in a reply
Member
Posts: 46
Joined: 2008.10
Post: #5
Any chance you could post a quick sketch of what your side-scroller looks like? I'd love to help, but I could use a little help understanding exactly how you want your terrain to work. Thanks either way!

"Who's John Galt?"
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2009.03
Post: #6
Sure, any help appreciated. I decided to try composing the terrain from sprites. But performance is lost at 25 plus

[Image: sketch.jpg]
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2009.03
Post: #7
I should add some specifics, thanks for any help.

I've changed from the original thought of a boat game to an airplane game in order to simplify the learning curve. Didn't wana bite off too much. I want to fly an airplane, and have a random generated terrain (the ground) that has varying heights, maybe a mountain or two... and have it scroll from right to left, and then have collision detection in the case of a crash into the ground... I did decide to take advantage of the cocos2d API.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ? Please help: 2D scroller Level Designs Elphaba 5 3,238 Jun 15, 2009 04:06 PM
Last Post: AndyKorth