Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
deck
Jul 13, 2006

The terrain in the original Scortched Earth was implemented using a basic "sand" engine.

There's a 1-bit "mask" bitmap that defines the terrain, and you deform it by just cutting holes in the mask. If the mask is altered, run passes of the sand algorithm until the terrain has settled.

The sand algorithm is simple. For each pixel in the mask, if there's empty space immediately below, shift the pixel down one row. Else, if there's empty space to the lower-left or lower-right, shift there instead. (If both are empty, use a random number to break the tie.) It's like a cellular automata process. With these basic rules, the sand will tend to form pyramid-shaped piles. You can extend the proces with more rules (sideways motion) to cause them to flatten more.

Watch for bias issues when doing this: you may need to cycle from bottom to top, and alternate left-to-right then right-to-left as you process all the pixels. Not doing this may cause your sand to settle with a left or right bias, or get spaced out as it falls.

Count the number of pixels that shift with each update, and when you fall below a threshhold (1 is probably the right choice given how fast computers can do this today), you're done.

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply