Browse Source

Player has millisecond of invulnerability after getting hit.

added rest time between attacks
master
Joshua Reason 9 years ago
parent
commit
536df032a3
4 changed files with 28 additions and 2 deletions
  1. BIN
      playable/Assets/Lachlan_jump_work.unity
  2. +1
    -0
      playable/Assets/Scripts/PlayerControler.cs
  3. +24
    -1
      playable/Assets/Scripts/playerController.cs
  4. +3
    -1
      playable/Assets/stickController.cs

BIN
playable/Assets/Lachlan_jump_work.unity View File


+ 1
- 0
playable/Assets/Scripts/PlayerControler.cs View File

@ -92,6 +92,7 @@ public class PlayerControler : MonoBehaviour {
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0);
health = 3; health = 3;
transform.position = spawnPos; transform.position = spawnPos;
rigidbody2D.velocity = Vector2.zero;
} }
} }

+ 24
- 1
playable/Assets/Scripts/playerController.cs View File

@ -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){

+ 3
- 1
playable/Assets/stickController.cs View File

@ -38,9 +38,11 @@ public class stickController : MonoBehaviour {
if(transform.position.y>col.transform.position.y){ if(transform.position.y>col.transform.position.y){
if (isAttacking){ if (isAttacking){
col.gameObject.GetComponent<playerController>().health --; col.gameObject.GetComponent<playerController>().health --;
col.gameObject.GetComponent<playerController>().isHit = true;
Confettishoot(col.gameObject.transform.position,col.gameObject.GetComponent<playerController>().confettiOnHit); Confettishoot(col.gameObject.transform.position,col.gameObject.GetComponent<playerController>().confettiOnHit);
Vector2 velocity = col.rigidbody.velocity; Vector2 velocity = col.rigidbody.velocity;
velocity.y = 22;
velocity.y = 20;
col.rigidbody.velocity = velocity; col.rigidbody.velocity = velocity;
} }
} }

Loading…
Cancel
Save