Skip to content
Snippets Groups Projects
PlayerController.cs 2.42 KiB
Newer Older
using System.Collections;
using UnityEngine;

public class PlayerController : Controller
william's avatar
william committed
	public static event System.Action<float> staminaUse;
william's avatar
william committed
	// Use this for initialization
	void Start()
	{
		inputs = new Inputs ();
		//fazer dinamico
		setup();
		canMove = true;
		canSkill = true;
		myTurn = true;
		currentHand = 1;        
		changeTurn();
		currentStamina = maxStamina;
william's avatar
william committed
		foreach (Skills s in GetComponents<Skills>())
		{
			s.skillCost += updateStamina;
		}
	}
william's avatar
william committed
	private void setup()
	{
		controlType = new KeyBoardControl ();
		animatorController = GetComponent<Animator>();
	}
william's avatar
william committed
	private void updateStamina(float cost)
	{
		currentStamina -= cost;
		if (staminaUse != null)
		{
			staminaUse(currentStamina);
		}
	}
william's avatar
william committed
	private void Update()
	{
		inputs.behindBack = Input.GetAxisRaw(controlType.getBehindBackInput());
		inputs.crossOver = Input.GetAxisRaw(controlType.getCrossOverInput());
		inputs.stepBack = Input.GetAxisRaw(controlType.getStepBackInput());
		inputs.horizontalMovement = Input.GetAxisRaw(controlType.getHorizontalInput());
		inputs.verticalMovement = Input.GetAxisRaw(controlType.getVerticalInput());
		inputs.steal = Input.GetAxisRaw(controlType.getStealInput());
		inputs.block = Input.GetAxisRaw(controlType.getBlockInput());
	}
william's avatar
william committed
	public override void changeTurn()
	{
		if (myTurn)
		{
			foreach (AtkSkills script in GetComponents<AtkSkills>())
			{
				script.enabled = true;
			}
			GetComponent<MovementScript>().enabled = true;
			GetComponent<BlockScript>().enabled = false;
			GetComponentInChildren<ForceBarController>().enabled = true;
			disableBallCollider();
			animatorController.SetTrigger("AtkTurn");
			myTurn = false;
Will Lucena's avatar
Will Lucena committed
            threePoint();
william's avatar
william committed
		} else
		{
			foreach (DefSkills script in GetComponents<DefSkills>())
			{
				script.enabled = true;
			}
			GetComponent<MovementScript>().enabled = true;
			enableBallCollider();
			animatorController.SetTrigger("DefTurn");
			myTurn = true;
Will Lucena's avatar
Will Lucena committed
            twoPoint();
        }
william's avatar
william committed
		//do something
	}
william's avatar
william committed
	public virtual void OnDisable()
	{
		StopAllCoroutines();
		disableSkills();
		ForceBarController fbc = FindObjectOfType<ForceBarController>();
		if (fbc != null)
		{
			fbc.enabled = false;
		}
		animatorController.SetTrigger("Idle");
	}
william's avatar
william committed
	public void moveToPosition(Transform atkPosition, Transform defPosition)
	{
		if (myTurn)
		{
			GetComponent<MovementScript>().moveToPosition(atkPosition);
		} else
		{
			GetComponent<MovementScript>().moveToPosition(defPosition);
		}
	}