Vacuum spread in a tile-based space game (like in Faster Than Light game)

Posted by Reeze on Stack Overflow See other posts from Stack Overflow or by Reeze
Published on 2013-11-09T02:52:07Z Indexed on 2013/11/09 3:54 UTC
Read the original article Hit count: 211

Filed under:
|
|

I've a space game with tilemap that looks like this (simplified):

Map view - from top (like in SimCity 1)

0 - room space, 1 - some kind of wall, 8 - "lock" beetween rooms

 public int[,] _layer = new int[,]   
        {
         { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
         { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 1, 1, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 1, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
         { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    };

Each tile contains Air property (100 = air, 0 = vacuum).

I made a little helper method to take tiles near tile with vacuum (to "suck air"):

 Point[] GetNearCells(Point cell, int distance = 1, bool diag = false)
    {
        Point topCell = new Point(cell.X, cell.Y - distance);
        Point botCell = new Point(cell.X, cell.Y + distance);
        Point leftCell = new Point(cell.X - distance, cell.Y);
        Point rightCell = new Point(cell.X + distance, cell.Y);

        if (diag)
        {
            return new[] { topCell, botCell, leftCell, rightCell };
        }


        Point topLeftCell = new Point(cell.X - distance, cell.Y - distance);
        Point topRightCell = new Point(cell.X + distance, cell.Y + distance);
        Point botLeftCell = new Point(cell.X - distance, cell.Y - distance);
        Point botRightCell = new Point(cell.X - distance, cell.Y - distance);

        return new[] { topCell, botCell, leftCell, rightCell, topLeftCell, topRightCell, botLeftCell, botRightCell };

    }

What is the best practice to fill rooms with vacuum (decrease air) from some point? Should i use some kind of water flow?

Thank you for any help!

© Stack Overflow or respective owner

Related posts about c#

Related posts about game-engine