Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Jari Komppa Nov 15 '12 at 10:07
3  
The keyword you're looking for is "cellular automata". –  Marton Nov 15 '12 at 10:38
    
@Marton thanks for the precision. –  nathan Nov 15 '12 at 10:39
1  
Related: choose-tile-based-on-adjacent-tiles –  Byte56 Nov 15 '12 at 17:40
    
@Byte56 great answer, pretty clear. Thanks for sharing. –  nathan Nov 15 '12 at 19:18

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
You got my question. Thanks. –  nathan Nov 15 '12 at 13:06
1  
@nathan Also look up Cellular Automata. –  Nick Wiggill 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.

share|improve this answer
    
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? –  nathan Nov 15 '12 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. –  Justin Nov 15 '12 at 10:24
    
yeah my question was more about how to choose what tile to use to get a coherent effect. –  nathan Nov 15 '12 at 10:38
1  
@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. –  Panda Pajama Nov 15 '12 at 11:44
1  
@nathan Probably should have asked how to display it, rather than how to produce it. –  Byte56 Nov 15 '12 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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