# How do display a "mucus spreading" effect in a 2D environment?

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).

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?

• 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. Commented Nov 15, 2012 at 10:07
• The keyword you're looking for is "cellular automata". Commented Nov 15, 2012 at 10:38
• Commented Nov 15, 2012 at 17:40
• @Byte56 great answer, pretty clear. Thanks for sharing. Commented Nov 15, 2012 at 19:18

## 2 Answers

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.

• @nathan Also look up Cellular Automata. Commented Dec 19, 2012 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.

• 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? Commented Nov 15, 2012 at 10:18
• @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. Commented Nov 15, 2012 at 10:24
• yeah my question was more about how to choose what tile to use to get a coherent effect. Commented Nov 15, 2012 at 10:38
• @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. Commented Nov 15, 2012 at 11:44
• @nathan Probably should have asked how to display it, rather than how to produce it. Commented Nov 15, 2012 at 15:06