Here is an example of such a mucus spreading. The substance is spread around the source (in this example, the source would be the main alien building).

enter image description here

The game is starcraft, the purple substance is called creep.

How this kind of substance spreading would be achieved in a top down 2D environment? Recalculating the substance progression and regenerate the effect on the fly each frame or rather use a large collection of tiles or something else?

  • \$\begingroup\$ It's hard to say what you're after, exactly. To hazard a guess, I'd do a pass through all tiles, and if tile is empty but has N tiles bordering with infection, then infect current tile. \$\endgroup\$ – Jari Komppa Nov 15 '12 at 10:07
  • 3
    \$\begingroup\$ The keyword you're looking for is "cellular automata". \$\endgroup\$ – Marton Nov 15 '12 at 10:38
  • 1
    \$\begingroup\$ Related: choose-tile-based-on-adjacent-tiles \$\endgroup\$ – MichaelHouse Nov 15 '12 at 17:40
  • \$\begingroup\$ @Byte56 great answer, pretty clear. Thanks for sharing. \$\endgroup\$ – nathan Nov 15 '12 at 19:18

According to your comment in the other answers, your problem isn't the creep growing algorithm, but rather the algorithm which chooses which creep tile to use.

Which tile to use depends on whether:

  1. the upper tile is infected or not
  2. the right tile is infected or not
  3. the lower tile is infected or not
  4. the left tile is infected or not

That means you will need a total of 16 tiles. You can easily address them with a bitfield. Here is some pseudocode which will choose a different tile for every possible creep constellation:

index = 0;
if left tile is creeped then index += 1
if lower tile is creeped then index += 2
if right tile is creeped then index += 4
if upper tile is creeped then index += 8    
creep_tile = creep_tiles[index]

Note that whenever you change the infection status of a tile, all infected adjacent tiles need to be re-evaluated, because their neighborhood has now changed.

How to design the 16 tile graphics so that they fit together nicely is a (new) question for a graphic designer.

| improve this answer | |
  • 1
    \$\begingroup\$ @nathan Also look up Cellular Automata. \$\endgroup\$ – Engineer Dec 19 '12 at 6:16

A while ago I read a strategy article that explained in detail how creep spreads in Starcraft 2, I'm struggling to find it now but I remember that its fairly simple and works a bit like this

  • The Starcraft 2 map is split into tiles
  • For each source of creep, every "tick" choose a random tile which is elegible for creep to spread to, and spread creep onto that tile
  • Creep may spread to any tile which is
    • Adjacent either to another tile with creep on it, or adjacent to the source of the creep
    • Within a given range of the source of creep
    • Not a cliff

The easiest way to track which tiles creep has spread to is probably just a flag for each tile - dont' try to re-calculate it each turn.

The time between "ticks" can be used to control the spread rate of the creep, alternatively you could allow creep to spread to multiple tiles each "tick", or even randomise the time between ticks.

The above algorithm has the effect that creep spreads faster if it is blocked in by cliffs on either side, however you could instead choose a random tile within range of the source of creep and then only spread creep to that tile if it is not a cliff.

| improve this answer | |
  • \$\begingroup\$ Nice but what about creeping a tile, the algorithm is simple right, i though to something similar. But how to get this natural, imperfect effect using tiles? \$\endgroup\$ – nathan Nov 15 '12 at 10:18
  • \$\begingroup\$ @nathan How do you mean? Because the creeping tile is chosen randomly the spread is imperfect (as opposed to spreading out in a perfect circle). The rest is done in the graphical engine by choosing what textures should be shown for each tile. \$\endgroup\$ – Justin Nov 15 '12 at 10:24
  • \$\begingroup\$ yeah my question was more about how to choose what tile to use to get a coherent effect. \$\endgroup\$ – nathan Nov 15 '12 at 10:38
  • 1
    \$\begingroup\$ @nathan They most likely have a lot of prerendered sprites that when put next to each other in the right combination, create the desired visual effect. \$\endgroup\$ – Panda Pajama Nov 15 '12 at 11:44
  • 1
    \$\begingroup\$ @nathan Probably should have asked how to display it, rather than how to produce it. \$\endgroup\$ – MichaelHouse Nov 15 '12 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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