diff --git a/Assets/ControllerMapper.asset b/Assets/ControllerMapper.asset index 3c8be40..53b355f 100644 Binary files a/Assets/ControllerMapper.asset and b/Assets/ControllerMapper.asset differ diff --git a/Assets/Scenes/PatScene.unity b/Assets/Scenes/PatScene.unity index 9a4d869..8ab48f9 100644 Binary files a/Assets/Scenes/PatScene.unity and b/Assets/Scenes/PatScene.unity differ diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 9f92da9..9cf7ac2 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -7,14 +7,28 @@ public class Child : MonoBehaviour public float Speed = 10f; public float JumpForce = 10f; public GameObject GroundCheck; + public Pillow pillow; private Rigidbody _rb; private bool _isGrounded = false; private float _xValue; private float _zValue; - public Pillow pillow; + private bool _isSleeping; public Transform target; + private int _index; + + public int Index + { + get { return _index; } + set { _index = value; } + } + + + public bool IsSleeping + { + get { return _isSleeping; } + } void Awake() { @@ -29,11 +43,8 @@ public class Child : MonoBehaviour if (target != null) { transform.LookAt(target); } - - //Debug.Log(_isGrounded); } - void OnTriggerEnter(Collider other) { if (other.tag == "Pillow") { @@ -64,7 +75,9 @@ public class Child : MonoBehaviour private bool IsGrounded() { - Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, 1 << LayerMask.NameToLayer("Ground")); + int mask = (1 << LayerMask.NameToLayer("Ground")) | (1 << LayerMask.NameToLayer("Bed")); + + Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, mask); return colliders.Length > 0; } @@ -84,4 +97,32 @@ public class Child : MonoBehaviour _rb.AddForce(new Vector3(0f, JumpForce, 0f)); } } + + public bool Sleep() + { + _isSleeping = IsOnBed(); + + // Temporary (only for visual cue until we get the animation) + if (_isSleeping) + { + transform.localEulerAngles = new Vector3(90f, transform.localEulerAngles.y, transform.localEulerAngles.z); + } + + return _isSleeping; + } + + public void WakeUp() + { + _isSleeping = false; + + // Temporary (only for visual cue until we get the animation) + transform.localEulerAngles = new Vector3(0f, transform.localEulerAngles.y, transform.localEulerAngles.z); + } + + private bool IsOnBed() + { + Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, 1 << LayerMask.NameToLayer("Bed")); + + return colliders.Length > 0; + } } diff --git a/Assets/Scripts/ChildController.cs b/Assets/Scripts/ChildController.cs index e555200..fca1baa 100644 --- a/Assets/Scripts/ChildController.cs +++ b/Assets/Scripts/ChildController.cs @@ -15,12 +15,13 @@ public class ChildController : MonoBehaviour void Awake() { - InputManager.Instance.PushActiveContext("Gameplay", (int)PlayerNumber); + InputManager.Instance.PushActiveContext("Awake", (int)PlayerNumber); InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerAxis); InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerButtons); _child = GetComponent(); _autoTarget = GetComponent(); + _child.Index = (int)PlayerNumber; } private void HandlePlayerAxis(MappedInput input) @@ -88,6 +89,18 @@ public class ChildController : MonoBehaviour { _child.Jump(); } + + if (input.Actions.Contains("Sleep") && _child.Sleep()) + { + Debug.Log("SLEEPING"); + InputManager.Instance.PushActiveContext("Sleeping", (int)PlayerNumber); + } + else if (input.Actions.Contains("WakeUp")) + { + Debug.Log("AWAKE"); + _child.WakeUp(); + InputManager.Instance.PushActiveContext("Awake", (int)PlayerNumber); + } } } diff --git a/Assets/Scripts/MomBehavior.cs b/Assets/Scripts/MomBehavior.cs new file mode 100644 index 0000000..4c681b7 --- /dev/null +++ b/Assets/Scripts/MomBehavior.cs @@ -0,0 +1,57 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.UI; + +public class MomBehavior : MonoBehaviour +{ + public Child[] Children; + + public Text WarningText; + public float MinTriggerTime = 60f; + public float MaxTriggerTime = 90f; + public float WarningHeadsupTime = 5f; + + private float _elapsedTime = 0f; + + private float _nextTriggerTime; + + void Awake() + { + _nextTriggerTime = GetNextTriggerTime(); + Debug.Log("NextTrigger: " + _nextTriggerTime); + } + + void Update() + { + // When the mom hasn't been triggered for a while, it can appear anytime between 2 borders + + _elapsedTime += Time.deltaTime; + + if (_elapsedTime >= _nextTriggerTime - WarningHeadsupTime && _elapsedTime < _nextTriggerTime) + { + WarningText.gameObject.SetActive(true); + } + else if (_elapsedTime >= _nextTriggerTime) + { + WarningText.gameObject.SetActive(false); + _nextTriggerTime = GetNextTriggerTime(); + + foreach (Child child in Children) + { + if (!child.IsSleeping) + { + // TODO: Do something (end the game? kill the player? make him lose 1 life? etc.) + + Debug.Log("Child " + child.Index + " got found by Mommy."); + } + } + + _elapsedTime = 0f; + } + } + + private float GetNextTriggerTime() + { + return UnityEngine.Random.Range(MinTriggerTime, MaxTriggerTime); + } +} diff --git a/Assets/Scripts/MomBehavior.cs.meta b/Assets/Scripts/MomBehavior.cs.meta new file mode 100644 index 0000000..d1165d8 --- /dev/null +++ b/Assets/Scripts/MomBehavior.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dc7c5ec2b3918f14591f5f055ded72ef +timeCreated: 1440227199 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index a8d546d..0875a70 100644 Binary files a/ProjectSettings/TagManager.asset and b/ProjectSettings/TagManager.asset differ