using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Assets.Scripts.Constants;
using Assets.Scripts.Managers;

public class GameCamera : MonoBehaviour {

	#region variables
	private float _rotationAmount = 180f;
	private float _animSpeed = 5f;

	private Quaternion _targetRotation;
	private GameObject _moveController;
	private Transform _activePlayer;
	#endregion


	#region events
	void Awake () {

		_targetRotation = transform.rotation;
		_moveController = GameObject.FindGameObjectWithTag ("MoveController");
        WallsManager.SetFrontAngle(GameManager.CurrentGameTime);
    }

	void Update () {
		if (Input.GetKeyDown (KeyCode.Space) && PlayerMovement.ControlsEnabled && PlayerMovement.ShiftEnabled) {
			_targetRotation = Quaternion.Euler (_targetRotation.eulerAngles + new Vector3 (0, _rotationAmount, 0));
			_moveController.transform.RotateAround (Vector3.zero, Vector3.up, _rotationAmount);
			_rotationAmount = -_rotationAmount;
            GameManager.CurrentAngle = WallsManager.SwitchCameraAngle(GameManager.CurrentAngle, GameManager.CurrentGameTime);
		}

		transform.rotation = Quaternion.Lerp (transform.rotation, _targetRotation, Time.deltaTime * _animSpeed);        
	}


	void FixedUpdate () {

		transform.position = Vector3.Lerp (transform.position, _activePlayer.position, Time.deltaTime * _animSpeed);
		
	}
	#endregion


	#region methods
	public void SetActivePlayer (Transform t) {

		_activePlayer = t;
		
	}
	#endregion

}
