Exemple #1
0
        public static Point normalizeCell(Point pt, Level lvl)
        {
            int betterX = pt.X, betterY = pt.Y;

            if (betterY < 0 || betterX < 0 || lvl.map.GetUpperBound(0) < betterY || lvl.map.GetUpperBound(1) < betterX)
            {
                if (betterX < 0) betterX = 0;
                if (betterY < 0) betterY = 0;
                if (betterX > lvl.map.GetUpperBound(1)) betterX = lvl.map.GetUpperBound(1);
                if (betterY > lvl.map.GetUpperBound(0)) betterY = lvl.map.GetUpperBound(0);
                return new Point(betterX, betterY);
            }
            return pt;
        }
        public static int[,] cleanUp(int[,] geo, Level lvl)
        {
            int[,] geolocal = (int[,])geo.Clone();
                for (int i = 0; i < geolocal.GetLength(0); i++)
                {
                    for (int j = 0; j < geolocal.GetLength(1); j++)
                    {
                        if ((i == 0 || i == geolocal.GetUpperBound(0) ||
                            j == 0 || j == geolocal.GetUpperBound(1)) && geolocal[i, j] == gr)
                        {
                            geolocal[i, j] = cw;
                        }
                    }
                }

            //DOOR CODE
            for (int i = 0; i < geolocal.GetLength(0); i++)
            {
                for (int j = 0; j < geolocal.GetLength(1); j++)
                {
                    if (geolocal[i, j] == gr)
                    {
                        bool left = false, right = false, top = false, bottom = false;
                        if (i > 0)
                            top = (geolocal[i - 1, j] == cw);
                        if (j > 0)
                            left = (geolocal[i, j - 1] == cw);
                        if (i < geolocal.GetLength(0) - 1)
                            bottom = (geolocal[i + 1, j] == cw);
                        if (j < geolocal.GetLength(1) - 1)
                            right = (geolocal[i, j + 1] == cw);

                        if (left && right && !top && !bottom)
                        {
                            geolocal[i, j] = 1187;
                            Demo.Entity fx = new Demo.Entity(1191, j, i);
                            lvl.fixtures.Add(fx.pos, fx);
                        }
                        else if (!left && !right && top && bottom)
                        {
                            geolocal[i, j] = 1187;
                            Demo.Entity fx = new Demo.Entity(1190, j, i);
                            lvl.fixtures.Add(fx.pos, fx);
                        }

                    }
                }
            }

            for (int i = 0; i < geolocal.GetLength(0); i++)
            {
                for (int j = 0; j < geolocal.GetLength(1); j++)
                {
                    if (geolocal[i, j] == cw)
                    {
                        bool left = false, right = false, top = false, bottom = false;
                        if (i > 0)
                            top = (geolocal[i - 1, j] != da) && (geolocal[i - 1, j] != gr);
                        if (j > 0)
                            left = (geolocal[i, j - 1] != da) && (geolocal[i, j - 1] != gr);
                        if (i < geolocal.GetLength(0) - 1)
                            bottom = (geolocal[i + 1, j] != da) && (geolocal[i + 1, j] != gr);
                        if (j < geolocal.GetLength(1) - 1)
                            right = (geolocal[i, j + 1] != da) && (geolocal[i, j + 1] != gr);

                        if (left)
                        {
                            if (right)
                            {
                                if (top)
                                {
                                    if (!bottom)
                                    {
                                        geolocal[i, j] = pu;
                                    }
                                }
                                else if (bottom)
                                {
                                    geolocal[i, j] = pd;
                                }
                                else
                                {
                                    geolocal[i, j] = sh;
                                }
                            }
                            else if (top)
                            {
                                if (bottom)
                                {
                                    geolocal[i, j] = pl;
                                }
                                else
                                {
                                    geolocal[i, j] = br;
                                }
                            }
                            else if (bottom)
                            {
                                geolocal[i, j] = tr;
                            }
                            else
                            {
                                geolocal[i, j] = sh;
                            }

                        }
                        else if (right)
                        {
                            if (top)
                            {
                                if (bottom)
                                {
                                    geolocal[i, j] = pr;
                                }
                                else
                                {
                                    geolocal[i, j] = bl;
                                }
                            }
                            else if (bottom)
                            {
                                geolocal[i, j] = tl;
                            }
                            else
                            {
                                geolocal[i, j] = sh;
                            }
                        }
                        else if (top || bottom)
                        {
                            geolocal[i, j] = sv;
                        }

                    }
                }
            }

            return geolocal;
        }