示例#1
0
        public void OreGeneration(int startx, int starty, int amount, string oreType)
        {
            // pick a point on the surface as the cave entrance
            int caveX = startx;
            int caveY = starty;

            while (worldTiles[caveX, caveY].type == null)
            {
                caveY++;
            }
            // drill down until we are deep underground
            while (worldTiles[caveX - 1, caveY].type == null ||
                   worldTiles[caveX + 1, caveY].type == null)
            {
                worldTiles[caveX, caveY] = new MineBlock(oreType, new Vector2(caveX, caveY));
                caveY++;
            }

            // starting from the entrance, walk randomly within the terrain,
            // "carving out" the cave
            // make sure we do not create new entrances; the carving must not go
            // adjacent to an "open air" cell
            for (int i = 0; i < amount; i++)
            {
                // "carve out" the current cell
                Game1.penumbra.Hulls.Remove(worldTiles[caveX, caveY].hull);
                worldTiles[caveX, caveY] = new MineBlock(oreType, new Vector2(caveX, caveY));

                // Get random direction:
                // 0: up
                // 1: right
                // 2: down
                // 3: left
                int dir = Game1.rand.Next(4);
                switch (dir)
                {
                case 0:     // up
                    if (IsValidCaveCell(caveX, caveY + 1))
                    {
                        caveY++;
                    }
                    break;

                case 1:     // right
                    if (IsValidCaveCell(caveX + 1, caveY))
                    {
                        caveX++;
                    }
                    break;

                case 2:     // down
                    if (IsValidCaveCell(caveX, caveY - 1))
                    {
                        caveY--;
                    }
                    break;

                case 3:     // left
                    if (IsValidCaveCell(caveX - 1, caveY))
                    {
                        caveX--;
                    }
                    break;
                }
            }
        }
示例#2
0
        public void initialize()
        {
            worldTiles  = new MineBlock[width, depth];
            backgrounds = new Background[width, depth];


            sun = new PointLight {
                Position = new Vector2((width * Game1.gridSize) / 2, -10000), Scale = new Vector2(1000000, 32500), ShadowType = ShadowType.Occluded, CastsShadows = false, Intensity = 0.8f
            };
            Game1.penumbra.Lights.Add(sun);

            //MAKES THE LAYERS OF TERRAIN
            for (int depth = 0; depth < this.depth; depth++)
            {
                for (int width = 0; width < this.width; width++)
                {
                    if (depth > Game1.rand.Next(10, 20))
                    {
                        worldTiles[width, depth] = new MineBlock("STONE", new Vector2(width, depth));
                    }
                    else if (depth > Game1.rand.Next(2, 7))
                    {
                        worldTiles[width, depth] = new MineBlock("DIRT", new Vector2(width, depth));
                    }
                    else
                    {
                        worldTiles[width, depth] = new MineBlock("TOP DIRT", new Vector2(width, depth));
                    }
                }
            }

            //MAKES THE BACKGROUNDS
            for (int depth = 0; depth < this.depth; depth += backgroundProportionallity)
            {
                for (int width = 0; width < this.width; width += backgroundProportionallity)
                {
                    if (depth > Game1.rand.Next(10, 20))
                    {
                        backgrounds[width, depth] = new Background(new Vector2(width, depth), "STONE", backgroundProportionallity);
                    }
                    else if (depth > 3)
                    {
                        backgrounds[width, depth] = new Background(new Vector2(width, depth), "DIRT", backgroundProportionallity);
                    }
                    else
                    {
                        backgrounds[width, depth] = new Background(new Vector2(width, depth), "BLANK", backgroundProportionallity);
                    }
                }
            }
            for (int num = 0; num < Game1.rand.Next(50, 100); num++)
            {
                int randW = Game1.rand.Next(0, width - 2);
                int randH = Game1.rand.Next(30, depth - 2);

                while (randW % 2 != 0)
                {
                    randW = Game1.rand.Next(0, width - 2);
                }
                while (randH % 2 != 0)
                {
                    randH = Game1.rand.Next(30, depth - 2);
                }


                backgroundsAnim.Add(new Background(new Vector2(randW, randH), "EYES", backgroundProportionallity));
            }
            for (int num = 0; num < Game1.rand.Next(50, 100); num++)
            {
                int randW = Game1.rand.Next(0, width - 2);
                int randH = Game1.rand.Next(30, depth - 2);

                while (randW % 2 != 0)
                {
                    randW = Game1.rand.Next(0, width - 2);
                }
                while (randH % 2 != 0)
                {
                    randH = Game1.rand.Next(30, depth - 2);
                }

                backgroundsAnim.Add(new Background(new Vector2(randW, randH), "EYES SMALL", backgroundProportionallity));
            }


            GenerateRandomTerrain(depth, 2);

            //MAKES CAVES, ORES, HALLWAYS
            for (int numOfCaves = 0; numOfCaves <= Game1.rand.Next(6, 15); numOfCaves++)
            {
                CaveGeneration(Game1.rand.Next(10, width - 10), Game1.rand.Next(40, depth - 30), Game1.rand.Next(100, 5000));
            }

            for (int numOfVeins = 0; numOfVeins <= Game1.rand.Next(50, 75); numOfVeins++)
            {
                OreGeneration(Game1.rand.Next(10, width - 10), Game1.rand.Next(10, depth - 10), Game1.rand.Next(4, 17), "GOLD");
            }

            for (int numOfHalls = 0; numOfHalls <= Game1.rand.Next(1, 2); numOfHalls++)
            {
                GenerateHallWay(Game1.rand.Next((int)(depth * 0.75), depth - 5), Game1.rand.Next(0, width - 10), Game1.rand.Next(6, 10), Game1.rand.Next(3, 5), "HALLWAY");
            }

            for (int depth = 0; depth < this.depth; depth++)
            {
                for (int width = 0; width < this.width; width++)
                {
                    worldTiles[width, depth].Update();
                }
            }


            while (objects.Count < 7)
            {
                Vector2 loc = new Vector2(Game1.rand.Next(2, width - 2), Game1.rand.Next(40, depth - 4));

                if (GetBlock(loc).type == "BLANK" && GetBlock(new Vector2(loc.X - 1, loc.Y)).type == "BLANK" && GetBlock(new Vector2(loc.X, loc.Y + 1)).type == "BLANK" && GetBlock(new Vector2(loc.X + 1, loc.Y + 1)).type == "BLANK" && GetBlock(new Vector2(loc.X, loc.Y + 2)).type != "BLANK" && GetBlock(new Vector2(loc.X + 1, loc.Y + 2)).type != "BLANK")
                {
                    objects.Add(new Objects("CHEST", loc));
                }
            }

            while (objects.Count < 3)
            {
                Vector2 loc = new Vector2(Game1.rand.Next(2, width - 2), Game1.rand.Next(40, depth - 4));

                if (GetBlock(loc).type == "BLANK" && GetBlock(new Vector2(loc.X - 1, loc.Y)).type == "BLANK" && GetBlock(new Vector2(loc.X, loc.Y + 1)).type == "BLANK" && GetBlock(new Vector2(loc.X + 1, loc.Y + 1)).type == "BLANK" && GetBlock(new Vector2(loc.X, loc.Y + 2)).type != "BLANK" && GetBlock(new Vector2(loc.X + 1, loc.Y + 2)).type != "BLANK")
                {
                    objects.Add(new Objects("CHEST TRAP", loc));
                }
            }
            //backgroundsAnim.Add(new Background(new Vector2(1, 1), "EYES", backgroundProportionallity));
            //backgroundsAnim.Add(new Background(new Vector2(3, 1), "EYES SMALL", backgroundProportionallity));

            objects.Add(new Objects("CHEST", new Vector2(0, -1)));
            objects.Add(new Objects("CHEST TRAP", new Vector2(5, -1)));

            //enemies.Add(new Enemy("RAT", new Vector2(5, -1)));

            //Console.WriteLine(backgroundsAnim);
        }