Example #1
0
 public static Generator CutCorners(AsciiTexture texture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
 {
     List <Vector2[]> walls = new List <Vector2[]>
     {
         new Vector2[] { new Vector2(10f, 50f), new Vector2(50f, 10f) },
         new Vector2[] { new Vector2(-50f, 10f), new Vector2(-10f, 50f) },
         new Vector2[] { new Vector2(-10f, -50f), new Vector2(-50f, -10f) },
         new Vector2[] { new Vector2(50f, -10f), new Vector2(10f, -50f) }
     };
     SceneGenUtils.AddWalls(scene, zone, walls, 4f, ObstacleLayer.Wall, texture, roomCenter);
 };
Example #2
0
 public static Generator PitPillar(AsciiTexture texture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
 {
     Vector2[] pillar = new Vector2[]
     {
         new Vector2(-5f, -5f),
         new Vector2(5f, -5f),
         new Vector2(5f, 5f),
         new Vector2(-5f, 5f),
         new Vector2(-5f, -5f)
     };
     SceneGenUtils.AddWalls(scene, zone, new List <Vector2[]> {
         pillar
     }, -20f, 4f, ObstacleLayer.Wall, texture, roomCenter);
 };
Example #3
0
 public static Generator PillarBig(AsciiTexture texture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
 {
     Vector2[] points = new Vector2[]
     {
         new Vector2(-4f, -10f),
         new Vector2(4f, -10f),
         new Vector2(10f, -4f),
         new Vector2(10f, 4f),
         new Vector2(4f, 10f),
         new Vector2(-4f, 10f),
         new Vector2(-10f, 4f),
         new Vector2(-10f, -4f),
         new Vector2(-4f, -10f)
     };
     SceneGenUtils.AddWalls(scene, zone, new List <Vector2[]> {
         points
     }, 4f, ObstacleLayer.Wall, texture, roomCenter);
 };
Example #4
0
        public static Generator Arena(AsciiTexture texture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
        {
            Vector2[] points = new Vector2[]
            {
                new Vector2(27.5f, -15f),
                new Vector2(32.5f, -15f),
                new Vector2(32.5f, 15f),
                new Vector2(27.5f, 15f),
                new Vector2(27.5f, -15f)
            };

            for (int i = 0; i < 4; i++)
            {
                SceneGenUtils.AddWalls(scene, zone, new List <Vector2[]> {
                    points
                }, 4f, ObstacleLayer.Wall, texture, roomCenter);
                for (int j = 0; j < points.Length; j++)
                {
                    points[j] = new Vector2(-points[j].Y, points[j].X);
                }
            }
        };
Example #5
0
        public static Generator Pit(AsciiTexture floorTexture, AsciiTexture wallTexture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
        {
            zone.AddMesh(SceneGenUtils.MakeFloor(roomCenter.X - 50f, roomCenter.X - 30f, roomCenter.Z - 50f, roomCenter.Z + 50f, -4f, floorTexture, true));
            zone.AddMesh(SceneGenUtils.MakeFloor(roomCenter.X + 30f, roomCenter.X + 50f, roomCenter.Z - 50f, roomCenter.Z + 50f, -4f, floorTexture, true));
            zone.AddMesh(SceneGenUtils.MakeFloor(roomCenter.X - 30f, roomCenter.X + 30f, roomCenter.Z - 50f, roomCenter.Z - 30f, -4f, floorTexture, true));
            zone.AddMesh(SceneGenUtils.MakeFloor(roomCenter.X - 30f, roomCenter.X + 30f, roomCenter.Z + 30f, roomCenter.Z + 50f, -4f, floorTexture, true));
            zone.AddMesh(SceneGenUtils.MakeFloor(roomCenter.X - 50f, roomCenter.X + 50f, roomCenter.Z - 50f, roomCenter.Z + 50f, 4f, floorTexture, false));

            Vector2[] walls = new Vector2[]
            {
                new Vector2(-30f, -30f),
                new Vector2(-30f, 30f),
                new Vector2(30f, 30f),
                new Vector2(30f, -30f),
                new Vector2(-30f, -30f)
            };
            zone.AddMesh(new MeshObject(SceneGenUtils.MakeWall(walls, -28f, -4f, wallTexture), roomCenter, 0f));
            Vector2 offset = new Vector2(roomCenter.X, roomCenter.Z);
            for (int i = 0; i < 4; i++)
            {
                scene.AddObstacle(walls[i + 1] + offset, walls[i] + offset, ObstacleLayer.Gap);
            }
        };
        private void GenerateRooms(Scene scene, Zone[,] zones)
        {
            // Generating geometry and colliders
            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    if (accessible[x, y])
                    {
                        float left   = x * tileSize - size * tileSize / 2;
                        float right  = left + tileSize;
                        float bottom = y * tileSize - size * tileSize / 2;
                        float top    = bottom + tileSize;
                        zones[x, y] = new Zone(new RectangleF(left, bottom, tileSize, tileSize));
                        scene.AddZone(zones[x, y]);

                        float[] roomCorridors = Enumerable.Range(0, 4).Select(t => corridorWidths[x, y, t]).ToArray();

                        // Walls
                        List <Vector2[]> walls         = SceneGenUtils.MakeRoomWalls(tileSize, tileSize, roomCorridors, 2f);
                        Vector2          roomCenter    = new Vector2((left + right) / 2, (top + bottom) / 2);
                        List <Triangle>  wallTriangles = new List <Triangle>();
                        foreach (Vector2[] wall in walls)
                        {
                            wallTriangles.AddRange(SceneGenUtils.MakeWall(wall, -4f, 4f, WallTexture));
                            scene.AddObstacle(wall[0] + roomCenter, wall[1] + roomCenter, ObstacleLayer.Wall);
                        }
                        MeshObject wallObject = new MeshObject(wallTriangles, new Vector3(roomCenter.X, 0f, roomCenter.Y), 0f);
                        zones[x, y].AddMesh(wallObject);


                        bool flagIsSpecial        = (x == exitRoom.X && y == exitRoom.Y) || (x == size / 2 && y == size / 2);
                        PopulateSchemeFlags flags = new PopulateSchemeFlags
                        {
                            IsSpecial      = flagIsSpecial,
                            ClearCenter    = scene.Collectibles[x, y] == null && !flagIsSpecial,
                            NotJoint       = true,
                            ClearPerimeter = true,
                            ClearFloor     = scene.Collectibles[x, y] == null && !flagIsSpecial
                        };

                        for (int t = 0; t < 4; t++)
                        {
                            if (corridorLayout[x, y, t] && corridorWidths[x, y, t] > 15f)
                            {
                                flags.NotJoint = false;
                            }
                        }


                        if (scene.Collectibles[x, y] != null)
                        {
                            Collectible.Type type    = scene.Collectibles[x, y].Value;
                            AsciiTexture     texture = null;
                            switch (type)
                            {
                            case Collectible.Type.Armor:
                                texture = Assets.barrelGreenTexture;
                                break;

                            case Collectible.Type.Health:
                                texture = Assets.barrelRedTexture;
                                break;

                            case Collectible.Type.Skill:
                                texture = Assets.barrelBlueTexture;
                                break;
                            }
                            MeshObject barrel = new MeshObject(Assets.barrelModel, texture, new Vector3(roomCenter.X, -3f, roomCenter.Y));
                            scene.AddGameObject(new Collectible(barrel, type, x, y));
                        }

                        if (x == exitRoom.X && y == exitRoom.Y)
                        {
                            flags.ClearCenter    = false;
                            flags.ClearPerimeter = false;
                            flags.ClearFloor     = false;

                            MeshObject exit = new MeshObject(Assets.exitModel, Assets.exitTexture,
                                                             new Vector3(roomCenter.X, -3.25f, roomCenter.Y));
                            zones[x, y].AddMesh(exit);
                            game.PlayerStats.exitPosition = new Vector2(roomCenter.X, roomCenter.Y);
                        }


                        PopulateRoomResults results = PopulateRoom(scene, zones[x, y], x, y, flags);

                        if (results.GenerateFloor)
                        {
                            zones[x, y].AddMesh(SceneGenUtils.MakeFloor(left, right, bottom, top, -4f, FloorTexture, true));
                            zones[x, y].AddMesh(SceneGenUtils.MakeFloor(left, right, bottom, top, 4f, FloorTexture, false));
                        }
                    }
                }
            }
        }
Example #7
0
 public static Generator PillarSmall(AsciiTexture texture, Vector2 center, Vector2 size) => (Scene scene, Zone zone, Vector3 roomCenter) =>
 {
     List <Vector2[]> walls  = SceneGenUtils.MakeRect(-size.X / 2f, size.X / 2f, -size.Y / 2f, size.Y / 2f);
     Vector3          offset = roomCenter + new Vector3(center.X, 0f, center.Y);
     SceneGenUtils.AddWalls(scene, zone, walls, 4f, ObstacleLayer.Wall, texture, offset);
 };