diff --git a/playable/Assets/Heart 1.prefab b/playable/Assets/Heart 1.prefab new file mode 100644 index 0000000..7db7749 Binary files /dev/null and b/playable/Assets/Heart 1.prefab differ diff --git a/playable/Assets/Heart 1.prefab.meta b/playable/Assets/Heart 1.prefab.meta new file mode 100644 index 0000000..90a2e42 --- /dev/null +++ b/playable/Assets/Heart 1.prefab.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: 0d389d1b38821bf42927835a245fcbfc +NativeFormatImporter: + userData: diff --git a/playable/Assets/Heart.png b/playable/Assets/Heart.png new file mode 100644 index 0000000..57b7dfa Binary files /dev/null and b/playable/Assets/Heart.png differ diff --git a/playable/Assets/Heart.png.meta b/playable/Assets/Heart.png.meta new file mode 100644 index 0000000..38e7363 --- /dev/null +++ b/playable/Assets/Heart.png.meta @@ -0,0 +1,47 @@ +fileFormatVersion: 2 +guid: e1474e33244f9b940b641e1d2f515f84 +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: .25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 1024 + textureSettings: + filterMode: -1 + aniso: 16 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: .5, y: .5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 1 + alphaIsTransparency: 1 + textureType: 8 + buildTargetSettings: [] + spriteSheet: + sprites: [] + spritePackingTag: + userData: diff --git a/playable/Assets/Heart.prefab b/playable/Assets/Heart.prefab new file mode 100644 index 0000000..0822037 Binary files /dev/null and b/playable/Assets/Heart.prefab differ diff --git a/playable/Assets/Heart.prefab.meta b/playable/Assets/Heart.prefab.meta new file mode 100644 index 0000000..e81a8bd --- /dev/null +++ b/playable/Assets/Heart.prefab.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: dd2f67d649876c549bbdec2deadaa076 +NativeFormatImporter: + userData: diff --git a/playable/Assets/Lachlan_jump_work.unity b/playable/Assets/Lachlan_jump_work.unity index f5e0318..e033436 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 6f77311..be7907b 100644 --- a/playable/Assets/Scripts/PlayerControler.cs +++ b/playable/Assets/Scripts/PlayerControler.cs @@ -11,7 +11,11 @@ public class PlayerControler : MonoBehaviour { public float speed; public Vector2 jumpVector; + public int health = 0; + private int displayedHealth = 0; + private bool updateHealth = false; public GameObject bullet; + public GameObject heart; bool canJump = true; @@ -24,6 +28,12 @@ public class PlayerControler : MonoBehaviour { animator.SetBool ("Fall", !canJump); applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P1")); + if (displayedHealth != health) { + updateHealth = true; + } + if (updateHealth) + displayHealth (health); + if (Input.GetKey (KeyCode.UpArrow)){ if (canJump == true){ @@ -39,6 +49,20 @@ public class PlayerControler : MonoBehaviour { //} } + private void displayHealth(int health){ + GameObject[] hearts = GameObject.FindGameObjectsWithTag("heartUI2"); + foreach (GameObject desHeart in hearts) + GameObject.Destroy (desHeart); + + for (int i=1; i<= health; i++) { + GameObject heartCanister = Instantiate (heart) as GameObject; + Vector3 heartPos = new Vector3 (1-(i * 0.033f), 0.95f, 0); + heartCanister.transform.position = heartPos; + } + displayedHealth = health; + updateHealth = false; + } + private void applyPlayerDirection(float moveHorizontal) { if (moveHorizontal != 0) @@ -52,8 +76,16 @@ public class PlayerControler : MonoBehaviour { void OnCollisionEnter2D(Collision2D col){ if (col.collider.tag == "ground") canJump = true; - else if(col.collider.tag == "Player") + else if (col.collider.tag == "Player") { canJump = true; + if(transform.position.y>col.transform.position.y){ + col.gameObject.GetComponent().health --; + //health --; + rigidbody2D.velocity = jumpVector; + canJump = false; + } + + } } } diff --git a/playable/Assets/Scripts/player2_controls.cs b/playable/Assets/Scripts/player2_controls.cs index 4707768..a0b5ce6 100644 --- a/playable/Assets/Scripts/player2_controls.cs +++ b/playable/Assets/Scripts/player2_controls.cs @@ -11,7 +11,11 @@ public class player2_controls : MonoBehaviour { public float speed; public Vector2 jumpVector; + public int health = 0; + private int displayedHealth = 0; + private bool updateHealth = false; public GameObject bullet; + public GameObject heart; bool canJump = true; @@ -24,6 +28,12 @@ public class player2_controls : MonoBehaviour { animator.SetFloat("Velocity",velo.magnitude); animator.SetBool ("Fall", !canJump); applyPlayerDirection (Input.GetAxisRaw ("Horizontal_P2")); + + if (displayedHealth != health) { + updateHealth = true; + } + if (updateHealth) + displayHealth (health); if (Input.GetKey (KeyCode.W)){ if (canJump == true){ @@ -39,6 +49,19 @@ public class player2_controls : MonoBehaviour { //} } + private void displayHealth(int health){ + GameObject[] hearts = GameObject.FindGameObjectsWithTag("heartUI"); + foreach (GameObject desHeart in hearts) + GameObject.Destroy (desHeart); + + for (int i=1; i<= health; i++) { + GameObject heartCanister = Instantiate (heart) as GameObject; + Vector3 heartPos = new Vector3 ((i * 0.033f), 0.95f, 0); + heartCanister.transform.position = heartPos; + } + displayedHealth = health; + updateHealth = false; + } //Changes direction of sprite according to key pressed private void applyPlayerDirection(float moveHorizontal) { @@ -53,8 +76,14 @@ public class player2_controls : MonoBehaviour { void OnCollisionEnter2D(Collision2D col){ if (col.collider.tag == "ground") canJump = true; - else if(col.collider.tag == "Player") - canJump = true; + else if (col.collider.tag == "Player") { + if(transform.position.y>col.transform.position.y){ + col.gameObject.GetComponent().health --; + //health --; + rigidbody2D.velocity = jumpVector; + canJump = false; + } + } } diff --git a/playable/ProjectSettings/TagManager.asset b/playable/ProjectSettings/TagManager.asset index 16fc12e..1d4d8c2 100644 Binary files a/playable/ProjectSettings/TagManager.asset and b/playable/ProjectSettings/TagManager.asset differ