diff --git a/Assets/Audio/Master.bank b/Assets/Audio/Master.bank index a1b4e563..f6cce22f 100644 Binary files a/Assets/Audio/Master.bank and b/Assets/Audio/Master.bank differ diff --git a/Assets/Audio/Master.strings.bank b/Assets/Audio/Master.strings.bank index ecad89fe..d858d0f6 100644 Binary files a/Assets/Audio/Master.strings.bank and b/Assets/Audio/Master.strings.bank differ diff --git a/Assets/Audio/Music.bank b/Assets/Audio/Music.bank new file mode 100644 index 00000000..3885d5df Binary files /dev/null and b/Assets/Audio/Music.bank differ diff --git a/Assets/Audio/SFX.bank b/Assets/Audio/SFX.bank new file mode 100644 index 00000000..7a7b0bbe Binary files /dev/null and b/Assets/Audio/SFX.bank differ diff --git a/Assets/Audio/UI.bank b/Assets/Audio/UI.bank new file mode 100644 index 00000000..78ed9460 Binary files /dev/null and b/Assets/Audio/UI.bank differ diff --git a/Assets/Scenes/PlayerControllerTest.shade b/Assets/Scenes/PlayerControllerTest.shade new file mode 100644 index 00000000..01039622 --- /dev/null +++ b/Assets/Scenes/PlayerControllerTest.shade @@ -0,0 +1,454 @@ +- EID: 0 + Name: ScoreZone + IsActive: true + NumberOfChildren: 0 + Components: + Camera Component: + Position: {x: 0, y: 0, z: 0} + Pitch: 0 + Yaw: 0 + Roll: 0 + Width: 1920 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + IsActive: true + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Directional + Direction: {x: 1.79999995, y: 0, z: 1} + Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1} + Layer: 4294967295 + Strength: 0 + IsActive: true + Scripts: ~ +- EID: 1 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -1.440328, y: -4.41369677, z: -5} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 49.4798889, y: 0.5, z: 17.5} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + RigidBody Component: + Type: Static + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Interpolate: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + Colliders: + - Is Trigger: false + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: ~ +- EID: 2 + Name: Player + IsActive: true + NumberOfChildren: 3 + Components: + Transform Component: + Translate: {x: -18.9007454, y: -3.67369723, z: -5.23871422} + Rotate: {x: -0, y: 0, z: 0} + Scale: {x: 2, y: 2, z: 2} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + RigidBody Component: + Type: Dynamic + Mass: 1 + Drag: 2 + Angular Drag: 0 + Use Gravity: false + Interpolate: false + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: true + Freeze Rotation Y: true + Freeze Rotation Z: true + IsActive: true + Collider Component: + Colliders: + - Is Trigger: false + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + IsActive: true + Scripts: + - Type: PlayerController + currentState: 0 + maxMoveVel: 4 + moveForce: 50 + sprintMultiplier: 1.5 + rotationFactorPerFrame: 1 + maxJumpHeight: 4 + maxJumpTime: 0.75 + fallMultipler: 2 + lightMultiper: 0.75 + mediumMultiper: 0.5 + heavyMultiper: 0.25 + - Type: PickAndThrow + holdPosition: [0, 1.20000005, 0] + throwForce: [200, 300, 200] +- EID: 3 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 1.20000005, z: 0} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Scripts: ~ +- EID: 4 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: -0.785401046, y: 1.65799224, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Camera Component: + Position: {x: -18.9007454, y: -3.67369723, z: -5.23871422} + Pitch: -45.000164 + Yaw: 94.9959564 + Roll: 0 + Width: 1920 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + IsActive: true + Scripts: + - Type: SHADE_Scripting.ThirdPersonCamera + armLength: 2 + turnSpeedPitch: 0.300000012 + turnSpeedYaw: 0.5 + pitchClamp: 45 +- EID: 9 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 144838771 + Material: 123745521 + IsActive: true + Scripts: ~ +- EID: 6 + Name: AI + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -8, y: -4.42369843, z: 2.5} + Rotate: {x: -0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + RigidBody Component: + Type: Dynamic + Mass: 1 + Drag: 0 + Angular Drag: 0 + Use Gravity: true + Interpolate: false + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: true + Freeze Rotation Y: true + Freeze Rotation Z: true + IsActive: true + Collider Component: + Colliders: + - Is Trigger: false + Type: Box + Half Extents: {x: 0.5, y: 0.5, z: 0.5} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + IsActive: true + Scripts: ~ +- EID: 7 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -16.8647861, z: -14.039052} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + Scripts: ~ +- EID: 8 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Ambient + Direction: {x: 0, y: 0, z: 1} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 0.25 + IsActive: true + Scripts: ~ +- EID: 11 + Name: GameManager + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + RigidBody Component: + Type: Static + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Interpolate: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + Colliders: ~ + IsActive: true + Scripts: + - Type: GameManager + itemPool: 12 + zonePool: 51000 + currGameState: 0 + totalItemCount: -202 + Score: 204 + timer: 0 +- EID: 12 + Name: ItemPool + IsActive: true + NumberOfChildren: 2 + Components: ~ + Scripts: ~ +- EID: 10 + Name: item + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 3.19870043, y: -3.67369723, z: -5} + Rotate: {x: -0, y: 0, z: 0} + Scale: {x: 2, y: 2, z: 2} + IsActive: true + Renderable Component: + Mesh: 144838771 + Material: 123745521 + IsActive: true + RigidBody Component: + Type: Dynamic + Mass: 1 + Drag: 0 + Angular Drag: 0 + Use Gravity: true + Interpolate: false + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: true + Freeze Rotation Y: true + Freeze Rotation Z: true + IsActive: true + Collider Component: + Colliders: + - Is Trigger: false + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + - Is Trigger: true + Type: Box + Half Extents: {x: 2, y: 2, z: 2} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + IsActive: true + Scripts: + - Type: Item + Score: 1 + currCategory: 0 +- EID: 5 + Name: item + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -20.6163979, y: -0.0419634879, z: -5.08873653} + Rotate: {x: -0, y: 0, z: 0} + Scale: {x: 2, y: 2, z: 2} + IsActive: false + Renderable Component: + Mesh: 144838771 + Material: 123745521 + IsActive: false + RigidBody Component: + Type: Dynamic + Mass: 1 + Drag: 0 + Angular Drag: 0 + Use Gravity: true + Interpolate: false + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: true + Freeze Rotation Y: true + Freeze Rotation Z: true + IsActive: false + Collider Component: + Colliders: + - Is Trigger: false + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + - Is Trigger: true + Type: Box + Half Extents: {x: 2, y: 2, z: 2} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + IsActive: false + Scripts: + - Type: Item + Score: 1 + currCategory: 0 +- EID: 15 + Name: ScoreZonePool + IsActive: true + NumberOfChildren: 2 + Components: ~ + Scripts: ~ +- EID: 13 + Name: ScoreZone + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -24.5947151, y: -3.15127993, z: -3.29243231} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + RigidBody Component: + Type: Static + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Interpolate: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + Colliders: + - Is Trigger: true + Type: Box + Half Extents: {x: 1, y: 20, z: 20} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: ~ +- EID: 14 + Name: ScoreZone + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -6.64785767, y: 0, z: -14.217104} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + RigidBody Component: + Type: Static + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Interpolate: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + Colliders: + - Is Trigger: true + Type: Box + Half Extents: {x: 20, y: 20, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/PlayerControllerTest.shade.shmeta b/Assets/Scenes/PlayerControllerTest.shade.shmeta new file mode 100644 index 00000000..3d9787c8 --- /dev/null +++ b/Assets/Scenes/PlayerControllerTest.shade.shmeta @@ -0,0 +1,3 @@ +Name: PlayerControllerTest +ID: 92100024 +Type: 5 diff --git a/Assets/Scripts/SC_GameManager.cs b/Assets/Scripts/SC_GameManager.cs new file mode 100644 index 00000000..743827ed --- /dev/null +++ b/Assets/Scripts/SC_GameManager.cs @@ -0,0 +1,62 @@ +using SHADE; +using System; +using System.Collections.Generic; + +public class GameManager : Script +{ + public enum GameState + { + MAINMENU, + WIN, + LOSE, + TOTAL + } + + public GameObject itemPool; + public GameObject zonePool; + public GameState currGameState; + + [NonSerialized] + public int totalItemCount; + [NonSerialized] + public int Score; + [NonSerialized] + public float timer; + + private IEnumerable listOfItems; + private IEnumerable listOfZone; + + protected override void awake() + { + totalItemCount = 0; + Score = 0; + currGameState = GameState.MAINMENU; + + if (itemPool) + { + listOfItems = itemPool.GetScriptsInChildren(); + foreach (Item i in listOfItems) + totalItemCount += 1; + } + + if (zonePool) + { + listOfZone = itemPool.GetScriptsInChildren(); + foreach (ScoringZone i in listOfZone) + i.gameManger = Owner.GetScript(); + } + } + + protected override void update() + { + if (timer > 0) + timer -= Time.DeltaTimeF; + else + currGameState = GameState.LOSE; + } + + protected override void onTriggerEnter(CollisionInfo info) + { + } + +} diff --git a/Assets/Scripts/SC_GameManager.cs.shmeta b/Assets/Scripts/SC_GameManager.cs.shmeta new file mode 100644 index 00000000..6082d6fe --- /dev/null +++ b/Assets/Scripts/SC_GameManager.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_GameManager +ID: 161629605 +Type: 9 diff --git a/Assets/Scripts/Item.cs b/Assets/Scripts/SC_Item.cs similarity index 67% rename from Assets/Scripts/Item.cs rename to Assets/Scripts/SC_Item.cs index 5047a241..cb2a5d32 100644 --- a/Assets/Scripts/Item.cs +++ b/Assets/Scripts/SC_Item.cs @@ -9,9 +9,16 @@ public class Item : Script HEAVY } + public int Score = 10; + public ItemCategory currCategory; protected override void awake() { } + + protected override void onTriggerEnter(CollisionInfo info) + { + } + } \ No newline at end of file diff --git a/Assets/Scripts/SC_Item.cs.shmeta b/Assets/Scripts/SC_Item.cs.shmeta new file mode 100644 index 00000000..2503da21 --- /dev/null +++ b/Assets/Scripts/SC_Item.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_Item +ID: 153136539 +Type: 9 diff --git a/Assets/Scripts/PickAndThrow.cs b/Assets/Scripts/SC_PickAndThrow.cs similarity index 78% rename from Assets/Scripts/PickAndThrow.cs rename to Assets/Scripts/SC_PickAndThrow.cs index ec8846c5..15edd302 100644 --- a/Assets/Scripts/PickAndThrow.cs +++ b/Assets/Scripts/SC_PickAndThrow.cs @@ -4,8 +4,9 @@ using static PlayerController; public class PickAndThrow : Script { + public Vector3 holdPosition = new Vector3(0.0f, 1.0f, 0.0f); public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f); - public GameObject item; + public GameObject item { get; set; } private PlayerController pc; private Camera cam; private Transform itemTransform; @@ -22,36 +23,13 @@ public class PickAndThrow : Script if (raccoonHoldLocation == null) Debug.Log("CHILD EMPTY"); else - raccoonHoldLocation.LocalPosition = new Vector3(0.0f, 1.0f, 0.0f); + raccoonHoldLocation.LocalPosition = holdPosition; } protected override void update() { - if (cam == null) - cam = GetComponentInChildren(); - else if (cam != null) - { - Vector3 camerAixs = cam.GetForward(); - camerAixs.y = 0; - camerAixs.Normalise(); - lastXDir = camerAixs.x; - lastZDir = camerAixs.z; - } + CalculateDir(); - if (item.GetScript() != null && itemTransform == null && itemRidibody == null) - { - itemTransform = item.GetComponent(); - if (itemTransform == null) - Debug.Log("Item transform EMPTY"); - - itemRidibody = item.GetComponent(); - if (itemRidibody == null) - Debug.Log("Item rb EMPTY"); - } - - if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E)) - pc.holdItem = true; - - if (pc != null && itemRidibody != null && itemTransform != null && pc.holdItem) + if (pc != null && pc.holdItem && itemRidibody != null && itemTransform != null) { itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition; itemRidibody.IsGravityEnabled = false; @@ -65,17 +43,60 @@ public class PickAndThrow : Script itemRidibody.IsGravityEnabled = true; itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir)); itemRidibody.LinearVelocity += pc.rb.LinearVelocity; + ResetItemObject(); } } else if(!pc.holdItem && itemRidibody != null) itemRidibody.IsGravityEnabled = true; + + if (pc != null && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) + { + pc.holdItem = true; + RetrieveItemComponets(); + } } + + private void ResetItemObject() + { + itemRidibody = null; + itemTransform = null; + item = new GameObject(); + } + + private void RetrieveItemComponets() + { + //get the transform of the given item + if (item.GetScript() != null && itemTransform == null && itemRidibody == null) + { + itemTransform = item.GetComponent(); + if (itemTransform == null) + Debug.Log("Item transform EMPTY"); + + itemRidibody = item.GetComponent(); + if (itemRidibody == null) + Debug.Log("Item rb EMPTY"); + } + } + + private void CalculateDir() + { + if (cam == null) + cam = GetComponentInChildren(); + else if (cam != null) + { + Vector3 camerAixs = cam.GetForward(); + camerAixs.y = 0; + camerAixs.Normalise(); + lastXDir = camerAixs.x; + lastZDir = camerAixs.z; + } + } + protected override void onCollisionEnter(CollisionInfo info) { } protected override void onTriggerEnter(CollisionInfo info) { - //Debug.Log("ENTER"); if (info.GameObject.GetScript() != null && !pc.holdItem) { item = info.GameObject; diff --git a/Assets/Scripts/SC_PickAndThrow.cs.shmeta b/Assets/Scripts/SC_PickAndThrow.cs.shmeta new file mode 100644 index 00000000..5703d6d7 --- /dev/null +++ b/Assets/Scripts/SC_PickAndThrow.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_PickAndThrow +ID: 154802724 +Type: 9 diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/SC_PlayerController.cs similarity index 61% rename from Assets/Scripts/PlayerController.cs rename to Assets/Scripts/SC_PlayerController.cs index 4a02d470..189622ac 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/SC_PlayerController.cs @@ -1,40 +1,47 @@ using SHADE; using System; +using System.Collections.Generic; using static Item; public class PlayerController : Script { public enum RaccoonStates { - IDILE, + IDLE, WALKING, RUNNING, JUMP, FALLING, + LANDED, CAUGHT, TOTAL } + public enum WalkingState + { + CARRY, + AIMING, + THROW, + WALK, + TOTAL + } + public RigidBody rb { get; set; } private Transform tranform; private Camera cam; private PickAndThrow pat; + private StateMachine stateMachine; - //to be remove - public float drag = 2.0f; public bool holdItem { get; set; } - [SerializeField] + [Tooltip("The current state fo the raccoon")] - public RaccoonStates currentState = RaccoonStates.IDILE; + public RaccoonStates currentState = RaccoonStates.IDLE; //Movement variables============================================================ - [SerializeField] [Tooltip("Max vel for walking")] public float maxMoveVel = 2.0f; - [SerializeField] [Tooltip("how much force is apply for walking")] - public float moveForce = 50.0f; - [SerializeField] + public float moveForce = 2.0f; [Tooltip("increase the moveForce and maxMoveVel by its amt")] public float sprintMultiplier = 2.0f; @@ -49,7 +56,6 @@ public class PlayerController : Script public bool isMoveKeyPress { get; set; } - [SerializeField] [Tooltip("curr not working")] public float rotationFactorPerFrame = 1.0f; @@ -75,6 +81,7 @@ public class PlayerController : Script protected override void awake() { + Audio.PlayBGMOnce2D("event:/Music/player_undetected"); //default setup isMoveKeyPress = false; holdItem = false; @@ -91,10 +98,6 @@ public class PlayerController : Script else { rb.IsGravityEnabled = false; - rb.FreezeRotationX = true; - rb.FreezeRotationY = true; - rb.FreezeRotationZ = true; - rb.Drag = drag; rb.Interpolating = false; } @@ -103,14 +106,18 @@ public class PlayerController : Script if(tranform == null) Debug.LogError("tranform is NULL!"); - //PickAndThrow checl + //PickAndThrow check pat = GetScript(); if (pat == null) Debug.LogError("PickAndThrow is NULL!"); - //toRemove - tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f); - tranform.LocalRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); + stateMachine = AddScript(); + Dictionary dictionary = new Dictionary(); + dictionary.Add(typeof(IdleState), new IdleState(stateMachine)); + dictionary.Add(typeof(WalkState), new WalkState(stateMachine)); + dictionary.Add(typeof(RunState), new RunState(stateMachine)); + stateMachine.InitStateMachine(dictionary); + } protected override void update() @@ -118,117 +125,102 @@ public class PlayerController : Script if (cam == null) cam = GetComponentInChildren(); - //toRemove - if (Input.GetKey(Input.KeyCode.G)) - { - tranform.LocalRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); - tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f); - } - GotCaught(); - MoveKey(); - - - + //Debug.Log($"{currentState}"); + //Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}"); + //Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}"); //Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString()); } protected override void fixedUpdate() { //Rotation(); + + + MoveKey(); Move(); Sprint(); Jump(); Gravity(); + //Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}"); } private void MoveKey() { - /* if (Input.GetKey(Input.KeyCode.A)) - xAxisMove = -1; - else if (Input.GetKey(Input.KeyCode.D)) - xAxisMove = 1; - else - xAxisMove = 0; - - if (Input.GetKey(Input.KeyCode.W)) - zAxisMove = -1; - else if (Input.GetKey(Input.KeyCode.S)) - zAxisMove = 1; - else - zAxisMove = 0;*/ - - - xAxisMove = 0; - zAxisMove = 0; axisMove = Vector2.Zero; if (Input.GetKey(Input.KeyCode.W)) { Vector3 camerAixs = cam.GetForward(); camerAixs.y = 0; camerAixs.Normalise(); - xAxisMove = camerAixs.x; - zAxisMove = camerAixs.z; axisMove += new Vector2(camerAixs.x, camerAixs.z); } + if (Input.GetKey(Input.KeyCode.S)) { Vector3 camerAixs = cam.GetForward(); camerAixs.y = 0; camerAixs.Normalise(); - xAxisMove = -camerAixs.x; - zAxisMove = -camerAixs.z; axisMove -= new Vector2(camerAixs.x, camerAixs.z); } + if (Input.GetKey(Input.KeyCode.A)) { Vector3 camerAixs = cam.GetRight(); camerAixs.y = 0; camerAixs.Normalise(); - xAxisMove = -camerAixs.x; - zAxisMove = -camerAixs.z; axisMove -= new Vector2(camerAixs.x, camerAixs.z); } + if (Input.GetKey(Input.KeyCode.D)) { Vector3 camerAixs = cam.GetRight(); camerAixs.y = 0; camerAixs.Normalise(); - xAxisMove = camerAixs.x; - zAxisMove = camerAixs.z; axisMove += new Vector2(camerAixs.x, camerAixs.z); } - axisMove.Normalise(); - isMoveKeyPress = xAxisMove != 0 || zAxisMove != 0; - if(isMoveKeyPress && currentState != RaccoonStates.RUNNING && isGrounded) + axisMove.Normalise(); + isMoveKeyPress = axisMove.x != 0 || axisMove.y != 0; + + if (isMoveKeyPress && isGrounded && !Input.GetKey(Input.KeyCode.LeftShift)) + { currentState = RaccoonStates.WALKING; + if(stateMachine && !stateMachine.IsState(typeof(WalkState))) + stateMachine.SetState(typeof(WalkState)); + } + if (!isMoveKeyPress && isGrounded) - currentState = RaccoonStates.IDILE; + { + currentState = RaccoonStates.IDLE; + + if(stateMachine && !stateMachine.IsState(typeof(IdleState))) + stateMachine.SetState(typeof(IdleState)); + } } private void Move() { if (rb != null) { - rb.AddForce(new Vector3(axisMove.x, 0.0f,axisMove.y) * moveForce); + rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF; if (isMoveKeyPress) { - if (rb.LinearVelocity.x > maxMoveVel || rb.LinearVelocity.x < -maxMoveVel) + if (rb) { - Vector3 v = rb.LinearVelocity; - v.x = System.Math.Clamp(v.x, -maxMoveVel, maxMoveVel); - rb.LinearVelocity = v; - } - if (rb.LinearVelocity.z > maxMoveVel || rb.LinearVelocity.z < -maxMoveVel) - { - Vector3 v = rb.LinearVelocity; - v.z = System.Math.Clamp(v.z, -maxMoveVel, maxMoveVel); - rb.LinearVelocity = v; + Vector3 velNor = rb.LinearVelocity; + velNor.y = 0.0f; + if (velNor.GetMagnitude() > maxMoveVel) + { + velNor.Normalise(); + velNor *= maxMoveVel; + rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z); + } } + } } } @@ -238,6 +230,9 @@ public class PlayerController : Script if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded) { currentState = RaccoonStates.RUNNING; + if (stateMachine && !stateMachine.IsState(typeof(RunState))) + stateMachine.SetState(typeof(RunState)); + holdItem = false; if (!sprintIncreaseOnce) { @@ -252,8 +247,12 @@ public class PlayerController : Script if (Input.GetKeyUp(Input.KeyCode.LeftShift)) { - if(isMoveKeyPress) + if (isMoveKeyPress) + { currentState = RaccoonStates.WALKING; + if(stateMachine && !stateMachine.IsState(typeof(WalkState))) + stateMachine.SetState(typeof(WalkState)); + } sprintIncreaseOnce = false; moveForce = oldForce; maxMoveVel = maxOldVel; @@ -263,37 +262,38 @@ public class PlayerController : Script //press and hold jump private void Jump() { - if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE) + if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE) { if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null) { currentState = RaccoonStates.JUMP; Vector3 v = rb.LinearVelocity; v.y = initialJumpVel * 0.5f; - if (pat != null && pat.item.GetScript() != null && holdItem) + if (holdItem && pat != null && pat.item.GetScript() != null) { Item item = pat.item.GetScript(); - if (item.currCategory == ItemCategory.LIGHT) + if (item != null && item.currCategory == ItemCategory.LIGHT) v.y *= lightMultiper; - if (item.currCategory == ItemCategory.MEDIUM) + if (item != null && item.currCategory == ItemCategory.MEDIUM) v.y *= mediumMultiper; - if (item.currCategory == ItemCategory.HEAVY) + if (item != null && item.currCategory == ItemCategory.HEAVY) v.y *= heavyMultiper; } rb.LinearVelocity = v; } } - if(rb != null && !isGrounded && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space))) + if(!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space))) currentState = RaccoonStates.FALLING; + } private void Rotation() { Vector3 poitionToLookAt; - poitionToLookAt.x = xAxisMove; + poitionToLookAt.x = axisMove.x; poitionToLookAt.y = 0.0f; - poitionToLookAt.z = zAxisMove; + poitionToLookAt.z = axisMove.y; if (tranform != null) { @@ -312,7 +312,11 @@ public class PlayerController : Script { //check player vel.y if its close to zero its on the ground if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f)) + { isGrounded = true; + if (currentState == RaccoonStates.FALLING) + currentState = RaccoonStates.LANDED; + } else isGrounded = false; @@ -344,7 +348,9 @@ public class PlayerController : Script { if (currentState == RaccoonStates.CAUGHT && tranform != null) { - currentState = RaccoonStates.IDILE; + currentState = RaccoonStates.IDLE; + if (stateMachine && !stateMachine.IsState(typeof(IdleState))) + stateMachine.SetState(typeof(IdleState)); tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f); } } @@ -353,6 +359,82 @@ public class PlayerController : Script { } +} + +public class WalkState : BaseState +{ + public WalkState(StateMachine stateMachine) : base(stateMachine) + { + stateName = "Walk State"; + } + public override void OnEnter() + { + //Debug.Log("WALK ENTER"); + } + public override void update() + { + //Debug.Log("WALKING"); + } + public override void fixedUpdate() + { + //Debug.Log("FIXED WALKING"); + } + public override void OnExit() + { + //Debug.Log("WALK EXIT"); + } + public override void onTriggerEnter(CollisionInfo info) + { + //Debug.Log("TRIGGER"); + } } +public class RunState : BaseState +{ + public RunState(StateMachine stateMachine) : base(stateMachine) + { + stateName = "Run State"; + } + public override void OnEnter() + { + //Debug.Log("Run ENTER"); + } + public override void update() + { + //Debug.Log("RUNING"); + } + public override void fixedUpdate() + { + //Debug.Log("FIXED RUNNING"); + } + public override void OnExit() + { + //Debug.Log("Run EXIT"); + } +} + +public class IdleState : BaseState +{ + public IdleState(StateMachine stateMachine) : base(stateMachine) + { + stateName = "Idle State"; + } + public override void OnEnter() + { + //Debug.Log("IDLE ENTER"); + } + public override void update() + { + //Debug.Log("IDLING"); + } + public override void fixedUpdate() + { + //Debug.Log("FIXED IDLING"); + } + public override void OnExit() + { + //Debug.Log("IDLE EXIT"); + } +} + diff --git a/Assets/Scripts/SC_PlayerController.cs.shmeta b/Assets/Scripts/SC_PlayerController.cs.shmeta new file mode 100644 index 00000000..445af934 --- /dev/null +++ b/Assets/Scripts/SC_PlayerController.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_PlayerController +ID: 160432754 +Type: 9 diff --git a/Assets/Scripts/SC_ScoringZone.cs b/Assets/Scripts/SC_ScoringZone.cs new file mode 100644 index 00000000..849f3e1c --- /dev/null +++ b/Assets/Scripts/SC_ScoringZone.cs @@ -0,0 +1,21 @@ +using SHADE; +using System; +public class ScoringZone : Script +{ + public GameManager gameManger { get; set; } + + protected override void awake() + { + } + + protected override void onTriggerEnter(CollisionInfo info) + { + if (gameManger && info.GameObject.GetScript()) + { + gameManger.Score += info.GameObject.GetScript().Score; + gameManger.totalItemCount -= 1; + info.GameObject.SetActive(false); + } + } + +} \ No newline at end of file diff --git a/Assets/Scripts/SC_ScoringZone.cs.shmeta b/Assets/Scripts/SC_ScoringZone.cs.shmeta new file mode 100644 index 00000000..51ef171b --- /dev/null +++ b/Assets/Scripts/SC_ScoringZone.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_ScoringZone +ID: 153171688 +Type: 9 diff --git a/Assets/Scripts/UT_BaseSate.cs b/Assets/Scripts/UT_BaseSate.cs new file mode 100644 index 00000000..521f5936 --- /dev/null +++ b/Assets/Scripts/UT_BaseSate.cs @@ -0,0 +1,68 @@ +using SHADE; +using System; + +public abstract class BaseState +{ + + protected string stateName = "Base State"; + protected StateMachine machine; + protected string animationName = ""; + + public BaseState(StateMachine stateMachine, string animName = "") + { + machine = stateMachine; + animationName = animName; + } + + public virtual void OnEnter() + { + } + + public abstract void update(); + + public abstract void fixedUpdate(); + + public virtual void OnExit() + { + + } + + public string GetStateName() + { + return stateName; + } + + public string GetAnimName() + { + return animationName; + } + + public virtual float GetAnimPercent() + { + return 1.0f; + } + + public virtual void onCollisionEnter(CollisionInfo info) + { + } + + public virtual void onCollisionStay(CollisionInfo info) + { + } + + public virtual void onCollisionExit(CollisionInfo info) + { + } + + public virtual void onTriggerEnter(CollisionInfo info) + { + } + + public virtual void onTriggerStay(CollisionInfo info) + { + } + + public virtual void onTriggerExit(CollisionInfo info) + { + } +} diff --git a/Assets/Scripts/UT_BaseSate.cs.shmeta b/Assets/Scripts/UT_BaseSate.cs.shmeta new file mode 100644 index 00000000..49e62af3 --- /dev/null +++ b/Assets/Scripts/UT_BaseSate.cs.shmeta @@ -0,0 +1,3 @@ +Name: UT_BaseSate +ID: 154709755 +Type: 9 diff --git a/Assets/Scripts/UT_StateMachine.cs b/Assets/Scripts/UT_StateMachine.cs new file mode 100644 index 00000000..aa3cfd72 --- /dev/null +++ b/Assets/Scripts/UT_StateMachine.cs @@ -0,0 +1,126 @@ +using SHADE; +using System; +using System.Collections.Generic; +using System.Linq; + +public class StateMachine : Script +{ + private Dictionary stateDictionary; + public BaseState currentState = null; + public string currentStateName; + public string currentAnimName; + + public void InitStateMachine(Dictionary dictionary) + { + + stateDictionary = dictionary; + currentState = stateDictionary.First().Value; + currentStateName = currentState.GetStateName(); + currentAnimName = currentState.GetAnimName(); + currentState.OnEnter(); + } + + public bool HasState(Type type) + { + if (!type.IsSubclassOf(typeof(BaseState))) + { + return false; + } + else + { + return stateDictionary.ContainsKey(type); + } + } + + public void SetState(Type type) + { + if (!type.IsSubclassOf(typeof(BaseState))) + { + return; + } + + + if (stateDictionary.ContainsKey(type)) + { + currentState.OnExit(); + currentState = stateDictionary[type]; + currentState.OnEnter(); + } + else + { + SetState(stateDictionary.First().Key); + } + } + + public BaseState GetState(Type type) + { + if (!stateDictionary.ContainsKey(type)) + return null; + + return stateDictionary[type]; + } + public bool IsState(Type type) + { + return (currentState.GetType() == type); + } + + protected override void update() + { + if (currentState != (null)) + { + currentStateName = currentState.GetStateName(); + currentAnimName = currentState.GetAnimName(); + currentState.update(); + } + + } + + protected override void fixedUpdate() + { + if (currentState != (null)) + { + currentStateName = currentState.GetStateName(); + currentAnimName = currentState.GetAnimName(); + currentState.fixedUpdate(); + } + } + + protected override void onCollisionEnter(CollisionInfo info) + { + if (currentState != (null)) + currentState.onCollisionEnter(info); + } + + protected override void onCollisionStay(CollisionInfo info) + { + if (currentState != (null)) + currentState.onCollisionStay(info); + } + + protected override void onCollisionExit(CollisionInfo info) + { + if (currentState != (null)) + currentState.onCollisionExit(info); + } + + protected override void onTriggerEnter(CollisionInfo info) + { + if (currentState != (null)) + currentState.onTriggerEnter(info); + } + + protected override void onTriggerStay(CollisionInfo info) + { + if (currentState != (null)) + currentState.onTriggerStay(info); + } + + protected override void onTriggerExit(CollisionInfo info) + { + if (currentState != (null)) + currentState.onTriggerExit(info); + } + + +} + diff --git a/Assets/Scripts/UT_StateMachine.cs.shmeta b/Assets/Scripts/UT_StateMachine.cs.shmeta new file mode 100644 index 00000000..3e0b1dee --- /dev/null +++ b/Assets/Scripts/UT_StateMachine.cs.shmeta @@ -0,0 +1,3 @@ +Name: UT_StateMachine +ID: 166010611 +Type: 9 diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp index c913030b..e98d895a 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp @@ -84,12 +84,32 @@ namespace SHADE LoadBank((AUDIO_FOLDER_PATH + "Master.bank").data()); LoadBank((AUDIO_FOLDER_PATH + "Master.strings.bank").data()); //LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data()); - LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data()); + //LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data()); + LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data()); + LoadBank((AUDIO_FOLDER_PATH + "SFX.bank").data()); + LoadBank((AUDIO_FOLDER_PATH + "UI.bank").data()); //auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human"); //clip->Play(); //PlayEventOnce("event:/Characters/sfx_footsteps_raccoon"); //PlayEventOnce("event:/SFX/Dawn/Dawn_Attack"); + + #ifdef SHEDITOR + + // Subscribe to Editor State Change Events + const std::shared_ptr ON_PLAY_RECEIVER{ std::make_shared>(this, &SHAudioSystem::onPlay) }; + const ReceiverPtr ON_PLAY_RECEIVER_PTR = std::dynamic_pointer_cast(ON_PLAY_RECEIVER); + SHEventManager::SubscribeTo(SH_EDITOR_ON_PLAY_EVENT, ON_PLAY_RECEIVER_PTR); + + const std::shared_ptr ON_STOP_RECEIVER{ std::make_shared>(this, &SHAudioSystem::onStop) }; + const ReceiverPtr ON_STOP_RECEIVER_PTR = std::dynamic_pointer_cast(ON_STOP_RECEIVER); + SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, ON_STOP_RECEIVER_PTR); + + const std::shared_ptr ON_PAUSE_RECEIVER{ std::make_shared>(this, &SHAudioSystem::onPause) }; + const ReceiverPtr ON_PAUSE_RECEIVER_PTR = std::dynamic_pointer_cast(ON_PAUSE_RECEIVER); + SHEventManager::SubscribeTo(SH_EDITOR_ON_PAUSE_EVENT, ON_PAUSE_RECEIVER_PTR); + + #endif } void SHADE::SHAudioSystem::Run(double dt) @@ -179,7 +199,6 @@ namespace SHADE it->second->createInstance(&event); if (event) { - event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume)); if (spatial) { @@ -285,6 +304,7 @@ namespace SHADE if (channel->isPlaying(&isPlaying) == FMOD_OK && isPlaying) channel->stop(); } + masterGroup->stop(); } std::optional SHAudioSystem::GetEventGUID(const char* path) @@ -410,6 +430,7 @@ namespace SHADE void SHAudioSystem::SetPaused(bool pause) { paused = pause; + masterGroup->setPaused(pause); for (auto const& channel : audioChannels) { channel->setPaused(paused); @@ -552,6 +573,27 @@ namespace SHADE return value; } + SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent) + { + StopAllSounds(); + + return onStopEvent->handle; + } + + SHEventHandle SHAudioSystem::onPause(SHEventPtr onStopEvent) + { + SetPaused(true); + + return onStopEvent->handle; + } + SHEventHandle SHAudioSystem::onPlay(SHEventPtr onStopEvent) + { + if(GetPaused()) + SetPaused(false); + + return onStopEvent->handle; + } + } #pragma warning(pop) diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.h b/SHADE_Engine/src/AudioSystem/SHAudioSystem.h index 7196b40d..777334e6 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.h +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.h @@ -10,6 +10,8 @@ #include "Math/Vector/SHVec3.h" #include #include +#include "Events/SHEvent.h" + #include "SH_API.h" #define AUDIO_SYS_MAX_CHANNELS 1024 @@ -104,6 +106,10 @@ namespace SHADE std::vector* denseListener; AudioClipID clipID = 0; + + SHEventHandle onPlay(SHEventPtr onStopEvent); + SHEventHandle onStop(SHEventPtr onStopEvent); + SHEventHandle onPause(SHEventPtr onStopEvent); }; } diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index 3a5a15b5..655ad68a 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -21,6 +21,7 @@ #include "UI/SHUIComponent.h" #include "UI/SHCanvasComponent.h" #include "SHEditorComponentView.h" +#include "AudioSystem/SHAudioListenerComponent.h" namespace SHADE { @@ -130,7 +131,8 @@ namespace SHADE if (auto cameraComponent = SHComponentManager::GetComponent_s(eid)) { DrawComponent(cameraComponent); - }if (auto cameraArmComponent = SHComponentManager::GetComponent_s(eid)) + } + if (auto cameraArmComponent = SHComponentManager::GetComponent_s(eid)) { DrawComponent(cameraArmComponent); }