|
@ -18,6 +18,9 @@ public class playerController : MonoBehaviour { |
|
|
public float health; //holds health
|
|
|
public float health; //holds health
|
|
|
public int confettiOnHit; //amount of confetti created on hit
|
|
|
public int confettiOnHit; //amount of confetti created on hit
|
|
|
public Vector2 healthPos; |
|
|
public Vector2 healthPos; |
|
|
|
|
|
public float invulTime; |
|
|
|
|
|
public float attackWait; |
|
|
|
|
|
public bool isHit; |
|
|
|
|
|
|
|
|
private float displayedHealth = 3; //currently displayed health
|
|
|
private float displayedHealth = 3; //currently displayed health
|
|
|
private bool updateHealth = true; //if the health bar needs updating
|
|
|
private bool updateHealth = true; //if the health bar needs updating
|
|
@ -25,6 +28,8 @@ public class playerController : MonoBehaviour { |
|
|
private bool canJump = true; // if player can jump
|
|
|
private bool canJump = true; // if player can jump
|
|
|
private List<GameObject> hearts = new List<GameObject> (); //list which holds health sprites;
|
|
|
private List<GameObject> hearts = new List<GameObject> (); //list which holds health sprites;
|
|
|
private bool isSpinning = false; //checks if player is spin attacking
|
|
|
private bool isSpinning = false; //checks if player is spin attacking
|
|
|
|
|
|
private float lastHit; |
|
|
|
|
|
private float lastAttack; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Start(){ |
|
|
void Start(){ |
|
@ -42,6 +47,7 @@ public class playerController : MonoBehaviour { |
|
|
displayHealth (); |
|
|
displayHealth (); |
|
|
death (); |
|
|
death (); |
|
|
applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn)); |
|
|
applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn)); |
|
|
|
|
|
damage (); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FixedUpdate() { |
|
|
void FixedUpdate() { |
|
@ -59,8 +65,10 @@ public class playerController : MonoBehaviour { |
|
|
}//end if
|
|
|
}//end if
|
|
|
|
|
|
|
|
|
if (Input.GetAxisRaw (StrongAttackBtn)==1) { |
|
|
if (Input.GetAxisRaw (StrongAttackBtn)==1) { |
|
|
if (!isSpinning) |
|
|
|
|
|
|
|
|
if (!isSpinning && (lastAttack+attackWait) < Time.time){ |
|
|
|
|
|
lastAttack = Time.time; |
|
|
StartCoroutine (spinAttack (Vector3.down * 360, 0.2f)); |
|
|
StartCoroutine (spinAttack (Vector3.down * 360, 0.2f)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -113,6 +121,7 @@ public class playerController : MonoBehaviour { |
|
|
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position
|
|
|
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position
|
|
|
health = 3; //resets life
|
|
|
health = 3; //resets life
|
|
|
transform.position = spawnPos; //changes position
|
|
|
transform.position = spawnPos; //changes position
|
|
|
|
|
|
rigidbody2D.velocity = Vector2.zero; |
|
|
}//end if
|
|
|
}//end if
|
|
|
}//end death
|
|
|
}//end death
|
|
|
|
|
|
|
|
@ -126,6 +135,17 @@ public class playerController : MonoBehaviour { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void damage (){ |
|
|
|
|
|
if (isHit) { |
|
|
|
|
|
gameObject.GetComponent<PolygonCollider2D> ().enabled = false; |
|
|
|
|
|
isHit = false; |
|
|
|
|
|
lastHit = Time.time; |
|
|
|
|
|
} |
|
|
|
|
|
if (lastHit+invulTime < Time.time) |
|
|
|
|
|
gameObject.GetComponent<PolygonCollider2D> ().enabled = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
IEnumerator spinAttack(Vector3 byAngles, float inTime) { |
|
|
IEnumerator spinAttack(Vector3 byAngles, float inTime) { |
|
|
isSpinning = true; |
|
|
isSpinning = true; |
|
|
stick.isAttacking = true; |
|
|
stick.isAttacking = true; |
|
@ -144,6 +164,9 @@ public class playerController : MonoBehaviour { |
|
|
isSpinning = false; |
|
|
isSpinning = false; |
|
|
stick.isAttacking = false; |
|
|
stick.isAttacking = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnCollisionEnter2D(Collision2D col){ |
|
|
void OnCollisionEnter2D(Collision2D col){ |
|
|