Skip to content
Snippets Groups Projects
Commit 5cb1a947 authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Changed ability code to handle fire types.

parent 10754bf0
No related branches found
No related tags found
1 merge request!56New ability fire rework. (Charging)
...@@ -119,13 +119,45 @@ namespace BigSock { ...@@ -119,13 +119,45 @@ namespace BigSock {
} }
// Dictionary that holds start times for charging abilities.
Dictionary<KeyCode, float> chargeStarts = new Dictionary<KeyCode, float>();
/*
Triggers an ability if it should be.
*/
private void CheckAbilityInput(KeyCode key, IAbility ability) {
var par = GetAbilityParam(Camera.main.ScreenToWorldPoint(Input.mousePosition));
switch(ability.FireType) {
// Standard: Press to fire.
case FireType.Standard:
if(Input.GetKeyDown(key)) ability.Use(par);
break;
// FullAuto: Keep firing while key is down.
case FireType.FullAuto:
if(Input.GetKey(key)) ability.Use(par);
break;
// Charge: Fire when let go.
case FireType.Charge:
// If pressed down: Store start time.
if(Input.GetKeyDown(key)) chargeStarts[key] = Time.time;
// If let go: Activate
else if(Input.GetKeyUp(key)) {
par.ChargeTime = Time.time - chargeStarts[key];
ability.Use(par);
}
break;
default:
break;
}
}
private void Update() { private void Update() {
// Regenerate mana & stamina. // Regenerate mana & stamina.
Regenerate(); Regenerate();
// Object w/ parameters for abilities. // Object w/ parameters for abilities.
var par = GetAbilityParam(Camera.main.ScreenToWorldPoint(Input.mousePosition));
//var par = new AbilityParam{ //var par = new AbilityParam{
// Actor = this, // Actor = this,
// TargetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition), // TargetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition),
...@@ -133,20 +165,27 @@ namespace BigSock { ...@@ -133,20 +165,27 @@ namespace BigSock {
//}; //};
// If pressed Soace or LMB: Regular attack. //// If pressed Soace or LMB: Regular attack.
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButton(0)) { //if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButton(0)) {
_testAttack.Use(par); // _testAttack.Use(par);
} //}
// If pressed Z: Big attack. // Check ability 1.
if(Input.GetKey(KeyCode.Z)) { CheckAbilityInput(KeyCode.Space, _testAttack);
_testAttack2.Use(par); // Check ability 2.
} CheckAbilityInput(KeyCode.Z, _testAttack2);
// Check ability 3.
CheckAbilityInput(KeyCode.X, _dodge);
// If pressed X: dodge. //// If pressed Z: Big attack.
if(Input.GetKey(KeyCode.X)) { //if(Input.GetKey(KeyCode.Z)) {
_dodge.Use(par); // _testAttack2.Use(par);
} //}
//// If pressed X: dodge.
//if(Input.GetKey(KeyCode.X)) {
// _dodge.Use(par);
//}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment