Example #1
0
 public static Generator Pillars4Inner(AsciiTexture texture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
 {
     PillarSmall(texture, new Vector2(-12.5f, -12.5f), 5f * Vector2.One).Invoke(scene, zone, roomCenter);
     PillarSmall(texture, new Vector2(12.5f, -12.5f), 5f * Vector2.One).Invoke(scene, zone, roomCenter);
     PillarSmall(texture, new Vector2(-12.5f, 12.5f), 5f * Vector2.One).Invoke(scene, zone, roomCenter);
     PillarSmall(texture, new Vector2(12.5f, 12.5f), 5f * Vector2.One).Invoke(scene, zone, roomCenter);
 };
Example #2
0
 public static Generator Pillars4Outer(AsciiTexture texture) => (Scene scene, Zone zone, Vector3 roomCenter) =>
 {
     PillarSmall(texture, new Vector2(-30f, -30f), 10f * Vector2.One).Invoke(scene, zone, roomCenter);
     PillarSmall(texture, new Vector2(30f, -30f), 10f * Vector2.One).Invoke(scene, zone, roomCenter);
     PillarSmall(texture, new Vector2(-30f, 30f), 10f * Vector2.One).Invoke(scene, zone, roomCenter);
     PillarSmall(texture, new Vector2(30f, 30f), 10f * Vector2.One).Invoke(scene, zone, roomCenter);
 };
Example #3
0
        public static void AddFloor(Zone zone, Vector2 v0, Vector2 v1, float height, AsciiTexture texture, bool floor, Vector3 offset, float uvDensity = 100f)
        {
            float      left   = offset.X + Math.Min(v0.X, v1.X);
            float      right  = offset.X + Math.Max(v0.X, v1.X);
            float      bottom = offset.Z + Math.Min(v0.Y, v1.Y);
            float      top    = offset.Z + Math.Max(v0.Y, v1.Y);
            MeshObject mesh   = MakeFloor(left, right, bottom, top, height + offset.Y, texture, floor, uvDensity);

            zone.AddMesh(mesh);
        }
Example #4
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 #5
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 #6
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 #7
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 #8
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 #10
0
        public static List <Triangle> MakeWall(Vector2[] points, float low, float high, AsciiTexture texture)
        {
            List <Triangle> triangles = new List <Triangle>();

            for (int i = 0; i < points.Length - 1; i++)
            {
                float x0    = points[i].X;
                float z0    = points[i].Y;
                float x1    = points[i + 1].X;
                float z1    = points[i + 1].Y;
                float ratio = (new Vector2(x0, z0) - new Vector2(x1, z1)).Length() / (high - low);

                Triangle triangle1 = new Triangle(new Vector3(x0, high, z0), new Vector3(x1, high, z1), new Vector3(x0, low, z0), texture,
                                                  new Vector2(0f, 0f), new Vector2(ratio, 0f), new Vector2(0f, 1f));
                Triangle triangle2 = new Triangle(new Vector3(x0, low, z0), new Vector3(x1, high, z1), new Vector3(x1, low, z1), texture,
                                                  new Vector2(0f, 1f), new Vector2(ratio, 0f), new Vector2(ratio, 1f));
                triangles.Add(triangle1);
                triangles.Add(triangle2);
            }

            return(triangles);
        }
Example #11
0
        public static MeshObject MakeFloor(float left, float right, float bottom, float top, float height, AsciiTexture texture, bool floor, float uvDensity = 100f)
        {
            Vector3 tr = new Vector3(right, height, top);
            Vector3 tl = new Vector3(left, height, top);
            Vector3 br = new Vector3(right, height, bottom);
            Vector3 bl = new Vector3(left, height, bottom);

            Vector2 uvtl = new Vector2(left, top) / uvDensity;
            Vector2 uvtr = new Vector2(right, top) / uvDensity;
            Vector2 uvbl = new Vector2(left, bottom) / uvDensity;
            Vector2 uvbr = new Vector2(right, bottom) / uvDensity;

            List <Triangle> triangles = floor
                ? new List <Triangle>
            {
                new Triangle(tl, tr, br, texture, uvtl, uvtr, uvbr),
                new Triangle(tl, br, bl, texture, uvtl, uvbr, uvbl)
            }
                : new List <Triangle>
            {
                new Triangle(tl, br, tr, texture, uvtl, uvbr, uvtr),
                new Triangle(tl, bl, br, texture, uvtl, uvbl, uvbr)
            };

            return(new MeshObject(triangles, Vector3.Zero, 0f));
        }
Example #12
0
        public static void AddWalls(Scene scene, Zone zone, List <Vector2[]> walls, float low, float high, ObstacleLayer layer, AsciiTexture texture, Vector3 offset)
        {
            Vector2 offset2D = new Vector2(offset.X, offset.Z);

            foreach (Vector2[] wall in walls)
            {
                List <Triangle> wallTriangles = MakeWall(wall, low, high, texture);
                MeshObject      meshObject    = new MeshObject(wallTriangles, offset, 0f);
                zone.AddMesh(meshObject);
                for (int i = 0; i < wall.Length - 1; i++)
                {
                    scene.AddObstacle(wall[i] + offset2D, wall[i + 1] + offset2D, layer);
                }
            }
        }
Example #13
0
 public static void AddWalls(Scene scene, Zone zone, List <Vector2[]> walls, float h, ObstacleLayer layer, AsciiTexture texture, Vector3 offset)
 {
     AddWalls(scene, zone, walls, -h, h, layer, texture, offset);
 }
Example #14
0
 public static Generator PillarSmall(AsciiTexture texture) => PillarSmall(texture, Vector2.Zero, 10f * Vector2.One);
Example #15
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);
 };