// Update is called once per frame void Update() { if (!_reached) { Vector3 position = gameObject.transform.position; position += _movDir * Time.deltaTime * _speed; _speed += _accl; gameObject.transform.position = position; float scale = gameObject.transform.localScale.x; if (scale < _destScale) { scale += _scaleSpeed * Time.deltaTime; _scaleSpeed += _scaleAccl; gameObject.transform.localScale = new Vector3(scale, scale, 1); } if (scale > _destScale) { gameObject.transform.localScale = new Vector3(_destScale, _destScale, 1); } Vector3 errorness = _destMovePos - position; if (Vector3.Dot(errorness, _movDir) < 0 || errorness.magnitude < 5) { _reached = true; gameObject.transform.position = _destMovePos; gameObject.transform.parent.SendMessage("onMovingDone", this); SoundHub.instance().play("MoveEnd"); } } }
private IEnumerator eliminateAdjacentPawns() { _gameState = GameState.JudgingElimination; for (int i = 0; i < _pawnListToEliminate.Count; ++i) { AdjacentPawnList pawnList = _pawnListToEliminate[i]; concludeEliminateStats(pawnList); int addedScore = calculateScore(pawnList.finalList, _combo); Pawn firstPawn = pawnList.finalList[0]; modifyScore(addedScore, firstPawn.type); checkAchieve(firstPawn.neighborOppositeCount, firstPawn.type); int eliminateSoundLevel = firstPawn.neighborOppositeCount / 2 + 1; SoundHub.instance().play("Eliminate" + eliminateSoundLevel); foreach (Pawn pawn in pawnList.finalList) { pawn.destroy(true, "eliminate"); } pawnList.finalList.Clear(); yield return new WaitForSeconds(0.3f); } _pawnListToEliminate.Clear(); clearGridFlags(); updateScenePawnState(); }
override public void onShow(bool show) { if (show) { SoundHub.instance().play("GameOver"); } }
private void putSelectingPawn(Vector2 gridIndice) { // move selecting pawn to here if (_selectingPawn != null) { int preGridIndex = _selectingPawn.gridIndex; _selectingPawn.gridPos = gridIndice; _selectingPawn.selected = false; _selectingPawn.dragging = false; SoundHub.instance().play("MoveEnd"); _lastPutPawns[(int)_turn].Clear(); _lastPutPawns[(int)_turn].Add(_selectingPawn); _lastPutPawns[(int)_turn].Add(preGridIndex); updateScenePawnState(true); _selectingPawn = null; if (_turn == Side.Self) { if (_lastUsedBackwardsLock > 0) { --_lastUsedBackwardsLock; } } stepEnd(); startWaitingOppoSide(_gameMode == GameMode.AI ? 0.3f : 0.0f); } }
public override void onShow(bool show) { if (show) { SoundHub.instance().play("NewAchieve"); } }
public void onToggleMusic() { SoundHub.instance().play("ButtonClick"); Toggle toggle = gameObject.transform.Find("ContentLayer/SettingLayer/ToggleMusic").GetComponent <Toggle>(); SoundHub.instance().muteMusic(!toggle.isOn); PlayerPrefs.SetInt("music", toggle.isOn ? 1 : 0); PlayerPrefs.Save(); }
private void onLevelUp(bool noReward = false) { SoundHub.instance().play("LevelUp"); FloatTip.instance.addTip("Level up!"); if (_newPawnCount < MaxNextPawnCount) { ++_newPawnCount; } if (!noReward) { modifyTrashChance(1); modifyBackwardsChance(1); } invalidUI(); }
public void moveTo(Vector3 destPos, float speed) { _startPos = gameObject.transform.position; _movDir = destPos - gameObject.transform.position; _movDir.Normalize(); _destMovePos = destPos; _speed = speed; _reached = false; float estimateTime = Vector3.Distance(_destMovePos, _startPos) / speed; float curScale = gameObject.transform.localScale.x; _scaleSpeed = (_destScale - curScale) / estimateTime; _scaleAccl = _scaleSpeed * _accl / _speed; SoundHub.instance().play("MoveBegin"); }
private void putPawnToTrash() { if (_gameState != GameState.SelectingPawnToTrash || _selectingPawn == null || _trashChance <= 0) { _gameState = GameState.WaitingPutPawn; return; } modifyTrashChance(-1); SoundHub.instance().play("Trash"); invalidUI(); _selectingPawn.selected = false; _selectingPawn.destroy(true, "eliminate"); _selectingPawn = null; _trashButton.animator.ResetTrigger("EnterTrash"); _trashButton.animator.SetTrigger("Normal"); updateScenePawnState(true); }
// revert AI and self last pawn and reput my pawn public void onBtnBackwards() { if (_turn != Side.Self || _lastUsedBackwardsLock > 0 || _gameMode != GameMode.AI || _backwardsChance <= 0 || _gameState != GameState.WaitingPutPawn) { return; } bool use = false; int side = (int)Side.Self; Pawn lastSelfMovePawn = null; if (_lastPutPawns[side].Count > 0) { lastSelfMovePawn = (Pawn)_lastPutPawns[side][0]; lastSelfMovePawn.gridIndex = (int)_lastPutPawns[side][1]; use = true; _lastPutPawns[side].Clear(); } side = (int)Side.Opposite; if (_lastPutPawns[side].Count > 0) { for (int i = 0; i < _lastPutPawns[side].Count; ) { Pawn pawn = (Pawn)_lastPutPawns[side][i]; if (pawn == lastSelfMovePawn) { ++i; continue; } pawn.destroy(true, "eliminate"); } _lastPutPawns[side].Clear(); use = true; } if (use) { SoundHub.instance().play("Backwards"); modifyBackwardsChance(-1); _lastUsedBackwardsLock = 2; } }
void Update() { if (_uiInvalid) { updateUI(_initialUpdateUI); _uiInvalid = false; _initialUpdateUI = false; } if (_paused) { return; } if (_gameState == GameState.WaitingPutPawn) { bool waitInput = false; if (_turn == Side.Opposite) { if (_waitingForOppoSide) { return; } stepBegin(); if (_gameMode == GameMode.AI) { performAIMove(); } else if (_gameMode == GameMode.Self){ waitInput = true; } } else { waitInput = true; } if (waitInput) { if (_pawns.Count == 0) { stepEnd(); return; } else if (_pawns.Count >= _grids.Length) { gameOver(); return; } if (Input.GetMouseButtonDown(0)) { Vector2 gridIndice; if (_chessBoard.getGridIndexByScreenPosition(Input.mousePosition, out gridIndice)) { Pawn pawn = getPawnAtPos((int)gridIndice.x, (int)gridIndice.y); Debug.Log("select grid pos " + gridIndice + ", pawn" + pawn); if (pawn != null) { if (_selectingPawn == pawn) { if (!_selectingPawn.dragging) { _selectingPawn.selected = false; _selectingPawn = null; } } else { if (_selectingPawn != null) { _selectingPawn.selected = false; _selectingPawn.dragging = true; } _selectingPawn = pawn; _selectingPawn.selected = true; _selectingPawn.dragging = true; _selectTimeStamp = Time.time; SoundHub.instance().play("MoveBegin"); } } else { putSelectingPawn(gridIndice); } } else { if (_selectingPawn != null) { _selectingPawn.selected = false; _selectingPawn.dragging = false; _selectingPawn = null; } } } else if (Input.GetMouseButton(0)) { if (Time.time - _selectTimeStamp < 0.1) { return; } if (_selectingPawn != null && _selectingPawn.dragging) { Vector3 posInBoard = _chessBoard.screenPosToPosInBoard(Input.mousePosition); posInBoard.z = 0; _selectingPawn.setLocalPosition(posInBoard); } } else if (Input.GetMouseButtonUp(0)) { if (_selectingPawn != null && _selectingPawn.dragging) { Vector2 gridIndice; if (_chessBoard.getGridIndexByScreenPosition(Input.mousePosition, out gridIndice)) { Pawn pawn = getPawnAtPos((int)gridIndice.x, (int)gridIndice.y); if (pawn != null) { cancelDrag(); } else { putSelectingPawn(gridIndice); } } else { cancelDrag(); } } } } } else if (_gameState == GameState.SelectingPawnToTrash) { if (Input.GetMouseButtonDown(0)) { Vector2 gridIndice; if (_chessBoard.getGridIndexByScreenPosition(Input.mousePosition, out gridIndice)) { Pawn pawn = getPawnAtPos((int)gridIndice.x, (int)gridIndice.y); if (pawn != null) { if (_selectingPawn == pawn) { if (!_selectingPawn.dragging) { _selectingPawn.selected = false; _selectingPawn = null; } } else { if (_selectingPawn != null) { _selectingPawn.selected = false; _selectingPawn.dragging = true; } _selectingPawn = pawn; _selectingPawn.selected = true; _selectingPawn.dragging = true; _selectTimeStamp = Time.time; SoundHub.instance().play("MoveBegin"); } } } else if (_selectingPawn != null) { putPawnToTrash(); } } else if (Input.GetMouseButton(0)) { if (Time.time - _selectTimeStamp < 0.1) { return; } if (_selectingPawn != null && _selectingPawn.dragging) { Vector3 posInBoard = _chessBoard.screenPosToPosInBoard(Input.mousePosition); posInBoard.z = 0; _selectingPawn.setLocalPosition(posInBoard); } } else if (Input.GetMouseButtonUp(0)) { if (_selectingPawn != null && _selectingPawn.dragging) { Vector2 gridIndice; if (_chessBoard.getGridIndexByScreenPosition(Input.mousePosition, out gridIndice)) { cancelDrag(); } else { putPawnToTrash(); } } } } else if (_gameState == GameState.GameOver) { } }