public void Center_ReturnsCenter_Case2() { var bounds = new BoundsInt(0,0,0,8,6,1); Vector2Int center = BoundsIntUtilities.Center(bounds); center.Should().Be(new Vector2Int(4,3)); }
public void Center_ReturnsCenter() { var bounds = new BoundsInt(-2,-2,0,4,4,1); Vector2Int center = BoundsIntUtilities.Center(bounds); center.Should().Be(Vector2Int.zero); }
public void With_ReturnsCorrectResult(BoundsInt source, Vector3Int consideredPosition, BoundsInt expectedResult) { BoundsInt result = BoundsIntUtilities.With(source, consideredPosition); result.Should().Be(expectedResult); }
private void PlaceTilesBasingOnDungeon(BoundsInt gridBounds, Dungeon generator) { bool stairsGenerated = false; foreach (Vector3Int position in gridBounds.allPositionsWithin) { Vector2Int position2D = position.ToVector2Int(); GenTile genTile = generator.GetCellType(position2D.x, position2D.y); switch (genTile) { case GenTile.DirtFloor: { _gameContext.DirtTilemap.SetTile(position, Dirt); if (_rng.Check(0.03f)) { _gameContext.EnvironmentTilemap.SetTile(position, _rng.Choice(FloorEnvironmetals)); } if (_rng.Check(0.06f)) { if (Vector2IntUtilities.Neighbours8(position2D).All(n => generator.GetCellType(n.x, n.y) == GenTile.DirtFloor)) { _gameContext.ObjectsTilemap.SetTile(position, _rng.Choice(WallEnvironmetals)); } } break; } case GenTile.Corridor: { _gameContext.DirtTilemap.SetTile(position, Dirt); break; } case GenTile.StoneWall: case GenTile.DirtWall: { _gameContext.WallsTilemap.SetTile(position, Wall); if (_rng.Check(0.04f)) { _gameContext.EnvironmentTilemap.SetTile(position, _rng.Choice(WallAttachmentEnvironmetals)); } break; } case GenTile.Upstairs: { _gameContext.DirtTilemap.SetTile(position, Dirt); _gameContext.EnvironmentTilemap.SetTile(position, StairsUp); _gameContext.WallsTilemap.SetTile(position, null); stairsGenerated = true; break; } case GenTile.Downstairs: { _gameContext.DirtTilemap.SetTile(position, Dirt); break; } case GenTile.Door: { _gameContext.DirtTilemap.SetTile(position, Dirt); GenTile tileToRight = generator.GetCellType(position.x + 1, position.y); bool isHorizontalDoor = tileToRight == GenTile.Corridor || tileToRight == GenTile.DirtFloor; bool doorsAreOpen = _rng.Check(0.3f); if (doorsAreOpen) { _gameContext.EnvironmentTilemap.SetTile(position, isHorizontalDoor ? DoorsHorizontalOpen : DoorsVerticalOpen); } else { _gameContext.WallsTilemap.SetTile(position, isHorizontalDoor ? DoorsHorizontalClosed : DoorsVerticalClosed); } break; } default: { break; } } } if (!stairsGenerated) { BoundsInt randomRoom = _rng.Choice(generator.Rooms); Vector3Int center = BoundsIntUtilities.Center(randomRoom).ToVector3Int(); _gameContext.DirtTilemap.SetTile(center, Dirt); _gameContext.EnvironmentTilemap.SetTile(center, StairsUp); _gameContext.WallsTilemap.SetTile(center, null); Debug.Log("Missing stairs in dungeon! Generating in random room on position: " + center); } }
private void GenerateActorsInDungeon(Dungeon currentDungeon, DungeonConfig dungeonConfig, bool isFirstDungeon) { BoundsInt playerRoom = new BoundsInt(); if (isFirstDungeon) { BoundsInt furthestRoomToStairs = FurthestRoomToStairsResolver.GetFurthestRoomToStairs(currentDungeon); playerRoom = furthestRoomToStairs; BoundsInt roomToSpawnPlayerIn = playerRoom; Vector2Int playerPosition = BoundsIntUtilities.Center(roomToSpawnPlayerIn); Vector2Int breadPosition = Vector2Int.zero; var neighboursRebourse = Vector2IntUtilities.Neighbours8(playerPosition).ToList(); neighboursRebourse.Reverse(); foreach (var neighbour in neighboursRebourse) { if (_gridInfoProvider.IsWalkable(neighbour) && neighbour != playerPosition) { _entitySpawner.SpawnItem(BreadItem, neighbour); breadPosition = neighbour; break; } } foreach (var neighbour in neighboursRebourse) { if (neighbour != breadPosition && _gridInfoProvider.IsWalkable(neighbour)) { _entitySpawner.SpawnItem(KeyItem, neighbour); break; } } BoundsInt aroundPlayerRoom = new BoundsInt(playerRoom.position - new Vector3Int(1, 1, 0), playerRoom.size + new Vector3Int(2, 2, 0)); foreach (Vector3Int positionInPlayerRoom in aroundPlayerRoom.allPositionsWithin) { if (_gameContext.WallsTilemap.GetTile(positionInPlayerRoom) == DoorsVerticalClosed || _gameContext.EnvironmentTilemap.GetTile(positionInPlayerRoom) == DoorsVerticalOpen) { _gameContext.WallsTilemap.SetTile(positionInPlayerRoom, HeavyDoorsVerticalClosed); _gameContext.EnvironmentTilemap.SetTile(positionInPlayerRoom, null); } if (_gameContext.WallsTilemap.GetTile(positionInPlayerRoom) == DoorsHorizontalClosed || _gameContext.EnvironmentTilemap.GetTile(positionInPlayerRoom) == DoorsHorizontalOpen) { _gameContext.WallsTilemap.SetTile(positionInPlayerRoom, HeavyDoorsHorizontalClosed); _gameContext.EnvironmentTilemap.SetTile(positionInPlayerRoom, null); } } var playerActorBehaviour = _entitySpawner.SpawnActor(ActorType.Player, playerPosition); playerActorBehaviour.ActorData.ControlledByPlayer = true; _gameContext.PlayerActor = playerActorBehaviour; _gameConfig.FollowPlayerCamera.Follow = playerActorBehaviour.transform; _uiConfig.Arrows.transform.parent = playerActorBehaviour.transform; _uiConfig.Arrows.transform.localPosition = new Vector3(0, -0.1f, 0); } foreach (BoundsInt room in currentDungeon.Rooms.Skip(isFirstDungeon ? 1 :0)) { if (room == playerRoom) { continue; } float populationValue = _rng.NextFloat(); int populationInRoom = Mathf.RoundToInt(dungeonConfig.ChanceToRoomPopulation.Evaluate(populationValue)); for (int i = 0; i < populationInRoom; i++) { ActorDefinition[] actorTypesAvailable = dungeonConfig.EnemiesToSpawn; ActorType actorTypeChosen = _rng.Choice(actorTypesAvailable).ActorType; Vector2Int centralPosition = BoundsIntUtilities.Center(room); _entitySpawner.SpawnActor(actorTypeChosen, centralPosition); } } _entitySpawner.SpawnActor(dungeonConfig.BossToSpawn.ActorType, currentDungeon.StairsLocation, true); }