refactor: cleaning movement code
moved skills and potions to skill handler
This commit is contained in:
@@ -31,27 +31,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(KeyCode.Space) && !playerSkillHandler.IsOnCooldown(PlayerSkillTree.Skills.Dash))
|
|
||||||
{
|
|
||||||
/* Get the input for horizontal and vertical movement */
|
|
||||||
float moveX = Input.GetAxisRaw("Horizontal");
|
|
||||||
float moveZ = Input.GetAxisRaw("Vertical");
|
|
||||||
|
|
||||||
move = new Vector3(moveX, 0, moveZ).normalized;
|
|
||||||
StartCoroutine(playerSkillHandler.DashCoroutine(controller, move));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.L))
|
|
||||||
{
|
|
||||||
if(PlayerSkills.TryUsePotion(PotionHandler.PotionType.HealthBig))
|
|
||||||
{
|
|
||||||
Debug.Log("Potion used!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Log("Potion not available!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
|
|||||||
@@ -13,17 +13,51 @@ public class PlayerSkillHandler: MonoBehaviour
|
|||||||
|
|
||||||
private Dictionary<PlayerSkillTree.Skills, float> cooldowns;
|
private Dictionary<PlayerSkillTree.Skills, float> cooldowns;
|
||||||
private Dictionary<PlayerSkillTree.Skills, float> cooldownsActivated;
|
private Dictionary<PlayerSkillTree.Skills, float> cooldownsActivated;
|
||||||
|
private PlayerSkillTree playerSkillTree;
|
||||||
|
|
||||||
|
private CharacterController controller;
|
||||||
|
|
||||||
public bool IsDashing() { return isDashing; }
|
public bool IsDashing() { return isDashing; }
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
|
|
||||||
cooldowns = new Dictionary<PlayerSkillTree.Skills, float>();
|
cooldowns = new Dictionary<PlayerSkillTree.Skills, float>();
|
||||||
cooldownsActivated = new Dictionary<PlayerSkillTree.Skills, float>();
|
cooldownsActivated = new Dictionary<PlayerSkillTree.Skills, float>();
|
||||||
|
controller = GetComponent<CharacterController>();
|
||||||
|
playerSkillTree = PlayerSkillTree.Instance;
|
||||||
AssignCooldowns();
|
AssignCooldowns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.Space) && !IsOnCooldown(PlayerSkillTree.Skills.Dash) && playerSkillTree.IsSkillUnlocked(PlayerSkillTree.Skills.Dash))
|
||||||
|
{
|
||||||
|
/* Get the input for horizontal and vertical movement */
|
||||||
|
float moveX = Input.GetAxisRaw("Horizontal");
|
||||||
|
float moveZ = Input.GetAxisRaw("Vertical");
|
||||||
|
|
||||||
|
var move = new Vector3(moveX, 0, moveZ).normalized;
|
||||||
|
StartCoroutine(DashCoroutine(controller, move));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.L))
|
||||||
|
{
|
||||||
|
if (playerSkillTree.TryUsePotion(PotionHandler.PotionType.HealthBig))
|
||||||
|
{
|
||||||
|
Debug.Log("Potion used!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("Potion not available!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FixedUpdate()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerator DashCoroutine(CharacterController controller, Vector3 direction)
|
public IEnumerator DashCoroutine(CharacterController controller, Vector3 direction)
|
||||||
{
|
{
|
||||||
Physics.IgnoreLayerCollision(6, 7, true); // disable collisions between player and enemies
|
Physics.IgnoreLayerCollision(6, 7, true); // disable collisions between player and enemies
|
||||||
@@ -61,8 +95,8 @@ public class PlayerSkillHandler: MonoBehaviour
|
|||||||
|
|
||||||
public bool IsOnCooldown(PlayerSkillTree.Skills skill)
|
public bool IsOnCooldown(PlayerSkillTree.Skills skill)
|
||||||
{
|
{
|
||||||
Debug.Log("cooldown time: " + (Time.time - cooldownsActivated[skill]));
|
//Debug.Log("cooldown time: " + (Time.time - cooldownsActivated[skill]));
|
||||||
Debug.Log("skill cooldown: " + cooldowns[skill]);
|
//Debug.Log("skill cooldown: " + cooldowns[skill]);
|
||||||
return !cooldowns.ContainsKey(skill) || !cooldownsActivated.ContainsKey(skill)
|
return !cooldowns.ContainsKey(skill) || !cooldownsActivated.ContainsKey(skill)
|
||||||
? false
|
? false
|
||||||
: Time.time - cooldownsActivated[skill] < cooldowns[skill];
|
: Time.time - cooldownsActivated[skill] < cooldowns[skill];
|
||||||
|
|||||||
Reference in New Issue
Block a user