diff --git a/Assets/Prefabs/Bed.prefab b/Assets/Prefabs/Bed.prefab new file mode 100644 index 0000000..7d8eead Binary files /dev/null and b/Assets/Prefabs/Bed.prefab differ diff --git a/Assets/Prefabs/Bed.prefab.meta b/Assets/Prefabs/Bed.prefab.meta new file mode 100644 index 0000000..fcac3b4 --- /dev/null +++ b/Assets/Prefabs/Bed.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9f2c38d0d3154bc4d8148a949b98af28 +timeCreated: 1440250095 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/PatScene.unity b/Assets/Scenes/PatScene.unity index dc1ee7a..b113749 100644 Binary files a/Assets/Scenes/PatScene.unity and b/Assets/Scenes/PatScene.unity differ diff --git a/Assets/Scripts/Bed.cs b/Assets/Scripts/Bed.cs new file mode 100644 index 0000000..a5598fd --- /dev/null +++ b/Assets/Scripts/Bed.cs @@ -0,0 +1,22 @@ +using UnityEngine; +using System.Collections; + +public class Bed : MonoBehaviour +{ + private bool _isTaken; + + public bool IsTaken + { + get { return _isTaken; } + } + + public void Take() + { + _isTaken = true; + } + + public void Leave() + { + _isTaken = false; + } +} diff --git a/Assets/Scripts/Bed.cs.meta b/Assets/Scripts/Bed.cs.meta new file mode 100644 index 0000000..7aacc3c --- /dev/null +++ b/Assets/Scripts/Bed.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 49fab454291c16d4185f7f6a511de185 +timeCreated: 1440250042 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 37f2284..a485243 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -6,6 +6,7 @@ public class Child : MonoBehaviour { public float Speed = 10f; public float JumpForce = 10f; + public float MaxInvulnerableTime = 2f; public GameObject GroundCheck; public Pillow pillow; public MomBehavior Mom; @@ -15,6 +16,8 @@ public class Child : MonoBehaviour private float _xValue; private float _zValue; private bool _isSleeping; + private float _invulnerableTime; + private Bed _currentBed; public Transform target; private int _index; @@ -108,11 +111,15 @@ public class Child : MonoBehaviour public bool Sleep() { - _isSleeping = IsOnBed(); + Bed bed = GetBed(); - // Temporary (only for visual cue until we get the animation) - if (_isSleeping) + if (bed != null && !bed.IsTaken) { + _currentBed = bed; + bed.Take(); + _isSleeping = true; + + // Temporary (only for visual cue until we get the animation) transform.localEulerAngles = new Vector3(90f, transform.localEulerAngles.y, transform.localEulerAngles.z); } @@ -123,23 +130,48 @@ public class Child : MonoBehaviour { _isSleeping = false; + _currentBed.Leave(); + + _currentBed = null; + // Temporary (only for visual cue until we get the animation) transform.localEulerAngles = new Vector3(0f, transform.localEulerAngles.y, transform.localEulerAngles.z); } - private bool IsOnBed() + private Bed GetBed() { Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, 1 << LayerMask.NameToLayer("Bed")); - return colliders.Length > 0; + return colliders.Length > 0 ? colliders[0].GetComponent() : null; + } + + void OnCollisionEnter(Collision collision) + { + if (collision.gameObject.tag == "Lava") + { + Debug.Log("Player " + _index + " entered lava. Lose one life."); + TakeLavaDamage(); + } } void OnCollisionStay(Collision collision) { if (collision.gameObject.tag == "Lava") { - // TODO: Lose a life (probably) and become immune for ~ 2 or 3 seconds - Debug.Log("Player " + _index + " is standing on lava."); + _invulnerableTime += Time.deltaTime; + + if (_invulnerableTime >= MaxInvulnerableTime) + { + Debug.Log("Player " + _index + " is still standing on lava. Lose one life."); + TakeLavaDamage(); + } } } + + private void TakeLavaDamage() + { + // TODO: Lose a life (probably) and become immune for ~ 2 or 3 seconds + + _invulnerableTime = 0f; + } }