/// <summary> /// Kills the player and notifies the GameManager. /// </summary> private void KillPacman() { _currentDir = TerrainManager.Direction.Right; RotatePacman(); _animator.SetTrigger("Die"); GameManager.Instance.KillPlayer(); }
/// <summary> /// Updates the pacman positon. /// If we have no direction (ak no key pressed), just keep going the same as before. /// Otherwise check if we can use the new direction, and move. Triggers the event. /// isJump represents the "teleporting" spots on the sides of the terrain. /// </summary> private void UpdateTarget() { bool isJump; if (_dir.Count <= 0) { _target = TerrainManager.Instance.GetNextAvailableNode(x, y, _currentDir, out x, out y, out isJump); PositionChanged?.Invoke(this, new Vector2(x, y)); } else { var currX = x; var currY = y; var newTarget = TerrainManager.Instance.GetNextAvailableNode(x, y, _dir.Peek(), out x, out y, out isJump); if (currX == x && currY == y) { newTarget = TerrainManager.Instance.GetNextAvailableNode(x, y, _currentDir, out x, out y, out isJump); PositionChanged?.Invoke(this, new Vector2(currX, currY)); } else { _currentDir = _dir.Dequeue(); } _target = newTarget; } if (isJump) { transform.position = _target; } RotatePacman(); }
/// <summary> /// If we already queued a direction, remove it so we only remember the last one. /// Otherwise, add it. /// </summary> /// <param name="direction"></param> public void AddDirection(TerrainManager.Direction direction) { if (_dir.Count > 0) { _dir.Dequeue(); } _dir.Enqueue(direction); }