private void PrepareUI() { GameUIScript.Init(settings); GameUIScript.SetPlayersCount(settings.players.Length, settings.players.Count(p => p.type == PlayerType.AI)); var ui = GameUIScript.GetUI(); for (int i = 0; i < settings.players.Length; i++) { var p = settings.players[i]; var z = ui.GetPlayerZone(p); p.gridViewport = z.rect; if (p.allowGridAngle) { p.gridAngle = z.angle; } GameUIScript.SetScore(i, 0); GameUIScript.SetSpeed(i, settings.gridSettings.startLevel); if (objectives != null) { GameUIScript.SetObjective(p.index, 1, objectives); } } }
void Update() { if (isPaused == false && isOver == false) { timeElapsed += Time.deltaTime; } GameUIScript.SetTime(timeElapsed); // Update objectives if (objectives != null) { UpdateObjectives(); } }
/// <summary> /// Create players and related grid using game settings. /// </summary> private void CreatePlayersAndGrids() { foreach (var basePlayer in settings.players) { var p = basePlayer; var po = new GameObject(); PlayerScript player; if (p.type == PlayerType.Local) { player = po.AddComponent <PlayerScript>(); } else if (p.type == PlayerType.AI) { player = po.AddComponent <AIPlayerScript>(); } else { Log.Error("Unsupported player type " + p.type); return; } po.name = "Player " + p.name; po.transform.parent = transform; po.transform.position = Vector3.zero; player.player = p; if (p.power != PowerType.None) { player.power = Power.Create(p.power); player.power.OnPowerUsed += OnPowerUsed; } player.cursorPrefabs = cursorPrefabs; player.cam = GetCamera(player); player.grid = CreateGrid(player, player.cam); players.Add(player); // Init UI with player player.grid.ui = GameUIScript.SetPlayer(player, settings.players.Length); if (player.power != null) { GameUIScript.SetPowerCharge(p.index, 0, 0); player.grid.PowerCharge += 0.35f; // Start at n% > 0 } } }
private void UpdateObjectives() { foreach (var p in players) { if (p.grid.IsPaused) { continue; } // Give new stats, widget will check if it's relevant var currentStats = new ObjectiveStats(p, timeElapsed); for (int i = 1; i <= 4; i++) { GameUIScript.UpdateObjective(p, i, currentStats); } } var p1 = players[0]; // Stop here if not started if (p1.grid.IsStarted == false) { return; } //-------------------------------------------------------------------------------------------------------------- if (isOver == false) { for (int i = 0; i < players.Count; i++) { var pWinner = players[i]; var pStats = new ObjectiveStats(pWinner, timeElapsed); if (objectives.Succeed(pWinner, pStats)) { Log.Info("Versus with level ended!"); GameOverVersus(pWinner); break; } } } }
/// <summary> /// Define the "draw" zone /// </summary> private void SetViewport(Rect r, float angle) { gridCam.rect = r; gridCam.transform.rotation = Quaternion.Euler(0, 0, angle); //float preview = Mathf.Abs(settings.previewLines) - (settings.previewLines != 0 ? 0.5f : 0); // Display only a bit of the preview float preview = (settings.previewLines > 0 ? 0.25f : 0); // Center on screen gridCam.transform.position = new Vector3( transform.position.x + (settings.width / 2f), transform.position.y + (settings.height / 2f) + (-preview / 2f), gridCam.transform.position.z ); gridCam.orthographicSize = (settings.height + preview) / 2f; var gui = GameUIScript.GetUI(); transform.position += new Vector3(0f, gui.gridRelativePosition.y * gridCam.orthographicSize * 2f); transform.localScale = gui.gridScale; }
void Start() { var trigger = speedUpButton.GetComponent <EventTrigger>(); var entryDown = new EventTrigger.Entry(); entryDown.eventID = EventTriggerType.PointerDown; entryDown.callback.AddListener((data) => { speedUp = true; GameUIScript.GetSpeedButton(Player.player.index).SetSpeedActivated(true); }); trigger.triggers.Add(entryDown); var entryUp = new EventTrigger.Entry(); entryUp.eventID = EventTriggerType.PointerUp; entryUp.callback.AddListener((data) => { speedUp = false; GameUIScript.GetSpeedButton(Player.player.index).SetSpeedActivated(false); }); trigger.triggers.Add(entryUp); }
private void ComboDetected(List<Block> comboBlocks, int currentComboIndex, int totalCombosCount) { int blocksCount = comboBlocks.Count; if (blocksCount < 3) return; bypassFrozen = false; // Light columns for (int b = 0; b < blocksCount; b++) { int x = comboBlocks[b].x + 1; columnSprites[x].color = new Color(1f, 1f, 1f, 0.75f); } // Shake shake shake GridShakerScript.Shake(this, 0.15f, 0.05f); // Reset Game Over timer timeBeforeGameOverCurrent = timeBeforeGameOverMax; totalCombos++; // Update chains bool isChain = false; if (PonGameScript.instance == null || PonGameScript.instance.Settings.disableChains == false) { // -- A chain is combo where at least one block is falling and it is not the latest block moved bool blocksAreChainable = true; foreach (var b in comboBlocks) { blocksAreChainable &= b.Chainable; if (!blocksAreChainable) break; } // -- Also a chain is never the first combo isChain = ComboMultiplier >= 1 && blocksAreChainable; if (isChain) { chainCount++; totalChains++; Log.Info("CHAIN! chainCount=" + chainCount); } } if (currentComboIndex >= totalCombosCount - 1) { lastMove = new Grid.MoveResult(); } if (blocksCount == 4) { total4Combos++; } else if (blocksCount == 5) { total5Combos++; } else if (blocksCount > 5) { total6Combos++; } CheckForNextLevel(); // Update combo IncreaseMultiplier(isChain ? 2 : 1); // Compute score long points = GetScore(blocksCount, isChain); AddPoints(points); // Add some power AddPower(blocksCount); // Combo feedback Vector3 loc = BlockToWorld(comboBlocks[Mathf.CeilToInt(comboBlocks.Count / 2f)].position, Vector2.zero); var locs = comboBlocks.Select(b => BlockToWorld(b.position, Vector2.zero) + new Vector2(0.50f, 0.5f)) .ToArray(); OnCombo.Raise(this, new ComboData(blocksCount, isChain ? chainCount : comboMultiplier, isChain, loc, comboBlocks[0].Definition)); // Center loc += new Vector3(0.60f, 0.5f); GameUIScript.DisplayComboWidget(this, comboMultiplier, blocksCount, points, comboBlocks[0].Definition, loc, locs); if (isChain) { GameUIScript.DisplayChainWidget(this, chainCount, points, comboBlocks[0].Definition.color, loc); } }
private void OnMultiplierChange(GridScript grid, int m) { // Update UI GameUIScript.SetMultiplier(grid.player.index, m); }
private void OnLevelChanged(GridScript g, int l) { // Update UI GameUIScript.SetSpeed(g.player.index, l); }
private void OnPowerChargeChanged(GridScript g, PowerType power, float charge, int direction) { // Update UI GameUIScript.SetPowerCharge(g.player.index, charge, direction); }
private void OnScoreChanged(GridScript g, long score) { // Update UI GameUIScript.SetScore(g.player.index, score); }
void Awake() { Instance = this; }