protected override void OnUpdate() { if (boardModel == null || gameStateModel.State != Match3State.MatchesFall) { return; } for (int x = 0; x < boardModel.BoardWidth; x++) { if (boardModel.HasEntityAt(new int2(x, boardModel.BoardHeight - 1)) == false) { var levelConfig = gameStateModel.GetCurrentLevelConfig(); var boardPosition = new int2(x, boardModel.BoardHeight); var spawnPosition = BoardCalculator.ConvertBoardPositionToTransformPosition(boardPosition); if (HasGemInProximityInColumn(x, spawnPosition)) { continue; } var entity = EntitiesHelper.CreateGem(EntitiesHelper.GetRandomColor(levelConfig.availableColors), BoardCalculator.ConvertBoardPositionToTransformPosition(boardPosition), boardPosition); signalBus.Fire(new Match3Signals.GemCreatedSignal(entity, BoardCalculator.ConvertBoardPositionToTransformPosition(boardPosition))); EntityManager.AddComponent <IsFallingComponent>(entity); } } }
private void CreateGems(LevelConfig levelConfig) { for (int x = 0; x < levelConfig.Width; x++) { for (int y = 0; y < levelConfig.Height; y++) { var gemColor = EntitiesHelper.GetRandomColor(levelConfig.availableColors); var boardPosition = new int2(x, y); var position = BoardCalculator.ConvertBoardPositionToTransformPosition(boardPosition); var gemEntity = EntitiesHelper.CreateGem(gemColor, position, boardPosition); signalBus.Fire(new Match3Signals.GemCreatedSignal(gemEntity, position)); boardModel.SetEntityAt(x, y, gemEntity); } } }