private void AddBackgroundSprites(SerialisableTile serialisableTile, InGameMazeTile tile) { InGameMazeTileBackgroundPlacer tileBackgroundPlacer = new InGameMazeTileBackgroundPlacer(tile); foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds) { Type type = Type.GetType(serialisableTileBackground.BackgroundType); if (type.Equals(typeof(SerialisableTilePathBackground))) { SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlacePath(new MazeLevelDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseGround))) { SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlaceGround(new MazeLevelDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseWater))) { tileBackgroundPlacer.PlaceBackground <MazeTileBaseWater>(); } else { Logger.Error($"Unknown TileBackgroundId {serialisableTileBackground.TileBackgroundId}"); } } }
// Previously tried solution with collision detection on all separate clients for all players(instead of events). // But the result was that some tile marking got skipped if the clients skipped walking over them because of a bad connection. // This way we can be sure all tiles are getting marked. public void SetTileMarker(InGameMazeTile tile, PlayerCharacter player) { if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer || GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer) { player.LastTile = tile; MazeTilePath mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { return; } PlayerMark playerMark = new PlayerMark(mazeTilePath.ConnectionScore); HandlePlayerMarkerSprite(tile, player.PlayerNumber, playerMark); HandlePlayerTileMarkerEnds(tile); HandleNumberOfUnmarkedTiles(); tile.ResetPlayerMarkEndsRenderer(); tile.TriggerTransformations(); } else { PlayerMarksTileEvent playerMarksTileEvent = new PlayerMarksTileEvent(); playerMarksTileEvent.SendPlayerMarksTileEvent(tile.GridLocation, player); } }
public override void Start() { base.Start(); PlayerExitsEvent += OnPlayerExit; PlayerCaughtEvent += OnPlayerCaught; if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer || GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer || PhotonView.IsMine) { _selectionIndicatorGO = Instantiate(_selectionIndicatorPrefab, SceneObjectManager.Instance.CharactersGO); SelectionIndicator selectionIndicator = _selectionIndicatorGO.GetComponent <SelectionIndicator>(); selectionIndicator.Setup(transform, this); SceneObjectManager.Instance.SceneObjects.Add(_selectionIndicatorGO); } //transform the player's starting tile and surrounding tiles InGameMazeTile currentTile = GameManager.Instance.CurrentGameLevel.TilesByLocation[StartingPosition] as InGameMazeTile; if (currentTile == null) { Logger.Error($"Current tile at {StartingPosition.X},{StartingPosition.Y} is null"); } currentTile.TriggerTransformations(); SetCurrentGridLocation(currentTile.GridLocation); MazeLevelGameplayManager.Instance.SetTileMarker(currentTile, this); }
private void InitialiseTileAttributes() { for (int i = 0; i < Level.Tiles.Count; i++) { InGameMazeTile tile = Level.Tiles[i] as InGameMazeTile; tile.InitialiseTileAttributes(); } }
public void EnemyCollisionWithMusicInstrumentCase(InGameMazeTile tile, EnemyCharacter enemy, MusicInstrumentCase musicInstrumentCase) { if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer || GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer) { musicInstrumentCase.EnemyCollisinOnTile(enemy); } else // network multiplayer { EnemyCollidesWithMusicInstrumentCaseEvent enemyCollidesWithMusicInstrumentCaseEvent = new EnemyCollidesWithMusicInstrumentCaseEvent(); enemyCollidesWithMusicInstrumentCaseEvent.SendEnemyCollidesWithMusicInstrumentCaseEvent(tile.GridLocation, enemy); } }
public void PlayerCollisionWithMusicInstrumentCase(InGameMazeTile tile, MazePlayerCharacter player, MusicInstrumentCase musicInstrumentCase) { if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer || GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer) { musicInstrumentCase.PlayerCollisionOnTile(player); } else // network multiplayer { PlayerCollidesWithMusicInstrumentCaseEvent playerCollidesWithMusicInstrumentCaseEvent = new PlayerCollidesWithMusicInstrumentCaseEvent(); playerCollidesWithMusicInstrumentCaseEvent.SendPlayerCollidesWithMusicInstrumentCaseEvent(tile.GridLocation, player); } }
private void AddCornerFillers(SerialisableTile serialisableTile, InGameMazeTile tile) { InGameMazeTileBackgroundPlacer tileBackgroundPlacer = new InGameMazeTileBackgroundPlacer(tile); // corner filler is also an IBackground foreach (SerialisableTileCornerFiller serialisableTileCornerFiller in serialisableTile.TileCornerFillers) { if (Enum.TryParse(serialisableTileCornerFiller.TileCorner, out TileCorner tileCorner)) { tileBackgroundPlacer.PlaceCornerFiler(tileCorner); } else { Logger.Error($"Could not parse the TileCorner value{serialisableTileCornerFiller.TileCorner}"); } } }
private void ConnectBridgeEdgesToTheirBridgePieces() { for (int i = 0; i < Tiles.Count; i++) { InGameMazeTile tile = Tiles[i] as InGameMazeTile; List <BridgeEdge> bridgeEdges = tile.GetBridgeEdges(); for (int j = 0; j < bridgeEdges.Count; j++) { Direction edgeSide = bridgeEdges[j].EdgeSide; InGameMazeTile neighbourTile = null; switch (edgeSide) { case Direction.Up: neighbourTile = tile.Neighbours[ObjectDirection.Up] as InGameMazeTile; break; case Direction.Right: neighbourTile = tile.Neighbours[ObjectDirection.Right] as InGameMazeTile; break; case Direction.Down: neighbourTile = tile.Neighbours[ObjectDirection.Down] as InGameMazeTile; break; case Direction.Left: neighbourTile = tile.Neighbours[ObjectDirection.Left] as InGameMazeTile; break; default: break; } if (neighbourTile) { BridgePiece bridgePiece = neighbourTile.TryGetBridgePiece(); if (bridgePiece == null) { Logger.Error($"Expected but could not find bridge piece at {neighbourTile.GridLocation.X}, {neighbourTile.GridLocation.Y}."); return; } bridgeEdges[j].WithBridgePieceConnection(bridgePiece); } } } }
private void CountTileMarkerScores() { Dictionary <PlayerNumber, int> tempPlayerScores = new Dictionary <PlayerNumber, int>(); List <InGameMazeTile> markedTiles = new List <InGameMazeTile>(); for (int i = 0; i < MazeLevelGameplayManager.Instance.Level.Tiles.Count; i++) { InGameMazeTile tile = MazeLevelGameplayManager.Instance.Level.Tiles[i] as InGameMazeTile; if (tile.PlayerMark != null) { markedTiles.Add(tile); } } int playerMarkScorePlayer1 = 0; int playerMarkScorePlayer2 = 0; for (int i = 0; i < markedTiles.Count; i++) { PlayerMark playerMark = markedTiles[i].PlayerMark; if (playerMark.Owner == PlayerMarkOwner.Player1) { playerMarkScorePlayer1 += MarkedTileValue; } else if (playerMark.Owner == PlayerMarkOwner.Player2) { playerMarkScorePlayer2 += MarkedTileValue; } } tempPlayerScores.Add(PlayerNumber.Player1, playerMarkScorePlayer1); if (PlayerMazeScores.ContainsKey(PlayerNumber.Player2)) { tempPlayerScores.Add(PlayerNumber.Player2, playerMarkScorePlayer2); } foreach (KeyValuePair <PlayerNumber, int> item in tempPlayerScores) { PlayerMazeScore p = PlayerMazeScores[item.Key]; p.TileMarkScore = item.Value; PlayerMazeScores[item.Key] = p; Logger.Log(Logger.Score, $"Tile marker scores: {item.Key.ToString()} has {PlayerMazeScores[item.Key].TileMarkScore} points."); } }
// Once the tile is marked, trigger the transformation of all tiles set up for this tile in the TilesToTransform list public void TriggerTransformations() { if (TransformationState == TransformationState.Bleak) { TriggerTransformationOnSelf(); } for (int i = 0; i < _tilesToTransform.Count; i++) { InGameMazeTile tileToTransform = _tilesToTransform[i]; if (tileToTransform.TransformationState == TransformationState.Colourful) { continue; } tileToTransform.TriggerTransformationOnSelf(); } }
public override void BuildTiles(MazeLevelData mazeLevelData) { Dictionary <InGameMazeTile, List <SerialisableGridLocation> > TileTransformationGridLocationByTile = new Dictionary <InGameMazeTile, List <SerialisableGridLocation> >(); for (int i = 0; i < mazeLevelData.Tiles.Count; i++) { SerialisableTile serialisableTile = mazeLevelData.Tiles[i]; GameObject tileGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.InGameTilePrefab, _mazeContainer.transform); InGameMazeTile tile = tileGO.GetComponent <InGameMazeTile>(); tile.SetGridLocation(serialisableTile.GridLocation.X, serialisableTile.GridLocation.Y); tile.SetId(serialisableTile.Id); tileGO.name = "Tile" + tile.GridLocation.X + ", " + tile.GridLocation.Y; tileGO.transform.position = GridLocation.GridToVector(tile.GridLocation); Tiles.Add(tile); AddBackgroundSprites(serialisableTile, tile); AddTileAttributes(serialisableTile, tile); AddCornerFillers(serialisableTile, tile); AddTileAreas(serialisableTile, tile); TilesByLocation.Add(tile.GridLocation, tile); GridLocation furthestBounds = LevelBounds; if (tile.GridLocation.X > furthestBounds.X) { _levelBounds.X = tile.GridLocation.X; } if (tile.GridLocation.Y > furthestBounds.Y) { _levelBounds.Y = tile.GridLocation.Y; } TileTransformationGridLocationByTile.Add(tile, serialisableTile.TilesToTransform); } foreach (KeyValuePair <InGameMazeTile, List <SerialisableGridLocation> > item in TileTransformationGridLocationByTile) { List <InGameMazeTile> tilesToTransform = new List <InGameMazeTile>(); for (int i = 0; i < item.Value.Count; i++) { for (int j = 0; j < Tiles.Count; j++) { InGameMazeTile tile = Tiles[j] as InGameMazeTile; if (item.Value[i].X == tile.GridLocation.X && item.Value[i].Y == tile.GridLocation.Y) { tilesToTransform.Add(tile); break; } } } item.Key.AddTilesToTransform(tilesToTransform); } for (int k = 0; k < Tiles.Count; k++) { InGameMazeTile tile = Tiles[k] as InGameMazeTile; tile.AddNeighbours(this); } ConnectBridgeEdgesToTheirBridgePieces(); }
private void AddTileAttributes(SerialisableTile serialisableTile, InGameMazeTile tile) { InGameMazeTileAttributePlacer tileAttributePlacer = new InGameMazeTileAttributePlacer(tile); foreach (SerialisableTileAttribute serialisableTileAttribute in serialisableTile.TileAttributes) { Type type = Type.GetType(serialisableTileAttribute.AttributeType); if (type.Equals(typeof(SerialisableTileObstacleAttribute))) { SerialisableTileObstacleAttribute serialisableTileObstacleAttribute = (SerialisableTileObstacleAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); tileAttributePlacer.PlaceTileObstacle(ObstacleType.Bush, new TileConnectionScoreInfo(serialisableTileObstacleAttribute.ConnectionScore, serialisableTileObstacleAttribute.SpriteNumber)); } else if (type.Equals(typeof(SerialisablePlayerExitAttribute))) { SerialisablePlayerExitAttribute serialisablePlayerExitAttribute = (SerialisablePlayerExitAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); tileAttributePlacer.PlacePlayerExit(ObstacleType.Bush, new TileConnectionScoreInfo(serialisablePlayerExitAttribute.ConnectionScore, serialisablePlayerExitAttribute.SpriteNumber)); } else if (type.Equals(typeof(SerialisablePlayerSpawnpointAttribute))) { tileAttributePlacer.PlacePlayerSpawnpoint(); } else if (type.Equals(typeof(SerialisablePlayerOnlyAttribute))) { tileAttributePlacer.PlacePlayerOnlyAttribute(PlayerOnlyType.Bush); } else if (type.Equals(typeof(SerialisableEnemySpawnpointAttribute))) { SerialisableEnemySpawnpointAttribute serialisableEnemySpawnpointAttribute = (SerialisableEnemySpawnpointAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); tileAttributePlacer.PlaceEnemySpawnpoint(serialisableEnemySpawnpointAttribute.TileAreaIds, TileAreas); } else if (type.Equals(typeof(SerialisableBridgePieceAttribute))) { SerialisableBridgePieceAttribute serialisableBridgePieceAttribute = (SerialisableBridgePieceAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); if (Enum.TryParse(serialisableBridgePieceAttribute.BridgePieceDirection, out BridgePieceDirection bridgePieceDirection)) { tileAttributePlacer.PlaceBridgePiece(BridgeType.Wooden, bridgePieceDirection); } else { Logger.Error($"Could not parse the BridgePieceDirection value{serialisableBridgePieceAttribute.BridgePieceDirection}"); } } else if (type.Equals(typeof(SerialisableBridgeEdgeAttribute))) { SerialisableBridgeEdgeAttribute serialisableBridgeEdgeAttribute = (SerialisableBridgeEdgeAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); if (Enum.TryParse(serialisableBridgeEdgeAttribute.BridgeEdgeSide, out Direction bridgeEdgeSide)) { tileAttributePlacer.PlaceBridgeEdge(BridgeType.Wooden, bridgeEdgeSide); } else { Logger.Error($"Could not parse the BridgeEdgeSide value{serialisableBridgeEdgeAttribute.BridgeEdgeSide}"); } } else if (type.Equals(typeof(SerialisableMusicInstrumentCaseAttribute))) { tileAttributePlacer.PlaceMusicInstrumentCase(); } else { Logger.Error($"Unknown tile attribute of type {type}"); } } }
public void OnEvent(EventData photonEvent) { byte eventCode = photonEvent.Code; if (eventCode == PlayerMarksTileEvent.PlayerMarksTileEventCode) { object[] data = (object[])photonEvent.CustomData; GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]); PlayerNumber playerNumber = (PlayerNumber)data[2]; InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile; MazeTilePath mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { return; } PlayerMark playerMark = new PlayerMark(mazeTilePath.ConnectionScore); HandlePlayerMarkerSprite(tile, playerNumber, playerMark); HandlePlayerTileMarkerEnds(tile); HandleNumberOfUnmarkedTiles(); tile.ResetPlayerMarkEndsRenderer(); tile.TriggerTransformations(); } else if (eventCode == LoadNextMazeLevelEvent.LoadNextMazeLevelEventCode) { object[] data = (object[])photonEvent.CustomData; string pickedLevel = (string)data[0]; MazeLevelData mazeLevelData = MazeLevelLoader.LoadMazeLevelData(pickedLevel); if (mazeLevelData == null) { Logger.Error($"Could not load maze level data for the randomly picked maze level {pickedLevel}"); } PersistentGameManager.SetCurrentSceneName(pickedLevel); IEnumerator loadLevelCoroutine = LoadOverworldCoroutine("Overworld"); StartCoroutine(loadLevelCoroutine); } else if (eventCode == LoadOverworldEvent.LoadOverworldEventCode) { object[] data = (object[])photonEvent.CustomData; string overworldName = (string)data[0]; PersistentGameManager.SetLastMazeLevelName(PersistentGameManager.CurrentSceneName); PersistentGameManager.SetCurrentSceneName(PersistentGameManager.OverworldName); IEnumerator loadLevelCoroutine = LoadOverworldCoroutine("Overworld"); StartCoroutine(loadLevelCoroutine); } else if (eventCode == PlayerCollidesWithMusicInstrumentCaseEvent.PlayerCollidesWithMusicInstrumentCaseEventCode) { object[] data = (object[])photonEvent.CustomData; GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]); PlayerNumber playerNumber = (PlayerNumber)data[2]; InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile; MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase); if (musicInstrumentCase == null) { Logger.Error("Could not find musicInstrumentCase"); } MazePlayerCharacter player = GameManager.Instance.CharacterManager.GetPlayers <MazePlayerCharacter>()[playerNumber]; musicInstrumentCase.PlayerCollisionOnTile(player); } else if (eventCode == EnemyCollidesWithMusicInstrumentCaseEvent.EnemyCollidesWithMusicInstrumentCaseEventCode) { object[] data = (object[])photonEvent.CustomData; GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]); int enemyId = (int)data[2]; InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile; MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase); if (musicInstrumentCase == null) { Logger.Error("Could not find musicInstrumentCase"); } MazeCharacterManager characterManager = GameManager.Instance.CharacterManager as MazeCharacterManager; EnemyCharacter enemyCharacter = characterManager.Enemies.FirstOrDefault(enemy => enemy.PhotonView.ViewID == enemyId); if (enemyCharacter == null) { Logger.Error("Could not find enemy character"); } musicInstrumentCase.EnemyCollisinOnTile(enemyCharacter); } }