示例#1
0
        public bool CheckTerrain(Rectangle rect)
        {
            if (rect.X < game.MapWidth / 2 + Graphics.PLOTSIZE / 4 &&
                rect.X > game.MapWidth / 2 - Graphics.PLOTSIZE / 4 - Graphics.SMALLPLAYERWIDTH)
            {
                return(true);
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    for (int m = 0; m < plots[x, y].Mountains.Length; m++)
                    {
                        Mountain mnt = plots[x, y].Mountains[m];

                        if (
                            rect.X < x * Graphics.PLOTSIZE + mnt.X + Graphics.MOUNTAINWIDTH &&
                            rect.X > x * Graphics.PLOTSIZE + mnt.X - rect.Width &&
                            rect.Y < y * Graphics.PLOTSIZE + mnt.Y + Graphics.MOUNTAINHEIGHT &&
                            rect.Y > y * Graphics.PLOTSIZE + mnt.Y - rect.Height
                            )
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
示例#2
0
        private void generateMountains()
        {
            int numMountains = game.Random.Next(3) + 1;

            mountains = new Mountain[numMountains];

            for (int i = 0; i < numMountains; i++)
            {
                mountains[i]      = new Mountain();
                mountains[i].Type =
                    (MountainType)(game.Random.Next(4) + 1);

                int y = 0;

                while (true)
                {
                    y =
                        game.Random.Next(
                            Graphics.PLOTSIZE - Graphics.MOUNTAINBUFFER * 2 - Graphics.MOUNTAINHEIGHT
                            ) +
                        Graphics.MOUNTAINBUFFER;

                    bool conflict = false;

                    for (int j = 0; j < i; j++)
                    {
                        if (y > mountains[j].Y - Graphics.MOUNTAINBUFFER - Graphics.MOUNTAINHEIGHT &&
                            y < mountains[j].Y + Graphics.MOUNTAINHEIGHT + Graphics.MOUNTAINBUFFER)
                        {
                            conflict = true;
                            break;
                        }
                    }

                    if (!conflict)
                    {
                        break;
                    }
                }

                mountains[i].Y = y;
                mountains[i].X = game.Random.Next(Graphics.PLOTSIZE - Graphics.MOUNTAINWIDTH);
            }
        }