You are on page 1of 5

using System.

Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fighter : MonoBehaviour
{
public enum PlayerType
{
HUMAN, HUMAN2, AI
};

public Animator _Anim;
private Rigidbody _Rb;
public string _FighterName;

public Fighter _Oponent;
public PlayerType _Player;
public FighterStates currentState = FighterStates.IDLE;

public static float _MaxHp = 100;
public float _Hp = _MaxHp;
public float _Speed = 1.0f;

void Start()
{
_Rb = GetComponent<Rigidbody>();
_Anim = GetComponent<Animator>();
}

public void UpdateHumanInput ()
{
//Horizontal Movement
if (Input.GetKey(KeyCode.A))
{
_Anim.SetBool("WALK", true);
}
else
{
_Anim.SetBool("WALK", false);
}
if (Input.GetKey(KeyCode.D))
{
_Anim.SetBool("WALK_BACK", true);
}
else
{
_Anim.SetBool("WALK_BACK", false);
}
//Vertical Movement
if (Input.GetKey (KeyCode.S))
{
_Anim.SetBool("DUCK", true);
}
else
{
_Anim.SetBool("DUCK", false);
}

if (Input.GetKeyDown(KeyCode.W))
{
_Anim.SetTrigger("JUMP");
}

//Attacks
if (Input.GetKeyDown(KeyCode.E))
{
_Anim.SetTrigger("PUNCH");
}
if (Input.GetKeyDown(KeyCode.F))
{
_Anim.SetTrigger("KICK");
}
if (Input.GetKeyDown(KeyCode.C))
{
_Anim.SetTrigger("HADOEKEN");
}

//Defend
if (Input.GetKey(KeyCode.LeftShift))
{
_Anim.SetBool("DEFEND", true);
}
else
{
_Anim.SetBool("DEFEND", false);
}
}

public void UpdateHuman2Input()
{
//Horizontal Movement
if (Input.GetKey(KeyCode.RightArrow))
{
_Anim.SetBool("WALK", true);
}
else
{
_Anim.SetBool("WALK", false);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
_Anim.SetBool("WALK_BACK", true);
}
else
{
_Anim.SetBool("WALK_BACK", false);
}

//Vertical Movement
if (Input.GetKey(KeyCode.DownArrow))
{
_Anim.SetBool("DUCK", true);
}
else
{
_Anim.SetBool("DUCK", false);
}

if (Input.GetKeyDown(KeyCode.UpArrow))
{
_Anim.SetTrigger("JUMP");
}

//Attacks
if (Input.GetKeyDown(KeyCode.RightControl))
{
_Anim.SetTrigger("PUNCH");
}
if (Input.GetKeyDown(KeyCode.RightShift))
{
_Anim.SetTrigger("KICK");
}
if (Input.GetKeyDown(KeyCode.RightAlt))
{
_Anim.SetTrigger("HADOEKEN");
}

//Defend
if (Input.GetKey(KeyCode.Keypad0))
{
_Anim.SetBool("DEFEND", true);
}
else
{
_Anim.SetBool("DEFEND", false);
}
}

void Update()
{
_Anim.SetFloat("health", HpPercent);

if (_Oponent != null)
{
_Anim.SetFloat("Oponent health", _Oponent.HpPercent);
}

else
{
_Anim.SetFloat("Oponent health", 1);
}

if (_Player == PlayerType.HUMAN)
{
UpdateHumanInput();
}

if (_Player == PlayerType.HUMAN2)
{
UpdateHuman2Input();
}
}

public virtual void hurt (float damage)
{
if (!invulnerable)
{
if (_Hp >= damage)
{
_Hp -= damage;
}
else
{
_Hp = 0;
}

if (_Hp > 0)
{
_Anim.SetTrigger("TAKE_HIT");
}

if (_Hp <= 0)
{
_Anim.SetTrigger("DEAD");
}
}
}

public bool invulnerable
{
get
{
return currentState == FighterStates.TAKE_HIT
||currentState == FighterStates.TAKE_HIT_DEFEND
|| currentState == FighterStates.DEFEND
|| currentState == FighterStates.DEAD;
}
}

public bool attacking
{
get
{
return currentState == FighterStates.ATTACK;
}
}

public float HpPercent
{
get
{
return _Hp / _MaxHp;
}
}

public Rigidbody body
{
get
{
return this._Rb;
}
}
}