public void SpawnCops(RandomDungeon dungeon, CollisionMap collisionMap, Vector2 avatarStartPosition) { List <Vector2Int> walkablePositions = collisionMap.EmptyPositions(); walkablePositions.RemoveAll((pos) => VectorHelper.OrthogonalDistance(pos, avatarStartPosition) < 10); // Spawn a few cops in the level int numCops = Random.Range(3, 6); for (int i = 0; i < numCops; ++i) { if (walkablePositions.Count == 0) { return; } string enemy = (Random.Range(0, 2) == 0 ? "CopRanged" : "CopMelee"); GameObject newEnemy = GameObject.Instantiate(PrefabManager.instance.PrefabByName(enemy)); Vector2Int pos2 = walkablePositions[Random.Range(0, walkablePositions.Count)]; walkablePositions.Remove(pos2); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newEnemy.transform.position = pos; collisionMap.MarkSpace(pos2.x, pos2.y, newEnemy.GetComponent <SimpleMovement>().uniqueCollisionIdentity); } }
public override IEnumerator PlayInternal(CinematicDirector player) { // Mark all the spaces below the rock as unwalkable so nobody teleports there RandomDungeon dungeon = Game.instance.levelGenerator.dungeon; for (int x = 0; x < dungeon.width; ++x) { for (int y = 13; y < dungeon.height; ++y) { if (Game.instance.levelGenerator.collisionMap.SpaceMarking(x, y) == 0) { Game.instance.levelGenerator.collisionMap.MarkSpace(x, y, 1); } } } yield break; }
public void SetupWithDungeon(RandomDungeon dungeon) { mMap = new int[dungeon.width, dungeon.height]; for (int x = 0; x < dungeon.width; ++x) { for (int y = 0; y < dungeon.height; ++y) { if (dungeon.TileType(x, y) == RandomDungeonTileData.WALL_TILE) { mMap[x, y] = 1; } else if (dungeon.TileType(x, y) == RandomDungeonTileData.EMPTY_TILE) { mMap[x, y] = -1; } else { mMap[x, y] = 0; } } } }
public void SpawnGhosts(RandomDungeon dungeon, CollisionMap collisionMap, Vector2Int avatarStartPosition) { List <Vector2Int> walkablePositions = collisionMap.EmptyPositions(); walkablePositions.RemoveAll((pos) => VectorHelper.OrthogonalDistance(pos, avatarStartPosition) < 10); // Spawn a few cops in the level int numGhosts = Random.Range(10, 20); for (int i = 0; i < numGhosts; ++i) { if (walkablePositions.Count == 0) { return; } GameObject newGhost = GameObject.Instantiate(PrefabManager.instance.PrefabByName("Ghost")); Vector2Int pos2 = walkablePositions[Random.Range(0, walkablePositions.Count)]; walkablePositions.Remove(pos2); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newGhost.transform.position = pos; } }
void OnEnable() { width = serializedObject.FindProperty("width"); height = serializedObject.FindProperty("height"); wallHeight = serializedObject.FindProperty("wallHeight"); scale = serializedObject.FindProperty("scale"); floorChance = serializedObject.FindProperty("floorChance"); randomAtGameStart = serializedObject.FindProperty("randomAtGameStart"); updateFloorColliders = serializedObject.FindProperty("updateFloorColliders"); updateWallColliders = serializedObject.FindProperty("updateWallColliders"); floorObjects = serializedObject.FindProperty("floorObjects"); randomDungeon = (RandomDungeon)serializedObject.targetObject; randomDungeon.wallLayer = randomDungeon.GetComponent <TileInfo>(); if (randomDungeon.transform.childCount > 0) { randomDungeon._floorLayer = randomDungeon.transform.GetChild(0).GetComponent <TileInfo>(); } tileTex = randomDungeon.GetComponent <MeshRenderer>().sharedMaterial.mainTexture; }
public void SpawnDebris(RandomDungeon dungeon, CollisionMap collisionMap, Vector2 avatarStartPosition) { List <Vector2Int> positions = collisionMap.EmptyPositions(); positions.RemoveAll((pos) => VectorHelper.OrthogonalDistance(pos, avatarStartPosition) < 3); int numDebris = Random.Range(positions.Count / 5, positions.Count / 4); for (int i = 0; i < numDebris; ++i) { if (positions.Count == 0) { return; } Vector2Int pos = positions.Sample(); // todo bdsowers - ensure that this position is valid GameObject newDebris = PrefabManager.instance.InstantiatePrefabByName(PrefabManager.instance.debrisPrefabs.Sample().name); newDebris.transform.position = MapCoordinateHelper.MapToWorldCoords(pos); collisionMap.MarkSpace(pos.x, pos.y, newDebris.GetComponent <SimpleMovement>().uniqueCollisionIdentity); positions.Remove(pos); } }
private IEnumerator Start() { mDungeonGenerator = new RandomDungeonGenerator(); TextAsset roomSetData = Resources.Load <TextAsset>("RoomSets/" + CurrentDungeonFloorData().roomSet); mRoomset = new RoomSet(); mRoomset.LoadFromTextAsset(roomSetData); mDungeon = mDungeonGenerator.GenerateDungeon(mRoomset, DungeonGenerationData()); mKillableMap = GetComponent <KillableMap>(); mKillableMap.SetupWithDungeon(mDungeon); mCollisionMap = GetComponent <CollisionMap>(); mCollisionMap.SetupWithSize(mDungeon.width, mDungeon.height); GenerateEnvironmentFromDungeon(mDungeon); PlaceAvatar(); // Provide some time after the avatar is generated for any of its setup (ie: quirk setup) // to impact dungeon generation yield return(null); // Special handling for the 'difficulty boost' effect DifficultyBoost db = GameObject.FindObjectOfType <DifficultyBoost>(); if (db != null) { db.ApplyQuirks(); yield return(null); } yield return(null); if (!IsPresetRoom()) { PlaceDeadEndInterests(); } PlaceTraps(); PlaceEnemies(); if (!IsPresetRoom()) { PlaceHearts(); PlaceExit(); QuirkSpecificSpawns(); } if (Game.instance.currentDungeonFloor == 5) { Game.instance.soundManager.PlayRandomMusicInCategory("BossMusic"); } else if (Game.instance.quirkRegistry.IsQuirkActive <GothQuirk>()) { Game.instance.soundManager.PlayRandomMusicInCategory("GothMusic"); } else if (Game.instance.quirkRegistry.IsQuirkActive <OldTimeyQuirk>()) { Game.instance.soundManager.PlayRandomMusicInCategory("OldTimey"); } else if (Game.instance.quirkRegistry.IsQuirkActive <Cowfolk>()) { Game.instance.soundManager.PlayRandomMusicInCategory("Cowboy"); } else { Game.instance.soundManager.PlayRandomMusicInCategory("DungeonMusic"); } Game.instance.playerData.MarkDirty(); yield break; }
private void GenerateEnvironmentFromDungeon(RandomDungeon dungeon) { DungeonBiomeData biomeData = Game.instance.currentDungeonData.biomeData; for (int x = 0; x < dungeon.width; ++x) { for (int y = 0; y < dungeon.height; ++y) { RandomDungeonTileData tileData = dungeon.Data(x, y); if (dungeon.TileType(x, y) >= 'A' && dungeon.TileType(x, y) <= 'Z') { HandleCheatTile(tileData, x, y, biomeData); } else if (dungeon.TileType(x, y) == RandomDungeonTileData.EMPTY_TILE) { mCollisionMap.MarkSpace(x, y, -1); } else if (dungeon.TileType(x, y) == RandomDungeonTileData.WALL_TILE) { // In the space level, we actually have requirements for what wall tiles // can be placed where; otherwise we get weird decoration clipping if (Game.instance.currentDungeonData.dungeonNum == 3) { bool hasForwardTile = (y + 1 < dungeon.height); char forwardTile = hasForwardTile ? dungeon.TileType(x, y + 1) : RandomDungeonTileData.EMPTY_TILE; if (forwardTile != RandomDungeonTileData.WALKABLE_TILE && forwardTile != RandomDungeonTileData.EXIT_TILE && forwardTile != RandomDungeonTileData.EMPTY_TILE) { int wall = Random.Range(0, 2); PlaceMapPrefab(biomeData.wallPrefabs[wall], x, y, WALKABLEMAP_STATIC_MARK); } else { PlaceMapPrefab(biomeData.wallPrefabs.Sample(), x, y, WALKABLEMAP_STATIC_MARK); } } else { PlaceMapPrefab(biomeData.wallPrefabs.Sample(), x, y, WALKABLEMAP_STATIC_MARK); } } else if (dungeon.TileType(x, y) == RandomDungeonTileData.WALKABLE_TILE || dungeon.TileType(x, y) == RandomDungeonTileData.EXIT_TILE || dungeon.TileType(x, y) == AVATAR_POSITION) { PlaceMapPrefab(biomeData.floorPrefabs.Sample(), x, y, -1, 0, true); } else if (dungeon.TileType(x, y) == SHOP_PEDESTAL) { PlaceMapPrefab(biomeData.floorPrefabs[0], x, y).GetComponent <RevealWhenAvatarIsClose>().allowScaleVariation = false;; PlaceMapPrefab(biomeData.shopPedestablPrefab, x, y, WALKABLEMAP_STATIC_MARK).GetComponent <RevealWhenAvatarIsClose>().allowScaleVariation = false; GameObject buyableItem = PlaceMapPrefab(RandomItem(), x, y); buyableItem.transform.localPosition += Vector3.up * 0.3f; GameObject activationPlate = PlaceMapPrefab("ActivationPlate", x, y + 1); PlaceSurroundingActivationPlates(x, y, null, null, null, buyableItem.GetComponent <Item>()); } else if (dungeon.TileType(x, y) == SHOP_KEEPER) { PlaceMapPrefab(biomeData.floorPrefabs[0], x, y); GameObject shopKeeper = PlaceMapPrefab("ShopKeep", x, y, WALKABLEMAP_USE_PREFAB_MARK, 0.5f); PlaceSurroundingActivationPlates(x, y, "shopkeep_talk", null, shopKeeper); if (Game.instance.isShopKeeperEnemy) { Game.instance.MakeShopKeeperEnemy(); } } else if (dungeon.TileType(x, y) == PRESET_ENEMY) { PlaceMapPrefab(biomeData.floorPrefabs[0], x, y); PlaceEnemy(CurrentDungeonFloorData(), new Vector2Int(x, y)); } if (tileData.chest == 2) { PlaceChest(new Vector2Int(x, y)); } else if (tileData.chest == 1) { bool generateShrine = (Random.Range(0, 100) < 50); if (generateShrine) { Debug.Log("A special room has spawned including a shrine."); PlaceShrine(new Vector2Int(x, y)); } else { Debug.Log("A special room has spawned including a chest."); PlaceChest(new Vector2Int(x, y)); } } } } }
public void SetupWithDungeon(RandomDungeon dungeon) { mMap = new Killable[dungeon.width, dungeon.height]; }