Пример #1
0
        public static void GenerateRandomMap()
        {
            for (int x = 0; x < MapWidth; x++)
                for (int y = 0; y < MapHeight; y++)
                {
                    //mapSquares[x, y] = floorTile;

                    //if ((x == 0) || (y == 0) ||
                    //    (x == MapWidth - 1) || (y == MapHeight - 1))
                    //{
                    //    mapSquares[x, y] = wallTile;
                    //    continue;
                    //}

                    //if ((x == 1) || (y == 1) ||
                    //    (x == MapWidth - 2) || (y == MapHeight - 2))
                    //{
                    //    continue;
                    //}

                    int roll = Random.Next(0, 100);
                    int unknownTileIndex = Random.Next(UnknownTileStart, UnknownTileEnd + 1);
                    if (roll < 10)
                    {
                        // Star
                        // Is there a star too close?
                        bool empty = true;
                        for (int i = x - StarTileBuffer; i < x + StarTileBuffer; i++)
                            for (int k = y - StarTileBuffer; k < y + StarTileBuffer; k++)
                            {
                                if (i < 0 || k < 0 ||
                                    i >= MapWidth || k >= MapHeight ||
                                    mapSquares[i, k] == null)
                                {
                                    // Do nothing
                                }
                                else if (mapSquares[i, k].IsStar)
                                {
                                    empty = false;
                                    break;
                                }
                            }

                        if (empty)
                        {
                            Vector2 position = new Vector2(SquareWorldRectangle(x, y).X,
                                    SquareWorldRectangle(x, y).Y);
                            roll = Random.Next(1, 5);
                            switch( roll )
                            {
                                case 1:
                                    mapSquares[x,y] = new HelpfulScanners(position);
                                    break;
                                case 2:
                                    mapSquares[x, y] = new KilledWorldTile(position);
                                    break;
                                case 3:
                                    mapSquares[x, y] = new ScaredWorldTile(position);
                                    break;
                                case 4:
                                    mapSquares[x, y] = new EmptyStar(position);
                                    break;
                                default:
                                    mapSquares[x, y] = new StarTile(position);
                                    break;
                            }
                        }
                        else
                        {
                            // Empty Space
                            mapSquares[x, y] = new SpaceTile(new Vector2(SquareWorldRectangle(x, y).X,
                            SquareWorldRectangle(x, y).Y));
                        }
                    }
                    else
                    {
                        // Empty Space
                        mapSquares[x, y] = new SpaceTile(new Vector2(SquareWorldRectangle(x, y).X,
                            SquareWorldRectangle(x, y).Y));
                    }
                }

            // Find star near starting point
            // and replace with Earth
            Vector2 playerStart = GetSquareAtPixel(Player.BaseSprite.WorldLocation);
            bool stop = false;
            for (int x = (int)playerStart.X - StarTileBuffer; x < playerStart.X + StarTileBuffer; x++)
            {
                if (stop)
                {
                    break;
                }
                for (int y = (int)playerStart.Y - StarTileBuffer; y < playerStart.Y + StarTileBuffer; y++)
                {
                    if (mapSquares[x, y].IsStar)
                    {
                        mapSquares[x, y] = new EarthTile(new Vector2( SquareWorldRectangle(x, y).X, SquareWorldRectangle(x,y ).Y));
                        stop = true;
                        break;
                    }
                }
            }
        }
Пример #2
0
        static public void GenerateRandomMap()
        {
            for (int x = 0; x < MapWidth; x++)
            {
                for (int y = 0; y < MapHeight; y++)
                {
                    //mapSquares[x, y] = floorTile;

                    //if ((x == 0) || (y == 0) ||
                    //    (x == MapWidth - 1) || (y == MapHeight - 1))
                    //{
                    //    mapSquares[x, y] = wallTile;
                    //    continue;
                    //}

                    //if ((x == 1) || (y == 1) ||
                    //    (x == MapWidth - 2) || (y == MapHeight - 2))
                    //{
                    //    continue;
                    //}

                    int roll             = Random.Next(0, 100);
                    int unknownTileIndex = Random.Next(UnknownTileStart, UnknownTileEnd + 1);
                    if (roll < 10)
                    {
                        // Star
                        // Is there a star too close?
                        bool empty = true;
                        for (int i = x - StarTileBuffer; i < x + StarTileBuffer; i++)
                        {
                            for (int k = y - StarTileBuffer; k < y + StarTileBuffer; k++)
                            {
                                if (i < 0 || k < 0 ||
                                    i >= MapWidth || k >= MapHeight ||
                                    mapSquares[i, k] == null)
                                {
                                    // Do nothing
                                }
                                else if (mapSquares[i, k].IsStar)
                                {
                                    empty = false;
                                    break;
                                }
                            }
                        }

                        if (empty)
                        {
                            Vector2 position = new Vector2(SquareWorldRectangle(x, y).X,
                                                           SquareWorldRectangle(x, y).Y);
                            roll = Random.Next(1, 5);
                            switch (roll)
                            {
                            case 1:
                                mapSquares[x, y] = new HelpfulScanners(position);
                                break;

                            case 2:
                                mapSquares[x, y] = new KilledWorldTile(position);
                                break;

                            case 3:
                                mapSquares[x, y] = new ScaredWorldTile(position);
                                break;

                            case 4:
                                mapSquares[x, y] = new EmptyStar(position);
                                break;

                            default:
                                mapSquares[x, y] = new StarTile(position);
                                break;
                            }
                        }
                        else
                        {
                            // Empty Space
                            mapSquares[x, y] = new SpaceTile(new Vector2(SquareWorldRectangle(x, y).X,
                                                                         SquareWorldRectangle(x, y).Y));
                        }
                    }
                    else
                    {
                        // Empty Space
                        mapSquares[x, y] = new SpaceTile(new Vector2(SquareWorldRectangle(x, y).X,
                                                                     SquareWorldRectangle(x, y).Y));
                    }
                }
            }

            // Find star near starting point
            // and replace with Earth
            Vector2 playerStart = GetSquareAtPixel(Player.BaseSprite.WorldLocation);
            bool    stop        = false;

            for (int x = (int)playerStart.X - StarTileBuffer; x < playerStart.X + StarTileBuffer; x++)
            {
                if (stop)
                {
                    break;
                }
                for (int y = (int)playerStart.Y - StarTileBuffer; y < playerStart.Y + StarTileBuffer; y++)
                {
                    if (mapSquares[x, y].IsStar)
                    {
                        mapSquares[x, y] = new EarthTile(new Vector2(SquareWorldRectangle(x, y).X, SquareWorldRectangle(x, y).Y));
                        stop             = true;
                        break;
                    }
                }
            }
        }