コード例 #1
0
    public void ConvertDirectionalCorridorFloor(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation l = conversion_cell.location;

        if (behaviour.useDirectionalFloors)
        {
            if (conversion_cell.IsCorridorFloor())
            {
                // Count how many border neighbours are non-walls
                int    countFloorNeighs = 0;
                bool[] validIndices     = new bool[4];

                if (conversion_cell.IsTile())
                {
                    // This was a tile, check neigh walls
                    CellLocation[] border_neighs = map.GetAllNeighbours(l);
                    for (int i = 0; i < border_neighs.Length; i++)
                    {
                        CellLocation other_l = border_neighs[i];
                        if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && !(map.GetCell(other_l).IsWall()))                             // TODO: Maybe isValid is not needed!
                        {
                            countFloorNeighs++;
                            validIndices[i] = true;
                        }
                    }
                }
                else
                {
                    // This was a border, check neigh floors instead
                    CellLocation[] floor_neighs = map.GetAllNeighbours(l);
                    for (int i = 0; i < floor_neighs.Length; i++)
                    {
                        CellLocation other_l = floor_neighs[i];
                        if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && map.GetCell(other_l).IsFloor())                                       // TODO: Maybe isValid is not needed!
                        {
                            countFloorNeighs++;
                            validIndices[i] = true;
                        }
                    }
                }

                // Define the adbvanced floors
                if (countFloorNeighs == 1)
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloorU;
                    for (int i = 0; i < 4; i++)
                    {
                        if (validIndices[i])
                        {
                            conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                            break;
                        }
                    }
                }
                else if (countFloorNeighs == 2)
                {
                    // Corridor I
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloorI;
                    for (int i = 0; i < 4; i++)
                    {
                        if (validIndices[i])
                        {
                            conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)];
                            break;
                        }
                    }

                    // Corridor L
                    for (int i = 0; i < 4; i++)
                    {
                        if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                        {
                            // This and the next are valid: left turn (we consider all of them to be left turns(
                            conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                            conversion_cell.Type        = VirtualCell.CellType.CorridorFloorL;
                            break;
                        }
                    }
                }
                else if (countFloorNeighs == 3)
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloorT;
                    for (int i = 0; i < 4; i++)
                    {
                        if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                        {
                            // This, the one before and the next are valid: T cross (with this being the middle road)
                            conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)];
                            break;
                        }
                    }
                }
                else if (countFloorNeighs == 4)
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloorX;
                }
            }
        }
    }
コード例 #2
0
    // The second pass will update the different tiles as needed
    private void PerformSpecificConversions(VirtualMap map, VirtualMap[] maps, int storey)
    {
        VirtualCell conversion_cell;

        VirtualCell[,] output_cells = new VirtualCell[map.Width, map.Height];

        for (int i = 0; i < map.Width; i++)
        {
            for (int j = 0; j < map.Height; j++)
            {
                CellLocation loc = new CellLocation(i, j);
                conversion_cell = VirtualCell.Copy(map.GetCell(loc));
                //Debug.Log("CHECKING " + conversion_cell);

                if (conversion_cell.IsFloor())
                {
                    ConvertFloor(map, conversion_cell);
                }
                else if (conversion_cell.IsDoor())
                {
                    ConvertDoor(map, conversion_cell);

                    CheckWallRendering(map, conversion_cell);
//					if (renderWall) ConvertFixedWallOrientation(map,conversion_cell);

                    AddFillingFloors(map, conversion_cell);
                }
                else if (conversion_cell.IsWall())
                {
                    bool isPerimeter = ConvertWall(map, conversion_cell);

                    bool renderWall = CheckWallRendering(map, conversion_cell);
                    if (renderWall)
                    {
                        if (!isPerimeter || (isPerimeter && !behaviour.orientPerimeter))
                        {
                            ConvertFixedWallOrientation(map, conversion_cell);
                        }
                    }
                    else
                    {
                        ConvertRock(map, conversion_cell);                      // May be a rock
                    }
                    AddFillingFloors(map, conversion_cell);
                }
                else if (conversion_cell.IsNone())
                {
                    //Debug.Log("NONE CELL " + conversion_cell);
                    // 'None' cells are usually converted to columns
                    bool isColumn    = ConvertColumn(map, conversion_cell);
                    bool isPerimeter = ConvertPerimeterColumn(map, conversion_cell);
                    ConvertFixedWallOrientation(map, conversion_cell);                          // Also columns need to be orientated correctly

                    // If not a column, check what this is
                    if (!isColumn && !isPerimeter)
                    {
                        // Usually a rock
                        ConvertRock(map, conversion_cell);
                    }

                    bool isActuallyFloor = false;
                    // Also, an inside-room tile may be transformed into a floor
                    if (!isPerimeter)
                    {
                        if (conversion_cell.IsFloor()) //CheckRoom(map,conversion_cell.location)){
                        //Debug.Log("INSIDE!");
                        {
                            AddToCorrectRoom(map, conversion_cell.location);
                            conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                            ConvertFloor(map, conversion_cell);
                            isActuallyFloor = true;
                        }
                    }

                    if (!isActuallyFloor)
                    {
                        AddFillingFloors(map, conversion_cell);
                    }
                }
                else if (conversion_cell.IsRock())
                {
                    // We may draw rocks
                    ConvertRock(map, conversion_cell);

                    AddFillingFloors(map, conversion_cell);
                }


                // Final pass on orientation randomization
                CheckOrientationRandomization(map, conversion_cell);

                // We save it in the initial map
                output_cells[i, j] = conversion_cell;
            }
        }

        // We can now override the initial map!
        for (int i = 0; i < map.Width; i++)
        {
            for (int j = 0; j < map.Height; j++)
            {
                map.SetCell(i, j, output_cells[i, j]);
            }
        }
    }
コード例 #3
0
    protected void ConvertFake3DEffect(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation below_loc = map.GetNeighbourCellLocation(conversion_cell.location, VirtualMap.DirectionType.South);

        if ((conversion_cell.IsColumn() || conversion_cell.IsWall()))
        {
            // If we have a wall below and this is a wall, we transform this to a special wall
            bool        isAbove    = false;
            VirtualCell below_cell = null;
            if (!map.LocationIsOutsideBounds(below_loc))
            {
                below_cell = map.GetCell(below_loc);
                if (below_cell.IsColumn() || below_cell.IsWall() || below_cell.IsRock())
                {
                    isAbove = true;
                }
                else
                {
                    isAbove = false;
                }
            }
            else
            {
                isAbove = true;
            }

            if (isAbove)
            {
                if (conversion_cell.IsRoom())
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Room_WallAbove;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Corridor_WallAbove;
                }
            }
            else
            {
                if (conversion_cell.IsRoom())
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Room_WallFront;

//					// Also, we add this to make sure the doors work correctly
//					if (below_cell.IsDoor()){
//						conversion_cell.AddCellInstance(VirtualCell.CellType.DoorHorizontalTop,below_cell.Orientation);
//					}
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Corridor_WallFront;
                }
            }

            conversion_cell.Orientation = VirtualMap.DirectionType.West;             // Force orientation
        }
        else if (conversion_cell.IsDoor())
        {
            if (conversion_cell.IsHorizontal())
            {
                conversion_cell.Type = VirtualCell.CellType.DoorHorizontalBottom;
            }
            else
            {
                conversion_cell.Type = VirtualCell.CellType.DoorVertical;
            }
        }
    }
コード例 #4
0
        public void ProjectComputedEntity()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            RequiredDataContainer ModelData = ProjectDataProvider.ComputedEntityData();

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/projectQuery.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            ComputedEntity CarRepairedByGarage = new ComputedEntity("CarManufacturedBy",
                                                                    new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Car"), "car"),
                                                                    (Relationship)ModelData.EntityRelationshipModel.FindByName("ManufacturedBy"),
                                                                    new List <QueryableEntity> {
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Manufacturer"), "manufacturer")
            });

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                (Relationship)ModelData.EntityRelationshipModel.FindByName("Owns"),
                new List <QueryableEntity> {
                new QueryableEntity(CarRepairedByGarage)
            },
                ModelData.ERMongoMapping);

            VirtualMap VMap = RJoinOp.ComputeVirtualMap();

            Dictionary <string, ProjectExpression> ProjectPersonAttrs = new Dictionary <string, ProjectExpression>();

            QueryableEntity Person       = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"));
            QueryableEntity Car          = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Car"));
            QueryableEntity Manufacturer = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Manufacturer"));

            List <ProjectArgument> ProjectArguments = new List <ProjectArgument>();

            ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Car.GetAttribute("model"), Car, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Car.GetAttribute("year"), Car, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Manufacturer.GetAttribute("name"), Manufacturer, new BooleanExpr(true)));

            ProjectStage ProjectOp = new ProjectStage(ProjectArguments, VMap);

            List <AlgebraOperator> OpList = new List <AlgebraOperator> {
                RJoinOp, ProjectOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
コード例 #5
0
ファイル: Tiles.cs プロジェクト: david-reborn/Celeste
        public void GenerateTiles(Tilemap tilemap, VirtualMap <char> foregroundData, int startX, int startY, int tilesX, int tilesY, bool forceSolid, char forceID, Autotiler.Behaviour behaviour, ColliderGrid colliderGrid)
        {
            Rectangle forceFill = Rectangle.Empty;

            if (forceSolid)
            {
                forceFill = new Rectangle(startX, startY, tilesX, tilesY);
            }
            if (foregroundData != null)
            {
                for (int x1 = startX; x1 < startX + tilesX; x1 += 50)
                {
                    for (int y1 = startY; y1 < startY + tilesY; y1 += 50)
                    {
                        if (!foregroundData.AnyInSegmentAtTile(x1, y1))
                        {
                            y1 = y1 / 50 * 50;
                        }
                        else
                        {
                            int x2 = x1;
                            for (int index1 = Math.Min(x1 + 50, startX + tilesX); x2 < index1; ++x2)
                            {
                                int y2 = y1;
                                for (int index2 = Math.Min(y1 + 50, startY + tilesY); y2 < index2; ++y2)
                                {
                                    Autotiler.Tiles tiles = this.TileHandler(foregroundData, x2, y2, forceFill, forceID, behaviour);
                                    if (tiles != null)
                                    {
                                        SolidTile tile = ScriptableObject.CreateInstance <SolidTile>();
                                        tile.SetTile(tiles);
                                        tile.colliderType = colliderGrid[x2 - startX, y2 - startY]? Tile.ColliderType.Grid:Tile.ColliderType.None;
                                        tilemap.SetTile(new Vector3Int(x2 - startX, -(y2 - startY), 0), tile);
                                        //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
                                        //return;
                                    }
                                    //if (tiles != null)
                                    //{
                                    //    tileGrid.Tiles[x2 - startX, y2 - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures);
                                    //    //if (tiles.HasOverlays)
                                    //    //    animatedTiles.Set(x2 - startX, y2 - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f);
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int x = startX; x < startX + tilesX; ++x)
                {
                    for (int y = startY; y < startY + tilesY; ++y)
                    {
                        Autotiler.Tiles tiles = this.TileHandler((VirtualMap <char>)null, x, y, forceFill, forceID, behaviour);
                        if (tiles != null)
                        {
                            SolidTile tile = ScriptableObject.CreateInstance <SolidTile>();
                            tile.SetTile(tiles);
                            tile.colliderType = colliderGrid[x - startX, y - startY] ? Tile.ColliderType.Grid : Tile.ColliderType.None;
                            tilemap.SetTile(new Vector3Int(x - startX, -(y - startY), 0), tile);
                            //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
                            //return;
                        }
                        //if (tiles != null)
                        //{
                        //    tileGrid.Tiles[x - startX, y - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures);
                        //    if (tiles.HasOverlays)
                        //        animatedTiles.Set(x - startX, y - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f);
                        //}
                    }
                }
            }
        }
コード例 #6
0
    private void CreateHorizontalCorridor(VirtualMap map, BSPTreeNodeBounds roomBoundsLeft, BSPTreeNodeBounds roomBoundsRight)
    {
        BSPTreeNodeBounds higherRoomBounds = null, lowerRoomBounds = null;
        int  v_start      = 0;
        bool createLShape = false;
        int  higher_min_v = Mathf.Max(roomBoundsLeft.min_y, roomBoundsRight.min_y);
        int  lower_max_v  = Mathf.Min(roomBoundsLeft.max_y, roomBoundsRight.max_y);
        int  overlapping_v_range = lower_max_v - higher_min_v;

        if (overlapping_v_range > 0)
        {
            // They overlap: we choose randomly the start where the sides overlap
            v_start = DungeonGenerator.Random.Instance.Next(
                higher_min_v,
                lower_max_v - 1);
        }
        else
        {
            // They do not overlap! We'll need a L-shaped corridor!
            // We do so starting from one room, then going OVER the other, and then going down
            //Debug.Log("L");
            createLShape = true;

            // We now need to check which is the higher one
            if (roomBoundsLeft.max_y > roomBoundsRight.max_y)
            {
                // L higher than R
                higherRoomBounds = roomBoundsLeft;
                lowerRoomBounds  = roomBoundsRight;
            }
            else
            {
                // R higher than L
                higherRoomBounds = roomBoundsRight;
                lowerRoomBounds  = roomBoundsLeft;
            }

            // The y_start comes from the higher one
            v_start = DungeonGenerator.Random.Instance.Next(
                higherRoomBounds.min_y,
                higherRoomBounds.max_y - 1);
        }

        // We create a corridor from west to east
        int corridorWidth = 1;

        if (!createLShape)
        {
            corridorWidth = Mathf.Min(overlapping_v_range, maxCorridorWidth);
            if (corridorWidth > 1 && overlapping_v_range > 0)
            {
                //Debug.Log("Start: " + v_start);
                int overflow = higher_min_v - (v_start - (corridorWidth - 1)); //(v_start - (corridorWidth - 1)) +  (higher_min_v - 1);
                v_start += overflow;
                //Debug.Log("Overflow: " + overflow);
                //Debug.Log("End: " + v_start);
            }
        }

        for (int x = roomBoundsLeft.max_x - 1; x < roomBoundsRight.min_x; x++)
        {
            CellLocation l = new CellLocation(x * 2 + 1, v_start * 2 + 1);
            //Debug.Log("EAST: " + l);

            // If already entering a corridor, we stop here!
            //CellLocation target_l = map.GetNeighbourCellLocationOfSameType(l,VirtualMap.DirectionType.East);
            //if (map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor) return;
            //CellLocation target_l = map.GetNeighbourCellLocationOfSameType(l, VirtualMap.DirectionType.East);
            //bool makeDoor = !(map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor);

            map.CreateCorridor(l, VirtualMap.DirectionType.East, corridorWidth, makeDoor: true);
        }

        if (createLShape)
        {
            // We also create the S-N corridor
            for (int y = lowerRoomBounds.max_y - 1; y < v_start; y++)
            {
                int x_start = 0;
                if (lowerRoomBounds == roomBoundsRight)
                {
                    x_start = roomBoundsRight.min_x;
                }
                else
                {
                    x_start = roomBoundsLeft.max_x - 1;
                }
                CellLocation l = new CellLocation(x_start * 2 + 1, y * 2 + 1);

                // If already entering a corridor, we stop here!
                //CellLocation target_l = map.GetNeighbourCellLocationOfSameType(l, VirtualMap.DirectionType.East);
                //if (map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor) return;
                // If already entering a corridor, we stop here!
                //CellLocation target_l = map.GetNeighbourCellLocationOfSameType(l, VirtualMap.DirectionType.North);
                //bool makeDoor = !(map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor);

                map.CreateCorridor(l, VirtualMap.DirectionType.North, makeDoor: true);
            }
        }
    }
コード例 #7
0
        public override void Render(Graphics map, VirtualMap <char> solids)
        {
            Bitmap img = Gameplay.GetImage("objects/cassetteblock/solid");

            if (img == null)
            {
                return;
            }

            List <Bitmap> sub = new List <Bitmap>();

            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    sub.Add(Util.GetSubImage(img, new Sprite(i * 8, j * 8, 8, 8, 0, 0, 8, 8)));
                }
            }

            int minX = int.MaxValue, maxX = int.MinValue, minY = int.MaxValue, maxY = int.MinValue;

            for (int i = 0; i < Bounds.Count; i++)
            {
                Rectangle rect = Bounds[i];
                if (rect.X < minX)
                {
                    minX = rect.X;
                }
                if (rect.X + rect.Width > maxX)
                {
                    maxX = rect.X + rect.Width;
                }
                if (rect.Y < minY)
                {
                    minY = rect.Y;
                }
                if (rect.Y + rect.Height > maxY)
                {
                    maxY = rect.Y + rect.Height;
                }
            }

            Color color;

            switch (Color)
            {
            case Type.Pink: color = Util.HexToColor("f049be"); break;

            case Type.Purple: color = Util.HexToColor("c547cb"); break;

            case Type.Orange: color = Util.HexToColor("b68026"); break;

            default: color = Util.HexToColor("49aaf0"); break;
            }

            ColorMatrix matrix = new ColorMatrix();

            matrix.Matrix40 = color.R / 255f - 1f;
            matrix.Matrix41 = color.G / 255f - 1f;
            matrix.Matrix42 = color.B / 255f - 1f;
            ImageAttributes attributes = new ImageAttributes();

            attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            for (int j = minY; j < maxY; j += 8)
            {
                for (int i = minX; i < maxX; i += 8)
                {
                    bool exists = Contains(i, j);
                    if (!exists)
                    {
                        continue;
                    }

                    bool   left  = Contains(i - 8, j);
                    bool   right = Contains(i + 8, j);
                    bool   up    = Contains(i, j - 8);
                    bool   down  = Contains(i, j + 8);
                    Bitmap tile  = null;
                    if (left && right && up && down)
                    {
                        if (!Contains(i + 8, i - 8))
                        {
                            tile = sub[3];
                        }
                        else if (!Contains(i + 8, i + 8))
                        {
                            tile = sub[11];
                        }
                        else if (!Contains(i - 8, i - 8))
                        {
                            tile = sub[7];
                        }
                        else if (!Contains(i - 8, i + 8))
                        {
                            tile = sub[15];
                        }
                        else
                        {
                            tile = sub[5];
                        }
                    }
                    else if (left && up && down)
                    {
                        tile = sub[6];
                    }
                    else if (right && up && down)
                    {
                        tile = sub[4];
                    }
                    else if (left && right && up)
                    {
                        tile = sub[9];
                    }
                    else if (left && right && down)
                    {
                        tile = sub[1];
                    }
                    else if (left && down)
                    {
                        tile = sub[2];
                    }
                    else if (right && down)
                    {
                        tile = sub[0];
                    }
                    else if (right && up)
                    {
                        tile = sub[8];
                    }
                    else
                    {
                        tile = sub[10];
                    }

                    map.DrawImage(tile, new Rectangle(i, j, 8, 8), 0, 0, 8, 8, GraphicsUnit.Pixel, attributes);
                }
            }

            for (int i = 0; i < sub.Count; i++)
            {
                sub[i].Dispose();
            }
            img.Dispose();
        }
コード例 #8
0
        public override void Awake(Scene scene)
        {
            base.Awake(scene);

            awake = true;
            if (!HasGroup)
            {
                MasterOfGroup  = true;
                Group          = new List <CaveWall>();
                GroupBoundsMin = new Point((int)X, (int)Y);
                GroupBoundsMax = new Point((int)Right, (int)Bottom);
                AddToGroupAndFindChildren(this);

                Rectangle         rectangle  = new Rectangle(GroupBoundsMin.X / 8, GroupBoundsMin.Y / 8, (GroupBoundsMax.X - GroupBoundsMin.X) / 8 + 1, (GroupBoundsMax.Y - GroupBoundsMin.Y) / 8 + 1);
                Level             level      = SceneAs <Level>();
                Rectangle         tileBounds = level.Session.MapData.TileBounds;
                VirtualMap <char> virtualMap = level.SolidsData.Clone();
                foreach (CaveWall item in Group)
                {
                    int x      = (int)(item.X / 8f) - level.Session.MapData.TileBounds.X;
                    int y      = (int)(item.Y / 8f - level.Session.MapData.TileBounds.Y);
                    int tilesX = (int)(item.Width / 8f);
                    int tilesY = (int)(item.Height / 8f);
                    for (int i = x; i < x + tilesX; i++)
                    {
                        for (int j = y; j < y + tilesY; j++)
                        {
                            virtualMap[i, j] = item.fillTile;
                        }
                    }
                }
                // Pretend that the CaveWalls are just part of the map, then draw the CaveWalls on top of it
                // This is a complicated solution to getting the CaveWalls to blend with both the foregroundTiles and each other
                foreach (CaveWall item in Group)
                {
                    int x      = (int)item.X / 8 - tileBounds.Left;
                    int y      = (int)item.Y / 8 - tileBounds.Top;
                    int tilesX = (int)item.Width / 8;
                    int tilesY = (int)item.Height / 8;
                    item.tiles = GFX.FGAutotiler.GenerateOverlay(item.fillTile, x, y, tilesX, tilesY, virtualMap).TileGrid;
                    item.Add(item.tiles);
                    item.Add(new TileInterceptor(item.tiles, highPriority: false));
                }
            }
            TryToInitPosition();

            if (CollideCheck <Player>())
            {
                tiles.Alpha    = 0f;
                fadeOut        = true;
                fadeIn         = false;
                cutout.Visible = false;
            }

            if (!disableTransitionFading)
            {
                TransitionListener transitionListener = new TransitionListener();
                transitionListener.OnOut      = OnTransitionOut;
                transitionListener.OnOutBegin = OnTransitionOutBegin;
                transitionListener.OnIn       = OnTransitionIn;
                transitionListener.OnInBegin  = OnTransitionInBegin;
                Add(transitionListener);
            }
        }
コード例 #9
0
        public override void Render(Graphics map, VirtualMap <char> solids)
        {
            Bitmap particles = Gameplay.GetImage("objects/dreamblock/particles");

            if (particles == null)
            {
                return;
            }

            List <Bitmap> parts = new List <Bitmap>();

            parts.Add(Util.GetSubImage(particles, new Sprite(14, 0, 7, 7, 0, 0, 7, 7)));
            parts.Add(Util.GetSubImage(particles, new Sprite(7, 0, 7, 7, 0, 0, 7, 7)));
            parts.Add(Util.GetSubImage(particles, new Sprite(0, 0, 7, 7, 0, 0, 7, 7)));

            using (SolidBrush brush = new SolidBrush(Color.Black)) {
                map.FillRectangle(brush, Position.X, Position.Y, Width, Height);
            }

            Bitmap img   = null;
            Color  color = Color.Red;
            int    count = (int)((float)Width * (float)Height / 64f * 0.7f);

            for (int i = 0; i < count; i++)
            {
                int x     = Util.Random.Next(Width);
                int y     = Util.Random.Next(Height);
                int layer = Util.Random.Choose(0, 1, 1, 1, 2, 2, 2, 2, 2);
                switch (layer)
                {
                case 0:
                    color = Util.Random.Choose(Util.HexToColor("FFEF11"), Util.HexToColor("FF00D0"), Util.HexToColor("08a310"));
                    img   = parts[0];
                    break;

                case 1:
                    color = Util.Random.Choose(Util.HexToColor("5fcde4"), Util.HexToColor("7fb25e"), Util.HexToColor("E0564C"));
                    img   = parts[1];
                    break;

                case 2:
                    color = Util.Random.Choose(Util.HexToColor("5b6ee1"), Util.HexToColor("CC3B3B"), Util.HexToColor("7daa64"));
                    img   = parts[2];
                    break;
                }

                if (x + img.Width > Width)
                {
                    x -= img.Width;
                }
                if (y + img.Height > Height)
                {
                    y -= img.Height;
                }

                ColorMatrix matrix = new ColorMatrix();
                matrix.Matrix40 = color.R / 255f - 1f;
                matrix.Matrix41 = color.G / 255f - 1f;
                matrix.Matrix42 = color.B / 255f - 1f;
                ImageAttributes attributes = new ImageAttributes();
                attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                map.DrawImage(img, new Rectangle((int)Position.X + x, (int)Position.Y + y, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attributes);
            }

            using (Pen pen = new Pen(Color.White)) {
                map.DrawRectangle(pen, Position.X, Position.Y, Width - 1, Height - 1);
            }

            particles.Dispose();
            for (int i = 0; i < parts.Count; i++)
            {
                parts[i].Dispose();
            }
        }
コード例 #10
0
    protected void AddStairsToRooms(VirtualMap currentMap, VirtualMap[] maps, int storey)
    {
        if (storey == 0)
        {
            return;                      // Do not add at the first one! We'll add stairs from top to bottom.
        }
        bool allowStairsCloseToDoors = false;

//		Debug.Log ("CHECKING STAIRS FOR STOREY " + storey);
        // Stairs are added if we have two consecutive floors both at storey i and i+1
        foreach (CellLocation l in currentMap.roomCells)
        {
            VirtualCell cell_here = currentMap.GetCell(l);

            if (cell_here.location == currentMap.end || cell_here.location == currentMap.start)
            {
                continue;                                                                                               // Not on the start/end cells
            }
            foreach (VirtualMap.DirectionType direction in currentMap.directions)
            {
                CellLocation next_l = currentMap.GetNeighbourCellLocationAtStep(l, direction, this.TileSeparationSteps);
                if (currentMap.LocationIsOutsideBounds(next_l))
                {
                    continue;
                }
                if (next_l == currentMap.end || next_l == currentMap.start)
                {
                    continue;                                                                           // Not on the start/end cells
                }
                VirtualCell cell_next = currentMap.GetCell(next_l);
//				Debug.Log ("Cell here: " + cell_here.starting_location + " is " + cell_here.Type + " and next: " + cell_next.starting_location + " is " + cell_next.Type);

                if (VirtualCell.IsRoomFloor(cell_here.Type) && VirtualCell.IsRoomFloor(cell_next.Type))
                {
                    if (!currentMap.CellsAreInTheSameRoom(cell_here.location, cell_next.location))
                    {
                        continue;
                    }
                    // Two consecutive floors! Check the below map as well
//				    Debug.Log ("DOUBLE FLOORS! " + storey);
                    if (!allowStairsCloseToDoors && (currentMap.HasAdjacentDoor(cell_here.location) || currentMap.HasAdjacentDoor(cell_next.location)))
                    {
                        continue;
                    }

                    VirtualMap belowMap = maps[storey - 1];
                    if (belowMap.GetCell(l).IsRoomFloor() && belowMap.GetCell(next_l).IsRoomFloor())
                    {
                        if (l == belowMap.end || l == belowMap.start)
                        {
                            continue;                                                                   // Not on the start/end cells
                        }
                        if (next_l == belowMap.end || next_l == belowMap.start)
                        {
                            continue;                                                                                   // Not on the start/end cells
                        }
                        if (!belowMap.CellsAreInTheSameRoom(cell_here.location, cell_next.location))
                        {
                            continue;
                        }
                        // Also below! This is a two-tile stair! Update the map!

                        if (!allowStairsCloseToDoors && (currentMap.HasAdjacentDoor(cell_here.location) || currentMap.HasAdjacentDoor(cell_next.location)))
                        {
                            continue;
                        }

                        // We place the stair below
                        belowMap.GetCell(l).AddCellInstance(VirtualCell.CellType.Ladder2, direction);

                        // We remove any ceiling below
                        belowMap.GetCell(l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Ceilings);
                        belowMap.GetCell(next_l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Ceilings);

                        // We override the current map by removing its floors
                        currentMap.GetCell(l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Floors);
                        currentMap.GetCell(next_l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Floors);

                        nStairs++;
                        if (nStairs > 0)
                        {
                            return;                                      // At most one stair
                        }
                    }
                }
            }
        }
    }
コード例 #11
0
 public FancyExitBlock(EntityData data, Vector2 offset)
     : base(data.Position + offset, data.Width, data.Height, data.Char("tileType", '3'))
 {
     tileMap  = GenerateTileMap(data.Attr("tileData", ""));
     Collider = GenerateBetterColliderGrid(tileMap, 8, 8);
 }
コード例 #12
0
    public void ConvertDirectionalRoomColumn(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation l = conversion_cell.location;

        if (behaviour.useDirectionalFloors)
        {
            CellLocation[] border_neighs;

            bool considerDoorsAsWalls = true;

            // Count how many border neighbours are room walls
            int    countWallNeighs = 0;
            bool[] validIndices    = new bool[4];

            // This was a 'tile', check neigh walls
            border_neighs = map.GetAllNeighbours(l);
            for (int i = 0; i < border_neighs.Length; i++)
            {
                CellLocation other_l = border_neighs[i];
                if (!map.LocationIsOutsideBounds(other_l)
                    &&
                    (((behaviour.isolateDirectionalWallsForRooms && map.GetCell(other_l).IsRoomWall()) ||
                      (!behaviour.isolateDirectionalWallsForRooms && map.GetCell(other_l).IsWall())) ||
                     (considerDoorsAsWalls && map.GetCell(other_l).IsDoor())) &&
                    !map.IsPassageRemovable(other_l)      // Make sure the wall is not being removed!
                    )
                {
                    //Debug.Log(l + " -  " + other_l + " " + map.GetCell(other_l).Type);
                    countWallNeighs++;
                    validIndices[i] = true;
                }
            }


            // Define the adbvanced tiles
            //Debug.Log ("Cell " + l + " has neigh walls " + countWallNeighs);
            if (countWallNeighs == 0)
            {
                conversion_cell.Type = VirtualCell.CellType.RoomWallO;
            }
            else if (countWallNeighs == 1)
            {
                conversion_cell.Type = VirtualCell.CellType.RoomWallU;
            }
            else if (countWallNeighs == 2)
            {
                // Wall I
                conversion_cell.Type = VirtualCell.CellType.RoomWallI;
                //Debug.Log("SETTING " + l + " TO I");
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[i])
                    {
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)];
                        break;
                    }
                }

                // Wall L
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                    {
                        // This and the next are valid: left turn (we consider all of them to be left turns(
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                        conversion_cell.Type        = VirtualCell.CellType.RoomWallL;
                        break;
                    }
                }
            }
            else if (countWallNeighs == 3)
            {
                conversion_cell.Type = VirtualCell.CellType.RoomWallT;
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                    {
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)];
                        break;
                    }
                }
            }
            else if (countWallNeighs == 4)
            {
                conversion_cell.Type = VirtualCell.CellType.RoomWallX;
            }
        }
    }
コード例 #13
0
    public void ConvertDirectionalCorridorColumn(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation l = conversion_cell.location;

        if (behaviour.useDirectionalFloors)
        {
            // Count how many border neighbours are walls
            int    countWallNeighs = 0;
            bool[] validIndices    = new bool[4];

            // This was a 'tile', check neigh walls
            CellLocation[] border_neighs = map.GetAllNeighbours(l);
            for (int i = 0; i < border_neighs.Length; i++)
            {
                CellLocation other_l = border_neighs[i];
                if (!map.LocationIsOutsideBounds(other_l) // && other_l.isValid()
                    )                                     // TODO: Maybe isValid is not needed!
                {
                    VirtualCell other_cell = map.GetCell(other_l);
                    if (other_cell.IsWall() && !map.IsPassageRemovable(other_cell.location))
                    {
                        countWallNeighs++;
                        validIndices[i] = true;
                    }
                }
            }

            // Define the advanced tile to use
            // TODO: merge this with the one for directional floors somehow!
            if (countWallNeighs == 0)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallO;
            }
            else if (countWallNeighs == 1)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallU;
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[i])
                    {
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                        break;
                    }
                }
            }
            else if (countWallNeighs == 2)
            {
                // Corridor I
                conversion_cell.Type = VirtualCell.CellType.CorridorWallI;
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[i])
                    {
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)];
                        break;
                    }
                }

                // Corridor L
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                    {
                        // This and the next are valid: left turn (we consider all of them to be left turns(
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                        conversion_cell.Type        = VirtualCell.CellType.CorridorWallL;
                        break;
                    }
                }
            }
            else if (countWallNeighs == 3)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallT;
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                    {
                        // This, the one before and the next are valid: T cross (with this being the middle road)
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)];
                        break;
                    }
                }
            }
            else if (countWallNeighs == 4)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallX;
            }
        }
    }
コード例 #14
0
    public void ConvertDirectionalRoomFloor(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation l = conversion_cell.location;

        if (behaviour.useDirectionalFloors)
        {
            if (conversion_cell.IsRoomFloor())
            {
                CellLocation[] border_neighs;
                CellLocation[] floor_neighs;

                bool considerDoorsAsWalls = true;

                // Count how many border neighbours are non-walls
                int    countFloorNeighs = 0;
                bool[] validIndices     = new bool[4];

                if (conversion_cell.IsTile())
                {
                    // This was a tile, check neigh walls
                    border_neighs = map.GetAllNeighbours(l);
                    for (int i = 0; i < border_neighs.Length; i++)
                    {
                        CellLocation other_l = border_neighs[i];
                        if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() &&
                            !(map.GetCell(other_l).IsWall()) &&
                            !(considerDoorsAsWalls && map.GetCell(other_l).IsDoor())
                            )
                        {
                            countFloorNeighs++;
                            validIndices[i] = true;
                        }
                    }
                }
                else
                {
                    // This was a border, check neigh floors instead
                    floor_neighs = map.GetAllNeighbours(l);
                    //					Debug.Log ("From " + l);None

                    for (int i = 0; i < floor_neighs.Length; i++)
                    {
                        CellLocation other_l = floor_neighs[i];
                        //						Debug.Log ("At " + other_l + " is " + map.GetCell(other_l).Type);
                        bool insideRoomTile = CheckInsideRoomTile(map, other_l);                        // We need this to be checked now, or we cannot know if a tile is inside a room reliably
                        if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() &&
                            (map.GetCell(other_l).IsFloor() ||                       //|| map.GetCell(other_l).IsNone()
                             map.GetCell(other_l).IsInsideRoomColumn() ||                       // Treat inside room columns as floors here
                             insideRoomTile
//						 || map.GetCell(other_l).IsNone()
                            ))
                        {
                            countFloorNeighs++;
                            validIndices[i] = true;
                        }
                    }
                }


                // Define the adbvanced floors
                //	Debug.Log (countFloorNeighs);
                if (countFloorNeighs == 2)
                {
                    bool adjacentFloors = false;

                    // This is a room corner
                    for (int i = 0; i < 4; i++)
                    {
                        if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                        {
                            conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                            adjacentFloors = true;
                            break;
                        }
                    }

                    if (adjacentFloors)
                    {
                        conversion_cell.Type = VirtualCell.CellType.RoomFloorCorner;
                    }
                    else
                    {
                        conversion_cell.Type = VirtualCell.CellType.RoomFloorInside;
                    }
                }
                else if (countFloorNeighs == 3)
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloorBorder;
                    for (int i = 0; i < 4; i++)
                    {
                        if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)])
                        {
                            conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 2, 4)];
                            break;
                        }
                    }
                }
                else if (countFloorNeighs == 4)
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloorInside;
                }
                else
                {
                    // Wrong number of floor neighs, may happen if we have too small rooms. We always use the INSIDE one, then.
                    conversion_cell.Type = VirtualCell.CellType.RoomFloorInside;
                }
            }
        }
    }
コード例 #15
0
    VirtualRoom CreateRoom(VirtualMap map, RoomGenerator roomGenerator, BSPTreeNode node, CellLocation starting_location)
    {
        // Get the maximum bounds
        BSPTreeNodeBounds bounds = node.areaBounds;
        int range_x = bounds.max_x - bounds.min_x;
        int range_y = bounds.max_y - bounds.min_y;

        // Cannot create a room if the area is empty!
        if (range_x == 0 || range_y == 0)
        {
            Debug.LogWarning("Room size too small to be created! " + range_x + "," + range_y);
            return(null);
        }

        // Choose a random size for the room
        int min_size_x = Mathf.Max(1, Mathf.FloorToInt(range_x * roomSizeMinRange));
        int max_size_x = Mathf.Max(1, Mathf.CeilToInt(range_x * roomSizeMaxRange));
        int min_size_y = Mathf.Max(1, Mathf.FloorToInt(range_y * roomSizeMinRange));
        int max_size_y = Mathf.Max(1, Mathf.CeilToInt(range_y * roomSizeMaxRange));

        // Compute size
        int size_x = DungeonGenerator.Random.Instance.Next(min_size_x, max_size_x);
        int size_y = DungeonGenerator.Random.Instance.Next(min_size_y, max_size_y);

        // Compute start
        int start_x, start_y;

        start_x = bounds.min_x + DungeonGenerator.Random.Instance.Next(range_x - size_x);
        start_y = bounds.min_y + DungeonGenerator.Random.Instance.Next(range_y - size_y);

        // If the starting location is inside these bounds, we must force it to create the room on it
        if (starting_location.isValid() && bounds.Contain(starting_location))
        {
            //Debug.Log("YES IN");
            int x = starting_location.x / 2;
            int y = starting_location.y / 2;

            //Debug.Log("Start bounds: " + (new BSPTreeNodeBounds(start_x, start_y, start_x + size_x, start_y + size_y)).ToString());

            // Make sure the start includes this, or decrease it
            if (x < start_x)
            {
                start_x = x;
            }
            if (y < start_y)
            {
                start_y = y;
            }

            //Debug.Log(y);
            //Debug.Log(start_y + size_y);

            // Make sure the end includes thid, or increase it
            if (x + 1 >= start_x + size_x)
            {
                size_x = x + 1 - start_x;
            }
            if (y + 1 >= start_y + size_y)
            {
                size_y = y + 1 - start_y;
            }

            //Debug.Log("End bounds: " + (new BSPTreeNodeBounds(start_x, start_y, start_x + size_x, start_y + size_y)).ToString());
        }

        //Debug.Log("MIN " + min_size_x + " MAX " + max_size_x + " SIZE " + size_x);

        //Debug.Log("SPACE " + " [" + node.areaBounds.min_x + "," + node.areaBounds.max_x + "] [" + node.areaBounds.min_y + "," + node.areaBounds.max_y + "]");

        //Debug.Log("delta_low " + delta_low + " delta_high " + delta_high);

        //Debug.Log("CREATING ROOM: " + start_x + " + " + size_x + "   ||   " + start_y + " + " + size_y);

        node.roomBounds = new BSPTreeNodeBounds(start_x, start_y, start_x + size_x, start_y + size_y);

        // Start and end must be converted to whole-map sizes (not just floors)
        start_x = start_x * 2 + 1;
        start_y = start_y * 2 + 1;

        return(roomGenerator.CreateRoom(map, size_x, size_y, start_x, start_y));
    }
コード例 #16
0
ファイル: TileGrid.cs プロジェクト: david-reborn/Celeste
 public TileGrid(int tileWidth, int tileHeight, int tilesX, int tilesY)
 {
     this.TileWidth  = tileWidth;
     this.TileHeight = tileHeight;
     this.Tiles      = new VirtualMap <MTexture>(tilesX, tilesY, (MTexture)null);
 }
コード例 #17
0
    void LinkCorridors(BSPTreeNode node, VirtualMap map, int recursionLevel, bool isLeft = false)
    {
        //Debug.Log("Linking at level " + recursionLevel);
        // We link corridors recursively
        if (node.left != null && node.right != null)
        {
            // First we recurse to the children
            LinkCorridors(node.left, map, recursionLevel + 1, isLeft: true);
            LinkCorridors(node.right, map, recursionLevel + 1, isLeft: false);

            // We get the left, we get the right, and we link them
            // We do this for non-leaf nodes
            if (node.left.roomBounds != null && node.right.roomBounds != null)
            {
                // DEBUG: Only connect at higher recursion level
                if (recursionLevel >= 0)
                {
                    if (node.splitDirection == BSPSplitDirection.HORIZONTAL)
                    {
                        CreateVerticalCorridor(map, node.left.roomBounds, node.right.roomBounds);
                    }
                    else
                    {
                        CreateHorizontalCorridor(map, node.left.roomBounds, node.right.roomBounds);
                    }
                }

                //if (isLeft)
                //return;
                //return;

                // Now that we linked the children, we update the bounds of this node, which had no roomBounds before
                BSPTreeNodeBounds lb = node.left.roomBounds;
                BSPTreeNodeBounds rb = node.right.roomBounds;

                // We always get the more central one, to make sure we can connect easily
                // Central one: has midpoint closest to the middle of the map
                int mid_x_map = map.ActualWidth / 2;
                int mid_y_map = map.ActualHeight / 2;
                int mid_x_lb  = (lb.min_x + lb.max_x) / 2;
                int mid_y_lb  = (lb.min_y + lb.max_y) / 2;
                int mid_x_rb  = (rb.min_x + rb.max_x) / 2;
                int mid_y_rb  = (rb.min_y + rb.max_y) / 2;

                //Debug.Log("MID_MAP " + mid_x_map);
                //Debug.Log("mid_x_lb " + mid_x_lb);
                //Debug.Log("mid_x_rb " + mid_x_rb);

                // Check the more central one
                int dist_lb = Mathf.Abs(mid_x_lb - mid_x_map) + Mathf.Abs(mid_y_lb - mid_y_map);
                int dist_rb = Mathf.Abs(mid_x_rb - mid_x_map) + Mathf.Abs(mid_y_rb - mid_y_map);

                //Debug.Log("RECURSION " + recursionLevel);
                //Debug.Log("THIS: " + node.areaBounds);// + "    CONNECTED INSIDE: " + node.roomBounds);
                //Debug.Log("Distance of L is " + dist_lb + " L: " + lb);
                //Debug.Log("Distance of R is " + dist_rb + " R: " + rb);
                //Debug.Log("CLOSEST L? " + (dist_lb <= dist_rb));
                if (dist_lb <= dist_rb)
                {
                    node.roomBounds = new BSPTreeNodeBounds(lb.min_x, lb.min_y, lb.max_x, lb.max_y);
                }
                else
                {
                    node.roomBounds = new BSPTreeNodeBounds(rb.min_x, rb.min_y, rb.max_x, rb.max_y);
                }

                // We use all the range (WRONG! may not connect!)

                /*
                 * node.roomBounds = new BSPTreeNodeBounds(Mathf.Min(lb.min_x, rb.min_x),
                 *                      Mathf.Min(lb.min_y, rb.min_y),
                 *                      Mathf.Max(lb.max_x, rb.max_x),
                 *                      Mathf.Max(lb.max_y, rb.max_y)
                 *                      );*/
                // We connect left or right, depending on where we are (WRONG)

                /*
                 * if (!isLeft)
                 * {
                 *  node.roomBounds =  new BSPTreeNodeBounds(lb.min_x, lb.min_y, lb.max_x, lb.max_y);
                 * }
                 * else
                 * {
                 *  node.roomBounds = new BSPTreeNodeBounds(rb.min_x, rb.min_y, rb.max_x, rb.max_y);
                 * }*/
                //node.roomBounds = new BSPTreeNodeBounds(lb.min_x, lb.min_y, lb.max_x, lb.max_y);
            }
        }
    }
コード例 #18
0
    public void ComputeStartAndEnd(VirtualMap map, VirtualMap vmapBelow)
    {
        List <CellLocation> iterable_locations;
        bool foundStart = false;

        if (forceStartAndEndInRooms)
        {
            iterable_locations = new List <CellLocation>(map.RoomWalkableLocations);
        }
        else
        {
            iterable_locations = new List <CellLocation>(map.WalkableLocations);
        }

        // Makes sure it is in some dead end, or in a room, if possible
        List <CellLocation> possible_start_locations = new List <CellLocation>();

        foreach (CellLocation l in iterable_locations)
        {
            if (map.IsDeadEnd(l) || map.IsInRoom(l))
            {
                possible_start_locations.Add(l);
            }
        }

        // If not possible, consider all locations equally
        if (possible_start_locations.Count == 0)
        {
            possible_start_locations = iterable_locations;
        }
        //		Debug.Log ("Possible start locations: " + possible_start_locations.Count);

        // TODO: Make an option for the start to be on the perimeter
//		foreach (CellLocation l in possible_start_locations) {
//			if (map.IsOnPerimeter(l) possible_start_locations
//		}


        // NOTE: we here find a start, but the algorithm already could have one! maybe use that?
        if (vmapBelow == null)
        {
            // Choose a random walkable cell as the starting point
            int index;
            index = DungeonGenerator.Random.Instance.Next(0, possible_start_locations.Count - 1);
            if (index != -1 && possible_start_locations.Count != 0)
            {
                map.start  = new CellLocation(possible_start_locations[index].x, possible_start_locations[index].y);
                foundStart = true;
            }
        }
        else
        {
            // Choose the cell above the below map's end as the starting point
            map.start  = vmapBelow.end;
            foundStart = true;
        }

        if (foundStart)
        {
            //Debug.Log ("CHOSEN START: " + map.start);
            // For this to work, we must compute the distance of all cells from the starting cell
            map.ComputeCellDistances(startCellLocation: map.start);

            // Choose a cell at a certain distance from the starting point as the ending point
            map.end = map.GetCellLocationInLimits(iterable_locations, minimumDistanceBetweenStartAndEnd / 100.0f * map.GetMaximumDistance(), maximumDistanceBetweenStartAndEnd / 100.0f * map.GetMaximumDistance());
        }

        //Debug.Log("START : " + map.start);
        //Debug.Log("END : " + map.end);
        //Debug.Log(map.GetWalkDistance(map.start,map.end));

        if (!foundStart)
        {
            Debug.LogError("Cannot find a suitable entrance!");
        }
        //DebugUtils.Assert(foundStart, "Cannot find a suitable entrance!");
    }
コード例 #19
0
    private void CreateVerticalCorridor(VirtualMap map, BSPTreeNodeBounds roomBoundsBottom, BSPTreeNodeBounds roomBoundsTop)
    {
        BSPTreeNodeBounds higherRoomBounds = null, lowerRoomBounds = null;
        int  v_start      = 0;
        bool createLShape = false;
        int  higher_min_v = Mathf.Max(roomBoundsBottom.min_x, roomBoundsTop.min_x);
        int  lower_max_v  = Mathf.Min(roomBoundsBottom.max_x, roomBoundsTop.max_x);
        int  overlapping_v_range = lower_max_v - higher_min_v;

        if (overlapping_v_range > 0)
        {
            // They overlap: we choose randomly the start where the sides overlap
            v_start = DungeonGenerator.Random.Instance.Next(higher_min_v, lower_max_v - 1);
        }
        else
        {
            // They do not overlap! We'll need a L-shaped corridor!
            // We do so starting from one room, then going OVER the other, and then going down
            //Debug.Log("L");
            createLShape = true;

            // We now need to check which is the higher one
            if (roomBoundsBottom.max_x > roomBoundsTop.max_x)
            {
                // B higher than T
                higherRoomBounds = roomBoundsBottom;
                lowerRoomBounds  = roomBoundsTop;
            }
            else
            {
                // T higher than B
                higherRoomBounds = roomBoundsTop;
                lowerRoomBounds  = roomBoundsBottom;
            }

            // The v_start comes from the higher one
            v_start = DungeonGenerator.Random.Instance.Next(
                higherRoomBounds.min_x,
                higherRoomBounds.max_x - 1);
        }


        // We create a corridor from south to north
        int corridorWidth = 1;

        if (!createLShape)
        {
            corridorWidth = Mathf.Min(overlapping_v_range, maxCorridorWidth);
            if (corridorWidth > 1 && overlapping_v_range > 0)
            {
                int overflow = v_start + (corridorWidth - 1) - (lower_max_v - 1);
                v_start -= overflow;
                //Debug.Log(overflow);
            }
        }

        for (int y = roomBoundsBottom.max_y - 1; y < roomBoundsTop.min_y; y++)
        {
            CellLocation l = new CellLocation(v_start * 2 + 1, y * 2 + 1);

            // If already entering a corridor, we stop here!

            /*CellLocation target_l =  map.GetNeighbourCellLocationOfSameType(l, VirtualMap.DirectionType.North);
             * bool makeDoor = !(map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor);
             * makeDoor = true;*/

            map.CreateCorridor(l, VirtualMap.DirectionType.North, corridorWidth, makeDoor: true);
        }

        if (createLShape)
        {
            // We also create the W-E corridor
            for (int x = lowerRoomBounds.max_x - 1; x < v_start; x++)
            {
                int y_start = 0;
                if (lowerRoomBounds == roomBoundsTop)
                {
                    y_start = roomBoundsTop.min_y;
                }
                else
                {
                    y_start = roomBoundsBottom.max_y - 1;
                }
                CellLocation l = new CellLocation(x * 2 + 1, y_start * 2 + 1);

                // If already entering a corridor, we stop here!
                //CellLocation target_l = map.GetNeighbourCellLocationOfSameType(l, VirtualMap.DirectionType.East);
                //bool makeDoor = !(map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor);
                //CellLocation target_l = map.GetNeighbourCellLocationOfSameType(l, VirtualMap.DirectionType.East);
                //if (map.GetCell(target_l).Type == VirtualCell.CellType.CorridorFloor) return;

                map.CreateCorridor(l, VirtualMap.DirectionType.East, makeDoor: true);
            }
        }
    }
コード例 #20
0
 virtual protected void GenerateWithAlgorithm(VirtualMap map, VirtualMap vmapBelow)
 {
 }
コード例 #21
0
        public override void Render(Graphics map, VirtualMap <char> solids)
        {
            Bitmap        block = Gameplay.GetImage("objects/zipmover/block");
            Bitmap        light = Gameplay.GetImage("objects/zipmover/light00");
            List <Bitmap> cogs  = Gameplay.GetAllImages("objects/zipmover/innercog");

            if (block == null)
            {
                return;
            }

            DrawCogs(map, new Vector2(Width / 2, Height / 2 + 1), Color.Black);
            DrawCogs(map, new Vector2(Width / 2, Height / 2), null);

            //Outline
            Vector2 position = Position;

            using (SolidBrush brush = new SolidBrush(Color.Black)) {
                map.FillRectangle(brush, Position.X - 1, Position.Y - 1, Width + 2, Height + 2);
            }

            int   val     = 1;
            float num2    = 0f;
            int   count   = cogs.Count;
            int   yOffset = 4;

            while (yOffset <= Height - 4f)
            {
                int valTemp = val;
                int xOffset = 4;
                while (xOffset <= Width - 4f)
                {
                    int       index      = (int)(mod((num2 + val * 3.14159274f * 4f) / 1.57079637f, 1f) * count);
                    Bitmap    currentCog = cogs[index];
                    Rectangle cogBounds  = new Rectangle(0, 0, currentCog.Width, currentCog.Height);
                    Vector2   zero       = Vector2.Zero;
                    if (xOffset <= 4)
                    {
                        zero.X           = 2f;
                        cogBounds.X      = 2;
                        cogBounds.Width -= 2;
                    }
                    else if (xOffset >= Width - 4f)
                    {
                        zero.X           = -2f;
                        cogBounds.Width -= 2;
                    }
                    if (yOffset <= 4)
                    {
                        zero.Y            = 2f;
                        cogBounds.Y       = 2;
                        cogBounds.Height -= 2;
                    }
                    else if (yOffset >= Height - 4f)
                    {
                        zero.Y            = -2f;
                        cogBounds.Height -= 2;
                    }

                    using (Bitmap sub = Util.GetSubImage(currentCog, new Sprite(cogBounds.X, cogBounds.Y, cogBounds.Width, cogBounds.Height, 0, 0, cogBounds.Width, cogBounds.Height))) {
                        if (val < 0)
                        {
                            //Darken
                            ColorMatrix matrix = new ColorMatrix();
                            matrix.Matrix00 = 0.5f;
                            matrix.Matrix11 = 0.5f;
                            matrix.Matrix22 = 0.5f;

                            ImageAttributes attributes = new ImageAttributes();
                            attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                            map.DrawImage(sub, new Rectangle((int)(Position.X + xOffset + zero.X - 5), (int)(Position.Y + yOffset + zero.Y - 5), sub.Width, sub.Height), 0, 0, sub.Width, sub.Height, GraphicsUnit.Pixel, attributes);
                        }
                        else
                        {
                            map.DrawImage(sub, Position.X + xOffset + zero.X - 5, Position.Y + yOffset + zero.Y - 5);
                        }
                    }
                    val      = -val;
                    num2    += 1.04719758f;
                    xOffset += 8;
                }
                if (valTemp == val)
                {
                    val = -val;
                }
                yOffset += 8;
            }

            int edgeColumn = 0;

            while (edgeColumn < Width / 8f)
            {
                int edgeRow = 0;
                while (edgeRow < Height / 8f)
                {
                    int edgeTileX = (edgeColumn == 0) ? 0 : ((edgeColumn == Width / 8f - 1f) ? 2 : 1);
                    int edgeTileY = (edgeRow == 0) ? 0 : ((edgeRow == Height / 8f - 1f) ? 2 : 1);
                    if (edgeTileX != 1 || edgeTileY != 1)
                    {
                        using (Bitmap sub = Util.GetSubImage(block, new Sprite(edgeTileX * 8, edgeTileY * 8, 8, 8, 0, 0, 8, 8))) {
                            map.DrawImage(sub, Position.X + edgeColumn * 8, Position.Y + edgeRow * 8);
                        }
                    }
                    edgeRow++;
                }
                edgeColumn++;
            }

            map.DrawImage(light, Position.X + Width / 2 - light.Width / 2, Position.Y);

            block.Dispose();
            light.Dispose();
            for (int i = 0; i < cogs.Count; i++)
            {
                cogs[i].Dispose();
            }
        }
コード例 #22
0
    void Start()
    {
        //读取配置文件
        Gfx.Game = Atlas.FromAtlas(Path.Combine("Graphics", "Atlases", "Gameplay"), Atlas.AtlasDataFormat.Packer);
        Gfx.Misc = Atlas.FromAtlas(Path.Combine("Graphics", "Atlases", "Misc"), Atlas.AtlasDataFormat.PackerNoAtlas);

        Gfx.SceneryTiles = new Tileset(Gfx.Game["tilesets/scenery"], 8, 8);
        //读取前景配置文件
        Gfx.BGAutotiler = new Autotiler(Path.Combine("Graphics", "BackgroundTiles.xml"));
        Gfx.FGAutotiler = new Autotiler(Path.Combine("Graphics", "ForegroundTiles.xml"));

        Debug.Log("==加载AreaData文件");
        SaveData.Start(new SaveData
        {
            Name        = "test001",
            AssistMode  = true,
            VariantMode = true
        }, 0);
        //加载区域
        AreaData.Load();

        Debug.Log("==创建Session,读取关卡地图");

        Session session = new Session(new AreaKey(0, AreaMode.Normal), null, null);

        MapData   mapData   = session.MapData;
        LevelData levelData = mapData.Levels[0];

        Debug.Log(levelData);

        Rectangle         tileBounds1 = mapData.TileBounds;
        VirtualMap <char> data1       = new VirtualMap <char>(tileBounds1.Width, tileBounds1.Height, '0');
        VirtualMap <char> data2       = new VirtualMap <char>(tileBounds1.Width, tileBounds1.Height, '0');
        VirtualMap <bool> virtualMap  = new VirtualMap <bool>(tileBounds1.Width, tileBounds1.Height, false);
        Regex             regex       = new Regex("\\r\\n|\\n\\r|\\n|\\r");

        foreach (LevelData level in mapData.Levels)
        {
            Rectangle tileBounds2 = level.TileBounds;
            int       left1       = tileBounds2.Left;
            tileBounds2 = level.TileBounds;
            int      top1      = tileBounds2.Top;
            string[] strArray1 = regex.Split(level.Bg);
            for (int index1 = top1; index1 < top1 + strArray1.Length; ++index1)
            {
                for (int index2 = left1; index2 < left1 + strArray1[index1 - top1].Length; ++index2)
                {
                    data1[index2 - tileBounds1.X, index1 - tileBounds1.Y] = strArray1[index1 - top1][index2 - left1];
                }
            }

            string[] strArray2 = regex.Split(level.Solids);
            for (int index1 = top1; index1 < top1 + strArray2.Length; ++index1)
            {
                for (int index2 = left1; index2 < left1 + strArray2[index1 - top1].Length; ++index2)
                {
                    data2[index2 - tileBounds1.X, index1 - tileBounds1.Y] = strArray2[index1 - top1][index2 - left1];
                }
            }
            tileBounds2 = level.TileBounds;
            int left2 = tileBounds2.Left;
            while (true)
            {
                int num1 = left2;
                tileBounds2 = level.TileBounds;
                int right = tileBounds2.Right;
                if (num1 < right)
                {
                    tileBounds2 = level.TileBounds;
                    int top2 = tileBounds2.Top;
                    while (true)
                    {
                        int num2 = top2;
                        tileBounds2 = level.TileBounds;
                        int bottom = tileBounds2.Bottom;
                        if (num2 < bottom)
                        {
                            virtualMap[left2 - tileBounds1.Left, top2 - tileBounds1.Top] = true;
                            ++top2;
                        }
                        else
                        {
                            break;
                        }
                    }
                    ++left2;
                }
                else
                {
                    break;
                }
            }
            Gfx.FGAutotiler.LevelBounds.Add(new Rectangle(level.TileBounds.X - tileBounds1.X, level.TileBounds.Y - tileBounds1.Y, level.TileBounds.Width, level.TileBounds.Height));
        }

        foreach (Rectangle rectangle in mapData.Filler)
        {
            for (int left = rectangle.Left; left < rectangle.Right; ++left)
            {
                for (int top = rectangle.Top; top < rectangle.Bottom; ++top)
                {
                    char ch1 = '0';
                    if (rectangle.Top - tileBounds1.Y > 0)
                    {
                        char ch2 = data2[left - tileBounds1.X, rectangle.Top - tileBounds1.Y - 1];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0' && rectangle.Left - tileBounds1.X > 0)
                    {
                        char ch2 = data2[rectangle.Left - tileBounds1.X - 1, top - tileBounds1.Y];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0' && rectangle.Right - tileBounds1.X < tileBounds1.Width - 1)
                    {
                        char ch2 = data2[rectangle.Right - tileBounds1.X, top - tileBounds1.Y];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0' && rectangle.Bottom - tileBounds1.Y < tileBounds1.Height - 1)
                    {
                        char ch2 = data2[left - tileBounds1.X, rectangle.Bottom - tileBounds1.Y];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0')
                    {
                        ch1 = '1';
                    }
                    data2[left - tileBounds1.X, top - tileBounds1.Y]      = ch1;
                    virtualMap[left - tileBounds1.X, top - tileBounds1.Y] = true;
                }
            }
        }
        using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
        {
label_85:
            while (enumerator.MoveNext())
            {
                LevelData current     = enumerator.Current;
                Rectangle tileBounds2 = current.TileBounds;
                int       left1       = tileBounds2.Left;
                while (true)
                {
                    int num1 = left1;
                    tileBounds2 = current.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = current.TileBounds;
                        int  top = tileBounds2.Top;
                        char ch1 = data1[left1 - tileBounds1.X, top - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, top - tileBounds1.Y - index]; ++index)
                        {
                            data1[left1 - tileBounds1.X, top - tileBounds1.Y - index] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num2 = tileBounds2.Bottom - 1;
                        char ch2  = data1[left1 - tileBounds1.X, num2 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, num2 - tileBounds1.Y + index]; ++index)
                        {
                            data1[left1 - tileBounds1.X, num2 - tileBounds1.Y + index] = ch2;
                        }
                        ++left1;
                    }
                    else
                    {
                        break;
                    }
                }
                tileBounds2 = current.TileBounds;
                int num3 = tileBounds2.Top - 4;
                while (true)
                {
                    int num1 = num3;
                    tileBounds2 = current.TileBounds;
                    int num2 = tileBounds2.Bottom + 4;
                    if (num1 < num2)
                    {
                        tileBounds2 = current.TileBounds;
                        int  left2 = tileBounds2.Left;
                        char ch1   = data1[left2 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left2 - tileBounds1.X - index, num3 - tileBounds1.Y]; ++index)
                        {
                            data1[left2 - tileBounds1.X - index, num3 - tileBounds1.Y] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num4 = tileBounds2.Right - 1;
                        char ch2  = data1[num4 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[num4 - tileBounds1.X + index, num3 - tileBounds1.Y]; ++index)
                        {
                            data1[num4 - tileBounds1.X + index, num3 - tileBounds1.Y] = ch2;
                        }
                        ++num3;
                    }
                    else
                    {
                        goto label_85;
                    }
                }
            }
        }

        using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
        {
label_100:
            while (enumerator.MoveNext())
            {
                LevelData current     = enumerator.Current;
                Rectangle tileBounds2 = current.TileBounds;
                int       left        = tileBounds2.Left;
                while (true)
                {
                    int num1 = left;
                    tileBounds2 = current.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = current.TileBounds;
                        int top = tileBounds2.Top;
                        if (data2[left - tileBounds1.X, top - tileBounds1.Y] == '0')
                        {
                            for (int index = 1; index < 8; ++index)
                            {
                                virtualMap[left - tileBounds1.X, top - tileBounds1.Y - index] = true;
                            }
                        }
                        tileBounds2 = current.TileBounds;
                        int num2 = tileBounds2.Bottom - 1;
                        if (data2[left - tileBounds1.X, num2 - tileBounds1.Y] == '0')
                        {
                            for (int index = 1; index < 8; ++index)
                            {
                                virtualMap[left - tileBounds1.X, num2 - tileBounds1.Y + index] = true;
                            }
                        }
                        ++left;
                    }
                    else
                    {
                        goto label_100;
                    }
                }
            }
        }
        using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
        {
label_122:
            while (enumerator.MoveNext())
            {
                LevelData current     = enumerator.Current;
                Rectangle tileBounds2 = current.TileBounds;
                int       left1       = tileBounds2.Left;
                while (true)
                {
                    int num1 = left1;
                    tileBounds2 = current.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = current.TileBounds;
                        int  top = tileBounds2.Top;
                        char ch1 = data2[left1 - tileBounds1.X, top - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, top - tileBounds1.Y - index]; ++index)
                        {
                            data2[left1 - tileBounds1.X, top - tileBounds1.Y - index] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num2 = tileBounds2.Bottom - 1;
                        char ch2  = data2[left1 - tileBounds1.X, num2 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, num2 - tileBounds1.Y + index]; ++index)
                        {
                            data2[left1 - tileBounds1.X, num2 - tileBounds1.Y + index] = ch2;
                        }
                        ++left1;
                    }
                    else
                    {
                        break;
                    }
                }
                tileBounds2 = current.TileBounds;
                int num3 = tileBounds2.Top - 4;
                while (true)
                {
                    int num1 = num3;
                    tileBounds2 = current.TileBounds;
                    int num2 = tileBounds2.Bottom + 4;
                    if (num1 < num2)
                    {
                        tileBounds2 = current.TileBounds;
                        int  left2 = tileBounds2.Left;
                        char ch1   = data2[left2 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left2 - tileBounds1.X - index, num3 - tileBounds1.Y]; ++index)
                        {
                            data2[left2 - tileBounds1.X - index, num3 - tileBounds1.Y] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num4 = tileBounds2.Right - 1;
                        char ch2  = data2[num4 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[num4 - tileBounds1.X + index, num3 - tileBounds1.Y]; ++index)
                        {
                            data2[num4 - tileBounds1.X + index, num3 - tileBounds1.Y] = ch2;
                        }
                        ++num3;
                    }
                    else
                    {
                        goto label_122;
                    }
                }
            }
        }
        Vector2         position        = new Vector2((float)tileBounds1.X, (float)tileBounds1.Y) * 8f;
        BackgroundTiles backgroundTiles = new BackgroundTiles(position, data1);


        //MTexture mTexture = Gfx.Game["tilesets/dirt"];
        //草地等等
        //MTexture mTexture = Gfx.Game["tilesets/scenery"];
        //StartCoroutine(DrawTiles(backgroundTiles.Tiles, Vector3.zero));


        /////////////////////////////////////////////////////
        ///构建BgTiles
        /////////////////////////////////////////////////////
        int  l8     = levelData.TileBounds.Left;
        int  t8     = levelData.TileBounds.Top;
        int  w8     = levelData.TileBounds.Width;
        int  h8     = levelData.TileBounds.Height;
        bool flag14 = !string.IsNullOrEmpty(levelData.BgTiles);

        if (flag14)
        {
            int[,] tiles = Util.ReadCSVIntGrid(levelData.BgTiles, w8, h8);
            backgroundTiles.Tiles.Overlay(Gfx.SceneryTiles, tiles, l8 - tileBounds1.X, t8 - tileBounds1.Y);
        }

        //BackdropRenderer backgroundRenderer = new BackdropRenderer();
        //backgroundRenderer.Backdrops = mapData.CreateBackdrops(mapData.Background);

        //BackdropRenderer foregroundRenderer = new BackdropRenderer();
        //foregroundRenderer.Backdrops = mapData.CreateBackdrops(mapData.Foreground);
        //foreach(Backdrop backdrop in backgroundRenderer.Backdrops)
        //{
        //    if(backdrop is Parallax)
        //    {
        //        ShowSprite((backdrop as Parallax).Texture);
        //    }

        //}
        //StartCoroutine(DrawTiles(backgroundTiles.Tiles, Vector3.zero));



        //foreach (DecalData bgDecal in levelData.BgDecals)
        //{
        //    new Decal(bgDecal.Texture, Vector3.zero + bgDecal.Position, bgDecal.Scale, 9000);
        //}
    }
コード例 #23
0
 public override void Render(Graphics map, VirtualMap <char> solids)
 {
 }
コード例 #24
0
    private void PickBestRoomLocation(VirtualMap map, VirtualRoom r)
    {//, int roomNumber){
        // Traverse all floor cells checking for the best position for a room
        int best_score = 1000000;
        int current_score;
        List <CellLocation> best_locations = new List <CellLocation>();
        List <CellLocation> locations      = new List <CellLocation>(map.floorCells);

        foreach (CellLocation map_l in locations)
        {
            r.leftCorner = map_l;
            if (IsRoomLocationValid(map, r))
            {
                current_score = 0;       // Lower is better
                for (int i = 0; i < r.Width; i++)
                {
                    for (int j = 0; j < r.Height; j++)
                    {
                        CellLocation possible_room_l = new CellLocation(r.leftCorner.x + 2 * i, r.leftCorner.y + 2 * j);
                        //						Debug.Log("Possible room l: " + possible_room_l);

                        // Corridor vicinity: good
                        if (map.IsSurroundedByWalls(possible_room_l) && map.HasAdjacentFloor(possible_room_l))
                        {
                            current_score += 1;
                        }

                        bool corridorOverlap = map.IsFloor(possible_room_l);

                        // Corridor overlap: bad (at default)
                        if (!forceRoomTransversal && corridorOverlap)
                        {
                            current_score += 3;
                        }

                        // or good if we want the room in the middle!
                        else if (forceRoomTransversal && !corridorOverlap)
                        {
                            current_score += 3;
                        }

                        // Room overlap: very very bad
                        if (map.IsRoomFloor(possible_room_l))
                        {
                            current_score += 100;
                        }

                        // If multi-storey, the first room should be placed above another room!
                        //						if (roomNumber == 0 && !belowMap.isRoomFloor(possible_room_l)) current_score += 5;

                        // TODO: may be more efficient to exit now if the score is already low enough!
                    }
                }

                if (current_score == 0)
                {
                    continue;                     // Zero is not a valid score, as it means the room is isolated
                }
                if (current_score == best_score)
                {
                    best_locations.Add(map_l);
                }
                else if (current_score < best_score)
                {
                    best_score = current_score;
                    best_locations.Clear();
                    best_locations.Add(map_l);
                }
            }
        }

        if (best_locations.Count == 0)
        {
            r.leftCorner = new CellLocation(-1, -1);
        }
        else
        {
            r.leftCorner = best_locations[DungeonGenerator.Random.Instance.Next(0, best_locations.Count - 1)];
        }
    }
コード例 #25
0
ファイル: AnimatedTiles.cs プロジェクト: david-reborn/Celeste
 public AnimatedTiles(int columns, int rows, AnimatedTilesBank bank)
 {
     this.tiles = new VirtualMap <List <AnimatedTiles.Tile> >(columns, rows, (List <AnimatedTiles.Tile>)null);
     this.Bank  = bank;
 }
コード例 #26
0
    /********************
    * Door creation
    ********************/
    public void CreateDoors(VirtualMap map, VirtualRoom r, RoomGenerator roomGenerator)
    {
        // Create a list of border floors (close to the borders of the room)
        List <CellLocation> borderFloors = new List <CellLocation>();

        for (int i = 0; i < r.Width; i++)
        {
            for (int j = 0; j < r.Height; j++)
            {
                if (i == 0 || j == 0 || i == r.Width - 1 || j == r.Height - 1)
                {
                    CellLocation l = new CellLocation(r.leftCorner.x + 2 * i, r.leftCorner.y + 2 * j);
                    borderFloors.Add(l);
                }
            }
        }

        // For each border floor, check if we are connecting to something on the other side
        List <CellLocation>             outsideBorderFloors = new List <CellLocation>();
        List <CellLocation>             insideBorderFloors  = new List <CellLocation>();
        List <VirtualMap.DirectionType> borderDirections    = new List <VirtualMap.DirectionType>();

        CellLocation target_passage;
        CellLocation target_floor;

        foreach (CellLocation l in borderFloors)
        {
            foreach (VirtualMap.DirectionType dir in map.directions)
            {
                target_passage = map.GetNeighbourCellLocation(l, dir);
                target_floor   = map.GetTargetLocation(l, dir);
                if (!map.LocationIsOutsideBounds(target_floor) &&
                    map.GetCell(target_passage).IsWall() &&
                    !map.IsSurroundedByWalls(target_floor))
                {
                    outsideBorderFloors.Add(target_floor);
                    insideBorderFloors.Add(l);
                    borderDirections.Add(dir);
                }
            }
        }

        // We now create a door for each outside border floor, making sure to avoid re-creating doors if the floors are already connected
        List <CellLocation> unremovedFloors = new List <CellLocation>(outsideBorderFloors);

        for (int i = 0; i < outsideBorderFloors.Count; i++)
        {
            CellLocation l = outsideBorderFloors[i];
            // If not already removed (but we may not skip if we request more doors than needed)
            if (unremovedFloors.Contains(l) || DungeonGenerator.Random.Instance.Next(0, 100) < doorsDensityModifier)
            {
                CreateDoor(map, r, roomGenerator, insideBorderFloors[i], l, borderDirections[i]);
                unremovedFloors.Remove(l);

                // We also remove the other connected cells
                for (int j = unremovedFloors.Count - 1; j >= 0; j--)
                {
                    CellLocation other_l    = unremovedFloors[j];
                    bool         existsPath = map.ExistsPathBetweenLocations(l, other_l);
                    if (existsPath)
                    {
                        unremovedFloors.Remove(other_l);
                    }
                }
            }
        }
    }
コード例 #27
0
    protected void AddFillingFloors(VirtualMap map, VirtualCell conversion_cell)
    {
        if (conversion_cell.Type == VirtualCell.CellType.None)
        {
            return;
        }

        // Fill with floors
        VirtualCell.CellType     initial_type = conversion_cell.Type;
        VirtualMap.DirectionType initial_dir  = conversion_cell.Orientation;
        bool addedFloor = false;

        if (behaviour.fillWithFloors)
        {
            bool mayBeDirectional = false;
            if (CheckRoom(map, conversion_cell.location))
            {
                if (conversion_cell.IsDoor() || conversion_cell.IsEmpty())
                {
                    AddToCorrectRoom(map, conversion_cell.location);
                    conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                    ConvertDirectionalRoomFloor(map, conversion_cell);
                    mayBeDirectional = true;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                }
            }
            else
            {
                if (conversion_cell.IsDoor() || conversion_cell.IsEmpty())
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                    ConvertDirectionalCorridorFloor(map, conversion_cell);
                    mayBeDirectional = true;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                }
            }
            ConvertFloor(map, conversion_cell, mayBeDirectional);
            addedFloor = true;
        }
        else
        {
            // Special case: when not filling with floors AND we do not draw doors, we still need to place a floor underneath the empty passage representing the doors!
            if (conversion_cell.IsEmpty())                      // Decomment this if you want floors underneath doors ALWAYS: // || input_cell.IsDoor()){
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                ConvertDirectionalCorridorFloor(map, conversion_cell);
                ConvertFloor(map, conversion_cell);
                addedFloor = true;
            }
        }

        if (addedFloor)
        {
            // The initial type is switched in, the floor becomes a subtype
            VirtualCell.CellType     new_subtype = conversion_cell.Type;
            VirtualMap.DirectionType new_dir     = conversion_cell.Orientation;
            conversion_cell.Type        = initial_type;
            conversion_cell.Orientation = initial_dir;
            conversion_cell.AddCellInstance(new_subtype, new_dir);
        }
    }
コード例 #28
0
 abstract public void StartDigging(VirtualMap map, CellLocation starting_location, int directionChangeModifier);
コード例 #29
0
        private static void DrawCombineHollowRect(Grid grid, Color color, int x, int y, int left, int right, int top, int bottom)
        {
            float   topLeftX      = grid.AbsoluteLeft + x * grid.CellWidth;
            float   topLeftY      = grid.AbsoluteTop + y * grid.CellHeight;
            Vector2 vector2Width  = Vector2.UnitX * grid.CellWidth;
            Vector2 vector2Height = Vector2.UnitY * grid.CellHeight;

            Vector2 topLeft     = new Vector2(topLeftX, topLeftY);
            Vector2 topRight    = topLeft + vector2Width;
            Vector2 bottomLeft  = topLeft + vector2Height;
            Vector2 bottomRight = topRight + vector2Height;

            VirtualMap <bool> data = grid.Data;

            if (data[x, y])
            {
                // left
                if (x != left && !data[x - 1, y])
                {
                    Draw.Line(topLeft + Vector2.UnitX, bottomLeft + Vector2.UnitX, color);
                }

                // right
                if (x == right || x + 1 <= right && !data[x + 1, y])
                {
                    Draw.Line(topRight, bottomRight, color);
                }

                // top
                if (y != top && !data[x, y - 1])
                {
                    Draw.Line(topLeft, topRight, color);
                }

                // bottom
                if (y == bottom || y + 1 <= bottom && !data[x, y + 1])
                {
                    Draw.Line(bottomLeft - Vector2.UnitY, bottomRight - Vector2.UnitY, color);
                }
            }
            else
            {
                // top left point
                if (x - 1 >= left && y - 1 >= top && data[x - 1, y - 1] && data[x - 1, y] && data[x, y - 1])
                {
                    Draw.Point(topLeft - Vector2.One, color);
                }

                // top right point
                if (x + 1 <= right && y - 1 >= top && data[x + 1, y - 1] && data[x + 1, y] && data[x, y - 1])
                {
                    Draw.Point(topRight - Vector2.UnitY, color);
                }

                // bottom left point
                if (x - 1 >= left && y + 1 <= bottom && data[x - 1, y + 1] && data[x - 1, y] && data[x, y + 1])
                {
                    Draw.Point(bottomLeft - Vector2.UnitX, color);
                }

                // bottom right point
                if (x + 1 <= right && y + 1 >= top && data[x + 1, y + 1] && data[x + 1, y] && data[x, y + 1])
                {
                    Draw.Point(bottomRight, color);
                }
            }
        }
コード例 #30
0
    // This will convert 'None' cells to columns where necessary.
    protected bool ConvertColumn(VirtualMap map, VirtualCell conversion_cell, bool mayBeDirectional = true)
    {
        CellLocation l = conversion_cell.location;
        //Debug.Log(l);
        bool isRoomColumn     = false;
        bool isCorridorColumn = false;
        bool isPassageColumn  = false;
        bool createColumn     = true;

        if (map.IsColumnRemovable(l, behaviour.drawWallCorners, behaviour.createColumnsInRooms))
        {
            //Debug.Log(conversion_cell.location + " Is removable!");
            createColumn = false;
        }
        else
        {
            //Debug.Log(conversion_cell.location + " Is not removable!");

            // We check all neighs to determine what type of column this is
            foreach (VirtualMap.DirectionType dir in map.directions)
            {
                CellLocation neigh_loc = map.GetNeighbourCellLocation(l, dir);
                if (!map.LocationIsOutsideBounds(neigh_loc))
                {
                    VirtualCell neigh_cell = map.GetCell(neigh_loc);

                    //Debug.Log("CHECK " + neigh_cell.location + " TYPE " + neigh_cell.Type);

                    if (neigh_cell.IsDoor())
                    {
                        conversion_cell.Type = VirtualCell.CellType.PassageColumn;
                        isPassageColumn      = true;
                        break;
                    }
                    else if (!isRoomColumn && neigh_cell.IsCorridorWall())
                    {
                        conversion_cell.Type = VirtualCell.CellType.CorridorColumn;
                        isCorridorColumn     = true;
                        // Do not break, as we need to check all the other walls to be sure
                    }
                    else if (neigh_cell.IsRoomWall())
                    {
                        conversion_cell.Type = VirtualCell.CellType.RoomColumn;
                        isRoomColumn         = true;
                        // Do not break, as we need to check all the other walls to be sure
                    }
                }
            }
        }

        // This may be surrounded by floors!
        if (createColumn &&
            (!isRoomColumn && !isCorridorColumn && !isPassageColumn))
        {
            if (map.IsInRoom(l))
            {
                if (behaviour.createColumnsInRooms)
                {
                    conversion_cell.Type = VirtualCell.CellType.InsideRoomColumn;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloorInside;
                }
            }
            else
            {
                // NOT IN ROOM: THIS IS EITHER SURROUNDED BY ROCKS OR BY CORRIDORS!!
                // We check all neighbours to make sure

                /*foreach(VirtualMap.DirectionType dir in map.directions){
                 *      CellLocation neigh_loc = map.GetNeighbourCellLocationOfSameType(l,dir);
                 *      if (!map.LocationIsOutsideBounds(neigh_loc)){
                 *              VirtualCell neigh_cell = map.GetCell(neigh_loc);
                 * }*/
                conversion_cell.Type = VirtualCell.CellType.CorridorColumn;
            }
            //Debug.Log("ROOM COL? " + conversion_cell.Type);
        }


        // Directional column
        if (createColumn)
        {
            ConvertDirectionalColumn(map, conversion_cell, mayBeDirectional);
        }

        // If the column is not created, we disable it
        if (!createColumn)
        {
            conversion_cell.Type = VirtualCell.CellType.None;
        }

        return(createColumn);
    }