I'm looking into adapting the classic "helicopter" game (i.e. http://www.addictinggames.com/helicopter.html), but I haven't yet figured out how to create the walls-generation engine.

Any pointers into the pseudocode? I'm not so interested in the objects in the middle- only the methodology for generating the sides in a way which increases with difficulty (closes in more, has more unexpected curves) as the game progresses.

  • 1
    \$\begingroup\$ Also- to clarify, I need the walls to be more curvy than blocky, since they will actually be "water waves"... \$\endgroup\$ – davidkomer Jan 10 '12 at 7:51
  • 1
    \$\begingroup\$ just do as blocks, but smooth interpolate between each then. \$\endgroup\$ – Gustavo Maciel Jan 10 '12 at 8:14

You could use 1D Perlin noise for that. Here's an image of 2D noise. I took samples where the red line is and multiplied them with some constant to get the green line.

2D noise with 1D section

The constant you multiply the values with is going to determine the height of the noise. So you could easily ramp up the difficulty. Another benefit of Perlin noise is, that it can generate tileable noise, so that you can build a seemingly endless level.

If you want to create a bottom and a ceiling, it's important that you don't generate any impassable areas. The easiest way would simply be to use the "upper" part of the noise (eg. 1.0 - noiseValue) as ceiling and the lower part (noiseValue) for the bottom (with some offset in between of course). If that's looking too dull, you could also consider two close samples, eg. imagine another red sample line one or two pixels up or down. This will give a similar, but not identical wave.

  • \$\begingroup\$ Wow, this was such a help! Thank you :) I'm developing in Flash/Actionscript- and I see there is a built-in perlinNoise function... will play with it and see how it goes :) \$\endgroup\$ – davidkomer Jan 10 '12 at 17:09
  • \$\begingroup\$ @davidkomer I'm glad this is useful. In flash you'll have to create a BitmapData object and use its perlinNoise function. The bitmap can be 800x3 pixels or something extreme, then you could simply extract the top and bottom line values (something like (bitmap.getPixel(x,y) & 0xff) / 255.0 should give you values in the 0..1 range. \$\endgroup\$ – bummzack Jan 10 '12 at 17:37
  • \$\begingroup\$ Hmmm- I got it working, but the constant/multiplier pushes the values into impassable areas... here's my code, any ideas? (vect is a vector of 32 bit values, sampled from the line of perlin noise... so y_val is just the blue channel multiplied by scaler) for(idx = 0; idx < vect.length; idx++) { y_val = (vect[idx] & 0xFF) * scaler; drawData.fillRect(new Rectangle(idx, drawData.height - y_val, 1, y_val), 0x0000ff); drawData.fillRect(new Rectangle(idx, 0, 1, y_val), 0x0000ff); } \$\endgroup\$ – davidkomer Jan 10 '12 at 18:17
  • \$\begingroup\$ I gotta run for now- but something tells me I just need to read your comments more carefully ;) This is where I'm at so far- pastebin.com/1tmMtEAh \$\endgroup\$ – davidkomer Jan 10 '12 at 18:24
  • \$\begingroup\$ What is the scaler? The values you get will be in the range of 0..255 in your code. \$\endgroup\$ – bummzack Jan 10 '12 at 18:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.