Example #1
0
        private void PokeExits(int numExits)
        {
            int buffersmoller    = height - 10;
            int distanceToCenter = (buffersmoller * buffersmoller);

            Vector2 center = new Vector2(width / 2, height / 2);

            roomsize = 5;

            foreach (MazeRoom outermostRooms in mazeRooms.Where(testby => testby.gen > maxGen * 0.75f).OrderBy(testby => 0 - (new Vector2(testby.loc.X, testby.loc.Y) - new Vector2(width / 2, height / 2)).LengthSquared()).Take(numExits))
            {
                Point check1   = outermostRooms.loc.ToPoint();
                Point pointvec = (Vector2.Normalize(check1.ToVector2() - center) * 32).ToPoint();
                Point check2   = new Point(check1.X + pointvec.X, check1.Y + pointvec.Y);



                for (int xx = -roomsize; xx <= roomsize; xx += 1)
                {
                    for (int yy = -roomsize; yy <= roomsize; yy += 1)
                    {
                        foreach (Point there in IDGWorldGen.GetLine(check1, check2))
                        {
                            Point16 there2 = new Point16(there.X + xx, there.Y + yy);
                            if (InsideMap(there2.X, there2.Y))
                            {
                                Tile tileline = Main.tile[there2.X, there2.Y];
                                if (tileline.active())
                                {
                                    tileline.active(false);
                                    tileline.type = 0;// TileID.AmberGemspark;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private void BossBox()
        {
            HashSet <Point16> BossBox = new HashSet <Point16>();

            MazeRoom EndPoint      = MazeGraphPoints[0];
            MazeRoom BossRoomPoint = new MazeRoom(new Point16(BossRoom.Center.X, BossRoom.Center.Y), 0, new Point16(0, 0), 0, true);

            EndPoint.previousRoom = BossRoomPoint;
            MazeGraphPoints.Insert(0, BossRoomPoint);

            for (int xx = BossRoom.X; xx < BossRoom.Width + BossRoom.X; xx += 1)
            {
                for (int yy = BossRoom.Y; yy < BossRoom.Height + BossRoom.Y; yy += 1)
                {
                    Vector2 vectordist = (BossRoom.Center.ToVector2() - new Vector2(xx, yy));
                    if (BossRoomInside.Contains(xx, yy) || UniRand.NextFloat(vectordist.Length(), 100) < 100)
                    {
                        IDGWorldGen.PlaceMulti(new Point(xx, yy), TileID.RubyGemspark, UniRand.Next(2, 6), -1, true);
                        BossBox.Add(new Point16(xx, yy));
                    }
                }
            }
            InnerArenaTiles = new HashSet <Point16>(BossBox);
            foreach (Point16 point in BossBox)
            {
                Tile tileline = Main.tile[point.X, point.Y];
                tileline.color((byte)Paints.Shadow);
                //if (BossRoomInside.Contains(point.X, point.Y))
                //{
                tileline.active(false);
                tileline.wall = tileline.wall = (ushort)SGAmod.Instance.WallType("NullWallBossArena");
                //}
            }
            if (roomsize < 5)
            {
                roomsize = 5;
            }

            foreach (Point point in IDGWorldGen.GetLine(startingPoint.ToPoint(), BossRoom.Center))
            {
                for (int xx = -(roomsize + 2); xx <= roomsize + 2; xx += 1)
                {
                    for (int yy = -roomsize; yy < roomsize + 1; yy += 1)
                    {
                        if (InsideMap(point.X + xx, point.Y + yy))
                        {
                            Tile tileline = Main.tile[point.X + xx, point.Y + yy];
                            tileline.active(false);

                            if (BossRoom.Contains(point.X, point.Y))
                            {
                                if (tileline.wall != (ushort)SGAmod.Instance.WallType("NullWall") && tileline.wall != (ushort)SGAmod.Instance.WallType("NullWallBossArena"))
                                {
                                    tileline.wall = (ushort)SGAmod.Instance.WallType("NullWall");
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public void EvilSegmentRooms(List <MazeRoom> ListOfRooms, int type)
        {
            //Do Sub-Boss Room Gen

            float   bossArenaSize = 80;
            Vector2 CorruptionRoomAngleAverage = Vector2.Zero;

            foreach (MazeRoom room in ListOfRooms)
            {
                CorruptionRoomAngleAverage += ((room.loc - Middle).ToVector2());
            }
            CorruptionRoomAngleAverage /= ListOfRooms.Count;

            CorruptionRoomAngleAverage = (Vector2.Normalize(CorruptionRoomAngleAverage) * 500f) + Middle.ToVector2();

            List <MazeRoom> MiniBossRoomsBossArena = new List <MazeRoom>();

            while (MiniBossRoomsBossArena.Count < 10)
            {
                MiniBossRoomsBossArena = ListOfRooms.FindAll(testby => (testby.loc.ToVector2() - CorruptionRoomAngleAverage).Length() < bossArenaSize).ToList();
                bossArenaSize         += 4;
            }

            Vector2 AveragePoint = Vector2.Zero;

            List <Point> ArenaPoints = new List <Point>();
            int          minx = width, miny = height, maxx = 0, maxy = 0;

            //Do Room Carve out
            foreach (MazeRoom room in MiniBossRoomsBossArena)
            {
                AveragePoint += room.loc.ToVector2();
                //IDGWorldGen.PlaceMulti(room.loc.ToPoint(), TileID.Cloud, 8);
                //IDGWorldGen.PlaceMulti(room.loc.ToPoint(), -1, 6);
                minx = Math.Min(minx, room.loc.X); miny = Math.Min(miny, room.loc.Y);
                maxx = Math.Max(maxx, room.loc.X); maxy = Math.Max(maxy, room.loc.Y);
                ArenaPoints.Add(room.loc.ToPoint());
                for (int i = 0; i < 2; i += 1)
                {
                    foreach (MazeRoom room2 in MiniBossRoomsBossArena)
                    {
                        foreach (Point there in IDGWorldGen.GetLine(room.loc.ToPoint(), room2.loc.ToPoint()))
                        {
                            int sizer2 = 8;
                            int sizer  = sizer2 - i * 2;

                            for (int x = -sizer; x <= sizer; x += 1)
                            {
                                for (int y = -sizer; y <= sizer; y += 1)
                                {
                                    Tile tile = Main.tile[there.X + x, there.Y + y];
                                    if (i < 1)
                                    {
                                        if (tile.active())
                                        {
                                            tile.type = type == 0 ? TileID.AmethystGemspark : TileID.AmberGemspark;
                                        }
                                    }
                                    else
                                    {
                                        tile.active(false);
                                        if (tile.wall == 0)
                                        {
                                            tile.wall = type == 0 ? WallID.AmethystGemsparkOff : WallID.AmberGemsparkOff;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            AveragePoint /= MiniBossRoomsBossArena.Count;
            List <MazeRoom> ListofOrderedRooms = ListOfRooms.OrderBy(testby => UniRand.Next(ListOfRooms.Count)).ToList();

            ListofOrderedRooms.Insert(0, new MazeRoom(AveragePoint.ToPoint16(), 0, new Point16(0, 0), 0, true));

            //place orbs/hearts
            int index = 0;
            int heart = type == 0 ? 0 : 1;

            foreach (MazeRoom lootroom in ListofOrderedRooms)
            {
                if (index < 3)
                {
                    IDGWorldGen.PlaceMulti(lootroom.loc.ToPoint(), type == 0 ? TileID.AmethystGemspark : TileID.AmberGemspark, 5, type == 0 ? WallID.AmethystGemspark : WallID.AmberGemspark);
                    IDGWorldGen.PlaceMulti(lootroom.loc.ToPoint(), -1, 3, type == 0 ? WallID.AmethystGemspark : WallID.AmberGemspark);
                    for (int num36 = 0; num36 < 2; num36++)
                    {
                        for (int num37 = 0; num37 < 2; num37++)
                        {
                            int num38 = lootroom.loc.X + num36;
                            int num39 = lootroom.loc.Y + num37;
                            Main.tile[num38, num39].active(active: true);
                            Main.tile[num38, num39].slope(0);
                            Main.tile[num38, num39].halfBrick(halfBrick: false);
                            Main.tile[num38, num39].type   = 31;
                            Main.tile[num38, num39].frameX = (short)(num36 * 18 + 36 * heart);
                            Main.tile[num38, num39].frameY = (short)(num37 * 18 + 36 * 0);
                        }
                    }
                }

                index += 1;
            }
        }
Example #4
0
        private void MazeGenerator(Point16 starting, int roomIndex, int maxsize, GenerationProgress prog)
        {
            Stack <MazeRoom> mazeStack = new Stack <MazeRoom>();

            maxGen = 0;
            int index = 0;

            currentPosition = starting;
            MazeRoom mazz = new MazeRoom(currentPosition, gen, Flow(currentPosition, flowSize), roomIndex);

            mazeStack.Push(mazz);
            if (roomIndex == 0)
            {
                startingPoint = mazz.loc + mazz.Offset;
                IDGWorldGen.PlaceMulti(startingPoint.ToPoint(), TileID.Adamantite, roomsize * 3);
            }

ResetMove:
            //And now, we gen a maze with depth first!
            //Ah Adamantite, my good friend! Please help me keep track of where we've been!

            while (mazeStack.Count > 0 && index < maxsize)
            {
                MazeRoom whereWeAre = mazeStack.Peek();
                //gen = whereWeAre.gen;
                maxGen = Math.Max(maxGen, gen);

                Point16 newpoint = currentPosition;

                prog.Value   = MathHelper.Clamp(mazeStack.Count / 100f, 0f, 1f);
                prog.Message = whereWeAre.loc.X + ":" + whereWeAre.loc.Y + " Gen " + gen;


                int offset = UniRand.Next(4);

                for (int i = 0; i < 4; i += 1)
                {
                    //Check Card Directions

                    //Point16 cardOffset = (DarkSector.Cardinals[(offset + i) % DarkSector.Cardinals.Length]) * new Point16(sizeCheck, sizeCheck);
                    Point16 cardOffset = (Vector2.UnitX * sizeCheck).RotatedBy(UniRand.NextFloat(MathHelper.TwoPi)).ToPoint16();
                    //(pointhere * sizeCheck).ToPoint16();//(DarkSector.Cardinals[(offset + i) % DarkSector.Cardinals.Length])*sizeCheck;
                    Point16 checkHere = currentPosition + (cardOffset);

                    if (checkHere.X < sizeCheck || checkHere.X > width - sizeCheck || checkHere.Y < sizeCheck || checkHere.Y > height - sizeCheck)
                    {
                        continue;
                    }

                    if (Avoid(checkHere))
                    {
                        continue;
                    }

                    //Found one, moving

                    // Main.tile[checkHere.X, checkHere.Y].type = TileID.Adamantite;
                    //Main.tile[checkHere.X, checkHere.Y].active(true);

                    //Place down some stuff to mark this area so we don't move back here
                    IDGWorldGen.PlaceMulti(checkHere.ToPoint(), TileID.Adamantite, roomsize * 3);

                    //Draw line and connect the dots
                    Point check1 = (currentPosition + Flow(currentPosition, flowSize)).ToPoint();
                    Point check2 = (checkHere + Flow(checkHere, flowSize)).ToPoint();

                    foreach (Point there in IDGWorldGen.GetLine(check1, check2))
                    {
                        Point16 there2 = new Point16(there.X, there.Y);
                        if (InsideMap(there2.X, there2.Y))
                        {
                            Tile tileline = Main.tile[there2.X, there2.Y];
                            //tileline.color((byte)FakeOverworld.Paints.Negative);
                            mazePainter.Add(new MazeRoom(there2, gen, new Point16(0, 0), roomIndex));
                        }
                    }

                    index += 1;
                    gen   += 1;
                    MazeRoom mazepoint = new MazeRoom(checkHere, gen, Flow(currentPosition, flowSize), roomIndex);
                    mazepoint.ConnectedRoom = whereWeAre;

                    if (LastRoom == null || gen > LastRoom.gen)
                    {
                        LastRoom = mazepoint;
                    }

                    mazeStack.Push(mazepoint);
                    mazeRooms.Add(whereWeAre);

                    currentPosition = checkHere;

                    goto ResetMove;
                }

                //Dead end, time to step back

                MazeRoom stepBack = mazeStack.Pop();
                MazeRoom previous = stepBack;
                if (mazeStack.Count > 1)
                {
                    previous         = mazeStack.Peek();
                    previous.deadEnd = false;
                }

                if (!mazeRooms.Any(tester => tester.loc == currentPosition))
                {
                    mazeRooms.Add(new MazeRoom(currentPosition, gen, Flow(currentPosition, flowSize), roomIndex, true));
                }

                gen            -= 1;
                currentPosition = previous.loc;
            }

            mazePainter.OrderBy(orderby => orderby.gen);
            mazeRooms.OrderBy(orderby => orderby.gen);

            /*MazeRoom spawnRoom = mazeRooms[mazeRooms.Count - 1];
             * Main.spawnTileX = spawnRoom.loc.X + spawnRoom.Offset.X;
             * Main.spawnTileY = spawnRoom.loc.Y + spawnRoom.Offset.Y;*/
        }