Esempio n. 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);
        }
Esempio n. 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)]);
            }
        }
Esempio n. 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]);
        }
Esempio n. 4
0
 public void AddPattern(TilerPattern pattern)
 {
     while (patterns.Count - 1 < pattern.inputID)
     {
         patterns.Add(null);
     }
     patterns[pattern.inputID] = pattern;
 }
Esempio n. 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);
        }
Esempio n. 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)]);
        }