Exemple #1
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));
                        }
                    }
                }
            }
        }