diff --git a/playable/Assets/Confetti.prefab b/playable/Assets/Confetti.prefab index e08a543..fc52f94 100644 Binary files a/playable/Assets/Confetti.prefab and b/playable/Assets/Confetti.prefab differ diff --git a/playable/Assets/Lachlan_jump_work.unity b/playable/Assets/Lachlan_jump_work.unity index 612cfb3..0ba3246 100644 Binary files a/playable/Assets/Lachlan_jump_work.unity and b/playable/Assets/Lachlan_jump_work.unity differ diff --git a/playable/Assets/Scripts/PlayerControler.cs b/playable/Assets/Scripts/PlayerControler.cs index e15c298..4c7cf86 100644 --- a/playable/Assets/Scripts/PlayerControler.cs +++ b/playable/Assets/Scripts/PlayerControler.cs @@ -14,6 +14,7 @@ public class PlayerControler : MonoBehaviour { public int health = 0; private int displayedHealth = 0; private bool updateHealth = false; + private float curDirection = -1; public GameObject bullet; public GameObject heart; bool canJump = true; @@ -27,7 +28,8 @@ public class PlayerControler : MonoBehaviour { rigidbody2D.velocity = velo; animator.SetFloat("Velocity",velo.magnitude); animator.SetBool ("Fall", !canJump); - applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P1")); + if (curDirection != Input.GetAxisRaw ("Horizontal_P1")) + applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P1")); if (displayedHealth != health) { updateHealth = true; @@ -71,9 +73,8 @@ public class PlayerControler : MonoBehaviour { { if (moveHorizontal != 0) { - Vector3 scale = transform.localScale; - scale.x = -moveHorizontal * Mathf.Abs(scale.x); - transform.localScale = scale; + transform.Rotate(0,180,0); + curDirection = moveHorizontal; } } @@ -87,9 +88,11 @@ public class PlayerControler : MonoBehaviour { } private void death(){ - Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); - health = 3; - transform.position = spawnPos; + if (health == 0) { + Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); + health = 3; + transform.position = spawnPos; + } } void OnCollisionEnter2D(Collision2D col){ @@ -99,7 +102,7 @@ public class PlayerControler : MonoBehaviour { canJump = true; if(transform.position.y>col.transform.position.y){ col.gameObject.GetComponent().health --; - Confettishoot(col.gameObject.transform.position,200.0f); + Confettishoot(col.gameObject.transform.position,20.0f); //health --; rigidbody2D.velocity = jumpVector; canJump = false; diff --git a/playable/Assets/Scripts/confettiController.cs b/playable/Assets/Scripts/confettiController.cs index df1bd4a..235e64c 100644 --- a/playable/Assets/Scripts/confettiController.cs +++ b/playable/Assets/Scripts/confettiController.cs @@ -15,7 +15,7 @@ public class confettiController : MonoBehaviour { int randColour = Mathf.FloorToInt (rand); startTime = Time.time; startScale = transform.localScale.x; - rigidbody.velocity = Random.onUnitSphere * speed; + rigidbody2D.velocity = Random.onUnitSphere * speed; switch (randColour) { case 0: diff --git a/playable/Assets/Scripts/player2_controls.cs b/playable/Assets/Scripts/player2_controls.cs index 7efdbf0..c93713b 100644 --- a/playable/Assets/Scripts/player2_controls.cs +++ b/playable/Assets/Scripts/player2_controls.cs @@ -7,28 +7,33 @@ public class player2_controls : MonoBehaviour { void Start () { - } + } public float speed; public Vector2 jumpVector; public int health = 0; private int displayedHealth = 0; private bool updateHealth = false; + private float curDirection = 1; public GameObject bullet; public GameObject heart; bool canJump = true; + public string HorizontalBtn; + public GameObject newConfetti; + //Horizontal_P2 void Update() { Vector2 velo = rigidbody2D.velocity; - velo.x = Input.GetAxis ("Horizontal_P2") * speed; + velo.x = Input.GetAxis (HorizontalBtn) * speed; rigidbody2D.velocity = velo; animator.SetFloat("Velocity",velo.magnitude); animator.SetBool ("Fall", !canJump); - applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P2")); + if (curDirection != Input.GetAxisRaw (HorizontalBtn)) + applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn)); if (displayedHealth != health) { updateHealth = true; @@ -71,9 +76,8 @@ public class player2_controls : MonoBehaviour { { if (moveHorizontal != 0) { - Vector3 scale = transform.localScale; - scale.x = moveHorizontal * Mathf.Abs(scale.x); - transform.localScale = scale; + transform.Rotate(0,180,0); + curDirection = moveHorizontal; } } @@ -99,7 +103,7 @@ public class player2_controls : MonoBehaviour { else if (col.collider.tag == "Player") { if(transform.position.y>col.transform.position.y){ col.gameObject.GetComponent().health --; - Confettishoot(col.gameObject.transform.position,200.0f); + Confettishoot(col.gameObject.transform.position,20.0f); //health --; rigidbody2D.velocity = jumpVector; diff --git a/playable/Assets/Scripts/playerController.cs b/playable/Assets/Scripts/playerController.cs new file mode 100644 index 0000000..e560130 --- /dev/null +++ b/playable/Assets/Scripts/playerController.cs @@ -0,0 +1,162 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; //input for lists + +public class playerController : MonoBehaviour { + + public string HorizontalBtn; //holds string for horizontal input + public string VerticalBtn; //holds string for Vertical input + public string StrongAttackBtn; + + public Animator animator; //Holds animator for Pinata + public GameObject heart; //Health sprites + public GameObject newConfetti; //confetti when hit + public stickController stick; //controller for stick + + public float runSpeed; //run speed + public float jumpHeight; //jump height + public float health; //holds health + public int confettiOnHit; //amount of confetti created on hit + public Vector2 healthPos; + + private float displayedHealth = 3; //currently displayed health + private bool updateHealth = true; //if the health bar needs updating + private float curDirection = -1; //direction player is pointing + private bool canJump = true; // if player can jump + private List hearts = new List (); //list which holds health sprites; + private bool isSpinning = false; //checks if player is spin attacking + + + void Start(){ + if (transform.rotation.y == 180) + curDirection = -1; + else + curDirection = 1; + + } + + + // Update is called once per frame + void Update () { + + displayHealth (); + death (); + applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn)); + } + + void FixedUpdate() { + + /* + * Movement inputs + */ + Vector2 velocity = rigidbody2D.velocity; + velocity.x = Input.GetAxis (HorizontalBtn) * runSpeed; //Horizontal input + + if ((Input.GetAxisRaw (VerticalBtn) == 1) && (canJump)) //Vertical input + { + velocity.y = jumpHeight; + canJump = false; + }//end if + + if (Input.GetAxisRaw (StrongAttackBtn)==1) { + if (!isSpinning) + StartCoroutine (spinAttack (Vector3.down * 360, 0.2f)); + } + + + + rigidbody2D.velocity = velocity; //apply inputs + animator.SetFloat("Velocity",velocity.magnitude);//inputs for animator + animator.SetBool ("Fall", !canJump); + + + }//end fixed update + + private void displayHealth(){ + + if (displayedHealth != health) //check if health needs updating + updateHealth = true; + + if (updateHealth){ + foreach (GameObject desHeart in hearts) //Destroy all heart sprites + GameObject.Destroy (desHeart); + hearts.Clear(); //sets list to zero + + for (int i=1; i<= health; i++) { //creates new heart sprite for each health + GameObject heartCanister = Instantiate (heart) as GameObject; //creat heart sprite + Vector3 heartPos = new Vector3 (); + + //set position + if (healthPos.x == 1) + heartPos.x = (i * 0.033f); + else + heartPos.x = 1-(i * 0.033f); + + if (healthPos.y == 1) + heartPos.y = 0.95f; + else + heartPos.y = 0.05f; + + heartCanister.transform.position = heartPos; + hearts.Add(heartCanister); //adds heart to list + }//end for + + displayedHealth = health; + updateHealth = false; + }//end if + + }//end displayHealth + + //respawns player if they die + private void death(){ + if (health <= 0) { + 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 + }//end if + }//end death + + private void applyPlayerDirection(float moveHorizontal) + { + + if ((curDirection != moveHorizontal) && (moveHorizontal != 0) && !isSpinning) //if player movement direction vs displayed direction + { + transform.Rotate(0,180,0); //rotates player + curDirection = moveHorizontal; //updates direction + } + } + + IEnumerator spinAttack(Vector3 byAngles, float inTime) { + isSpinning = true; + stick.isAttacking = true; + Debug.Log ("" + gameObject.name + "spinning"); + Quaternion startAngle = transform.rotation; + Quaternion endAngle = Quaternion.Euler(transform.eulerAngles + byAngles); + float direction = transform.eulerAngles.y; + + for(float i = 0; i < 1; i += Time.deltaTime/inTime) { + transform.rotation = Quaternion.Euler(0,direction,Mathf.Lerp(0,360,i)); + yield return null; + + } + transform.eulerAngles = new Vector3 (0,direction,0); + Debug.Log ("" + gameObject.name + "End spin"); + isSpinning = false; + stick.isAttacking = false; + } + + + void OnCollisionEnter2D(Collision2D col){ + if (col.collider.tag == "ground") + canJump = true; + else if (col.collider.tag == "Player") { + canJump = true; + } + } + + + + + + +} diff --git a/playable/Assets/Scripts/playerController.cs.meta b/playable/Assets/Scripts/playerController.cs.meta new file mode 100644 index 0000000..a71b0e5 --- /dev/null +++ b/playable/Assets/Scripts/playerController.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: feb419ae5508b15478825d388564e732 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/playable/Assets/Scripts/spotLightController.cs b/playable/Assets/Scripts/spotLightController.cs new file mode 100644 index 0000000..7dfd8bb --- /dev/null +++ b/playable/Assets/Scripts/spotLightController.cs @@ -0,0 +1,10 @@ +using UnityEngine; +using System.Collections; + +public class spotLightController : MonoBehaviour { + + public Transform target; + void Update() { + transform.LookAt(target); + } +} diff --git a/playable/Assets/Scripts/spotLightController.cs.meta b/playable/Assets/Scripts/spotLightController.cs.meta new file mode 100644 index 0000000..cbf6971 --- /dev/null +++ b/playable/Assets/Scripts/spotLightController.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 72c6d3c5f1bbc484bbf1d4932cb997d9 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/playable/Assets/stickController.cs b/playable/Assets/stickController.cs new file mode 100644 index 0000000..d413aa0 --- /dev/null +++ b/playable/Assets/stickController.cs @@ -0,0 +1,52 @@ +using UnityEngine; +using System.Collections; + +public class stickController : MonoBehaviour { + + public GameObject newConfetti; + + public bool isAttacking; + public bool isSpinning; + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + if (isAttacking) { + gameObject.GetComponent ().enabled = true; + gameObject.GetComponent ().enabled = true; + } else { + gameObject.GetComponent ().enabled = false; + gameObject.GetComponent ().enabled = false; + } + } + + private void Confettishoot(Vector3 target,int size){ //creates confetti + Debug.Log ("Creating Confetti"); + + target.y += 1.5f; + for (int i = 0; i col.transform.position.y){ + if (isAttacking){ + col.gameObject.GetComponent().health --; + Confettishoot(col.gameObject.transform.position,col.gameObject.GetComponent().confettiOnHit); + Vector2 velocity = col.rigidbody.velocity; + velocity.y = 22; + col.rigidbody.velocity = velocity; + } + } + + } + } + + +} diff --git a/playable/Assets/stickController.cs.meta b/playable/Assets/stickController.cs.meta new file mode 100644 index 0000000..d3ae9f1 --- /dev/null +++ b/playable/Assets/stickController.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 34ac62105d880784f9e51ad9f26a0111 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/playable/ProjectSettings/InputManager.asset b/playable/ProjectSettings/InputManager.asset index 9c16f77..3320af6 100644 Binary files a/playable/ProjectSettings/InputManager.asset and b/playable/ProjectSettings/InputManager.asset differ