|
|
@ -18,6 +18,9 @@ public class playerController : MonoBehaviour { |
|
|
|
public float health; //holds health
|
|
|
|
public int confettiOnHit; //amount of confetti created on hit
|
|
|
|
public Vector2 healthPos; |
|
|
|
public float invulTime; |
|
|
|
public float attackWait; |
|
|
|
public bool isHit; |
|
|
|
|
|
|
|
private float displayedHealth = 3; //currently displayed health
|
|
|
|
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 List<GameObject> hearts = new List<GameObject> (); //list which holds health sprites;
|
|
|
|
private bool isSpinning = false; //checks if player is spin attacking
|
|
|
|
private float lastHit; |
|
|
|
private float lastAttack; |
|
|
|
|
|
|
|
|
|
|
|
void Start(){ |
|
|
@ -42,6 +47,7 @@ public class playerController : MonoBehaviour { |
|
|
|
displayHealth (); |
|
|
|
death (); |
|
|
|
applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn)); |
|
|
|
damage (); |
|
|
|
} |
|
|
|
|
|
|
|
void FixedUpdate() { |
|
|
@ -59,8 +65,10 @@ public class playerController : MonoBehaviour { |
|
|
|
}//end if
|
|
|
|
|
|
|
|
if (Input.GetAxisRaw (StrongAttackBtn)==1) { |
|
|
|
if (!isSpinning) |
|
|
|
if (!isSpinning && (lastAttack+attackWait) < Time.time){ |
|
|
|
lastAttack = Time.time; |
|
|
|
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
|
|
|
|
health = 3; //resets life
|
|
|
|
transform.position = spawnPos; //changes position
|
|
|
|
rigidbody2D.velocity = Vector2.zero; |
|
|
|
}//end if
|
|
|
|
}//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) { |
|
|
|
isSpinning = true; |
|
|
|
stick.isAttacking = true; |
|
|
@ -144,6 +164,9 @@ public class playerController : MonoBehaviour { |
|
|
|
isSpinning = false; |
|
|
|
stick.isAttacking = false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnCollisionEnter2D(Collision2D col){ |
|
|
|