|
|
@ -7,6 +7,7 @@ public class playerController : MonoBehaviour { |
|
|
|
public string HorizontalBtn; //holds string for horizontal input
|
|
|
|
public string VerticalBtn; //holds string for Vertical input
|
|
|
|
public string StrongAttackBtn; |
|
|
|
public string DashAttackBtn; |
|
|
|
|
|
|
|
public Animator animator; //Holds animator for Pinata
|
|
|
|
public GameObject heart; //Health sprites
|
|
|
@ -24,6 +25,9 @@ public class playerController : MonoBehaviour { |
|
|
|
public float invulTime; |
|
|
|
public float attackWait; |
|
|
|
public bool isHit; |
|
|
|
public float dashDistance; |
|
|
|
public float dashTime; |
|
|
|
public float dashWait; |
|
|
|
|
|
|
|
private float displayedHealth = 3; //currently displayed health
|
|
|
|
private bool updateHealth = true; //if the health bar needs updating
|
|
|
@ -35,7 +39,10 @@ public class playerController : MonoBehaviour { |
|
|
|
private float lastHit; |
|
|
|
private float lastAttack; |
|
|
|
private int score; |
|
|
|
|
|
|
|
private bool isDashing =false; |
|
|
|
private bool canDash = true; |
|
|
|
private float lastDash; |
|
|
|
private bool stopDash = false; |
|
|
|
|
|
|
|
void Start(){ |
|
|
|
if (transform.rotation.y == 180) |
|
|
@ -59,6 +66,7 @@ public class playerController : MonoBehaviour { |
|
|
|
if (score >= 10) { |
|
|
|
gameOverDisplay.enabled = true; |
|
|
|
gameOverDisplay.text = ""+ gameObject.name + " Wins"; |
|
|
|
Time.timeScale = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -86,6 +94,15 @@ public class playerController : MonoBehaviour { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (Input.GetAxisRaw (DashAttackBtn) == 1) { |
|
|
|
//Debug.Log ("dashbutton pressed");
|
|
|
|
if(!isDashing && canDash && Time.time - lastDash > dashWait){ |
|
|
|
lastDash = Time.time; |
|
|
|
StartCoroutine (dashAttack (dashDistance,dashTime)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rigidbody2D.velocity = velocity; //apply inputs
|
|
|
@ -184,6 +201,49 @@ public class playerController : MonoBehaviour { |
|
|
|
stick.isAttacking = false; |
|
|
|
} |
|
|
|
|
|
|
|
IEnumerator dashAttack (float dashDistance,float dashTime) { |
|
|
|
float endPosition; |
|
|
|
int dashDirection; |
|
|
|
|
|
|
|
isDashing = true; |
|
|
|
canDash = false; |
|
|
|
stick.isAttacking = true; |
|
|
|
Debug.Log ("" + gameObject.name + "Dashing"); |
|
|
|
rigidbody2D.gravityScale = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 startPosition = transform.position; |
|
|
|
Debug.Log ("rotation Y: " + transform.eulerAngles.y); |
|
|
|
if (transform.eulerAngles.y >= 150) |
|
|
|
dashDirection = -1; |
|
|
|
else |
|
|
|
dashDirection = 1; |
|
|
|
|
|
|
|
endPosition = startPosition.x + (dashDirection * dashDistance); |
|
|
|
Debug.Log ("Dash start: " + startPosition.x); |
|
|
|
Debug.Log ("Dash Direction: " + (dashDirection )); |
|
|
|
Debug.Log ("Dash end: " + endPosition); |
|
|
|
|
|
|
|
for (float i = 0; i < 1; i += Time.deltaTime/dashTime) { |
|
|
|
transform.position = new Vector3(dashDirection * Mathf.Lerp((dashDirection)*startPosition.x, (dashDirection)* endPosition, i), startPosition.y, startPosition.z); |
|
|
|
|
|
|
|
if (stopDash) |
|
|
|
break; |
|
|
|
|
|
|
|
yield return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stopDash = false; |
|
|
|
isDashing = false; |
|
|
|
canDash = true; |
|
|
|
stick.isAttacking = false; |
|
|
|
Debug.Log ("" + gameObject.name + " finished Dashing"); |
|
|
|
rigidbody2D.gravityScale = 4; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -197,6 +257,11 @@ public class playerController : MonoBehaviour { |
|
|
|
canJump = true; |
|
|
|
canSpin = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (col.collider.tag == "wall") { |
|
|
|
stopDash = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D trig) |
|
|
|