Example #1
0
        private int Get4DirMask(Array2D <int> input, int x, int y, TilerPattern p)
        {
            //   3
            // 0   1
            //   2

            int m = 0;

            if (p.Connects(GetCell(input, x - 1, y)))
            {
                m |= 1;
            }
            if (p.Connects(GetCell(input, x + 1, y)))
            {
                m |= 2;
            }
            if (p.Connects(GetCell(input, x, y - 1)))
            {
                m |= 4;
            }
            if (p.Connects(GetCell(input, x, y + 1)))
            {
                m |= 8;
            }

            //if (x != 0 && p.Connects(mapInput[input[x - 1, y]])) m |= 1;
            //if (y != 0 && p.Connects(mapInput[input[x, y - 1]])) m |= 4;
            //if (x != input.sizeX - 1 && p.Connects(input[x + 1, y])) m |= 2;
            //if (y != input.sizeY - 1 && p.Connects(input[x, y - 1])) m |= 8;

            return(m);
        }
Example #2
0
        public int ProcessTile(Array2D <int> input, int x, int y)
        {
            int t = input[x, y];

            if (t < 0)
            {
                return(defaultOutput);
            }

            int          tt = mapInput != null ? mapInput[t] : t;
            TilerPattern p  = patterns[tt];

            if (p == null)
            {
                return(defaultOutput);
            }

            switch (p.type)
            {
            case TilerPatternType.PATH:
                return(ProcessTilePath(input, x, y, tt));

            case TilerPatternType.BORDER:
                return(ProcessTileBorder(input, x, y, tt));

            default:                     // SINGLE
                return(p.defaultOutput[Random.Range(0, p.defaultOutput.Length)]);
            }
        }
Example #3
0
        private int ProcessTileBorder(Array2D <int> input, int x, int y, int tt)
        {
            TilerPattern p = patterns[tt];
            int          m = Get8DirMask(input, x, y, p);
            int          l = _borderLookup[m];

            return(p.tiles[l]);
        }
Example #4
0
 public void AddPattern(TilerPattern pattern)
 {
     while (patterns.Count - 1 < pattern.inputID)
     {
         patterns.Add(null);
     }
     patterns[pattern.inputID] = pattern;
 }
Example #5
0
        private int Get8DirMask(Array2D <int> input, int x, int y, TilerPattern p)
        {
            // 0 1 2
            // 3   4
            // 5 6 7

            int m = 0;

            if (p.Connects(GetCell(input, x - 1, y - 1)))
            {
                m |= 1;
            }
            if (p.Connects(GetCell(input, x, y - 1)))
            {
                m |= 2;
            }
            if (p.Connects(GetCell(input, x + 1, y - 1)))
            {
                m |= 4;
            }
            if (p.Connects(GetCell(input, x - 1, y)))
            {
                m |= 8;
            }
            if (p.Connects(GetCell(input, x + 1, y)))
            {
                m |= 16;
            }
            if (p.Connects(GetCell(input, x - 1, y + 1)))
            {
                m |= 32;
            }
            if (p.Connects(GetCell(input, x, y + 1)))
            {
                m |= 64;
            }
            if (p.Connects(GetCell(input, x + 1, y + 1)))
            {
                m |= 128;
            }

            //if (x != 0)
            //{
            //	if (y != 0 && p.Connects(mapInput[input[x - 1, y - 1]]))
            //		m |= (1 << 0);
            //	if (y != input.sizeY - 1 && p.Connects(mapInput[input[x - 1, y + 1]]))
            //		m |= (1 << 5);
            //	if (p.Connects(mapInput[input[x - 1, y]]))
            //		m |= (1 << 3);
            //}

            //if (x != input.sizeX - 1)
            //{
            //	if (y != 0 && p.Connects(mapInput[input[x + 1, y - 1]]))
            //		m |= (1 << 2);
            //	if (y != input.sizeY - 1 && p.Connects(mapInput[input[x + 1, y + 1]]))
            //		m |= (1 << 7);
            //	if (p.Connects(mapInput[input[x + 1, y]]))
            //		m |= (1 << 4);
            //}

            //if (y != 0 && p.Connects(mapInput[input[x, y - 1]]))
            //	m |= (1 << 1);
            //if (y != input.sizeY - 1 && p.Connects(mapInput[input[x, y + 1]]))
            //	m |= (1 << 6);

            return(m);
        }
Example #6
0
        private int ProcessTilePath(Array2D <int> input, int x, int y, int tt)
        {
            TilerPattern p = patterns[tt];

            return(p.tiles[Get4DirMask(input, x, y, p)]);
        }