From af93e59d0e6e0253a56786acd7bf953951f359e0 Mon Sep 17 00:00:00 2001 From: Glence Date: Wed, 23 Nov 2022 20:26:53 +0800 Subject: [PATCH] added text to maingame --- Assets/Scenes/MainGame.shade | 312 +++++++++++------- .../Gameplay/Player/SC_PickAndThrow.cs | 29 +- Assets/Scripts/Gameplay/SC_GameManager.cs | 46 ++- .../src/Serialization/SHYAMLConverters.h | 2 +- 4 files changed, 244 insertions(+), 145 deletions(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 96235cf5..c69e8764 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8198,125 +8198,6 @@ Strength: 0.699999988 IsActive: true Scripts: ~ -- EID: 2 - Name: Player - IsActive: true - NumberOfChildren: 3 - Components: - Transform Component: - Translate: {x: 2.12735963, y: 0.362327814, z: 6.98932981} - Rotate: {x: -0, y: 0, z: -0} - Scale: {x: 0.999999881, y: 1, z: 0.999999881} - IsActive: true - Renderable Component: - Mesh: 149697411 - Material: 126974645 - IsActive: true - RigidBody Component: - Type: Dynamic - Drag: 1 - Angular Drag: 0.100000001 - Use Gravity: false - Interpolate: true - Sleeping Enabled: true - Freeze Position X: false - Freeze Position Y: true - 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.400000006, y: 0.5, z: 0.300000012} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0.25, z: 0} - Rotation Offset: {x: 0, y: 0, z: 0} - IsActive: true - Scripts: - - Type: PlayerController - Enabled: true - respawnPoint: 239 - currentState: 0 - maxMoveVel: 3 - moveForce: 50 - sprintMultiplier: 1.5 - rotationFactorPerFrame: 5 - maxJumpHeight: 1 - maxJumpTime: 0.5 - fallMultipler: 3 - lightMultiper: 0.75 - mediumMultiper: 0.5 - heavyMultiper: 0.25 - - Type: PickAndThrow - Enabled: true - throwForce: [300, 300, 300] - delayTimer: 1 - aimingLength: 0.5 -- EID: 3 - Name: HoldingPoint - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 0, y: 0.699999988, z: 0.200000003} - Rotate: {x: 0, y: 0, z: -0} - Scale: {x: 1, y: 1, z: 1} - IsActive: true - Scripts: ~ -- EID: 4 - Name: PlayerCamera - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 0, y: 0, z: 0} - Rotate: {x: 0, y: 6.28318548, z: 2.23517329e-08} - Scale: {x: 1, y: 1, z: 1} - IsActive: true - Camera Component: - Position: {x: 2.12735963, y: 0.362327814, z: 7.98932981} - Pitch: 0 - Yaw: 360 - Roll: 1.28065994e-06 - Width: 1920 - Height: 1080 - Near: 0.00999999978 - Far: 10000 - Perspective: true - IsActive: true - Camera Arm Component: - Arm Pitch: 0 - Arm Yaw: 0 - Arm Length: 1 - Look At Camera Origin: true - IsActive: true - Scripts: - - Type: SHADE_Scripting.ThirdPersonCamera - Enabled: true - armLength: 1 - turnSpeedPitch: 0.300000012 - turnSpeedYaw: 0.5 - pitchClamp: 45 -- EID: 9 - Name: PlayerBag - 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: 240 Name: ====ItemPool==== IsActive: true @@ -8355,7 +8236,7 @@ Colliders: - Is Trigger: false Type: Box - Half Extents: {x: 0.100000001, y: 0.100000001, z: 0.100000001} + Half Extents: {x: 0.200000003, y: 0.200000003, z: 0.200000003} Friction: 0.400000006 Bounciness: 0 Density: 1 @@ -8363,7 +8244,7 @@ Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: true Type: Box - Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012} + Half Extents: {x: 0.400000006, y: 0.400000006, z: 0.400000006} Friction: 0.400000006 Bounciness: 0 Density: 1 @@ -8425,8 +8306,8 @@ Scripts: - Type: Item Enabled: true - Score: 10 - currCategory: 0 + Score: 100 + currCategory: 2 - EID: 241 Name: Mesh_Meat IsActive: true @@ -8477,8 +8358,8 @@ Scripts: - Type: Item Enabled: true - Score: 10 - currCategory: 0 + Score: 50 + currCategory: 1 - EID: 15 Name: ====ScoreZonePool==== IsActive: true @@ -8561,6 +8442,185 @@ Scripts: - Type: ScoringZone Enabled: true +- EID: 238 + Name: ====GameManager==== + IsActive: true + NumberOfChildren: 0 + Components: ~ + Scripts: + - Type: GameManager + Enabled: true + itemPool: 240 + zonePool: 15 + winScene: 92009475 + loseScene: 91685359 + currGameState: 0 + totalItemCount: 0 + Score: 0 + timer: 100 + scoreText: 237 + timeText: 206 +- EID: 199 + Name: =====Text==== + IsActive: true + NumberOfChildren: 2 + Components: ~ + Scripts: ~ +- EID: 237 + Name: Score + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -800, y: 400, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 60, y: 60, z: 60} + IsActive: true + Text Renderer Component: + Text: My name is Brandon. + Font: 176667660 + IsActive: true + Scripts: ~ +- EID: 206 + Name: Timer + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 500, y: 400, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 60, y: 60, z: 60} + IsActive: true + Text Renderer Component: + Text: My name is Brandon. + Font: 176667660 + IsActive: true + Scripts: ~ +- EID: 198 + Name: ====Raccoon==== + IsActive: true + NumberOfChildren: 2 + Components: ~ + Scripts: ~ +- EID: 2 + Name: Player + IsActive: true + NumberOfChildren: 3 + Components: + Transform Component: + Translate: {x: 2.12735963, y: 0.362327814, z: 6.98932981} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 0.999999881, y: 1, z: 0.999999881} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + RigidBody Component: + Type: Dynamic + Drag: 1 + Angular Drag: 0.100000001 + Use Gravity: false + Interpolate: true + Sleeping Enabled: true + Freeze Position X: false + Freeze Position Y: true + 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.400000006, y: 0.5, z: 0.300000012} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.25, z: 0} + Rotation Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: + - Type: PlayerController + Enabled: true + respawnPoint: 239 + currentState: 0 + maxMoveVel: 3 + moveForce: 50 + sprintMultiplier: 1.5 + rotationFactorPerFrame: 5 + maxJumpHeight: 1 + maxJumpTime: 0.5 + fallMultipler: 3 + lightMultiper: 0.75 + mediumMultiper: 0.5 + heavyMultiper: 0.25 + - Type: PickAndThrow + Enabled: true + throwForce: [50, 50, 50] + delayTimer: 1 + aimingLength: 0.5 +- EID: 3 + Name: HoldingPoint + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0.700000048, z: 0.200000286} + Rotate: {x: 0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Scripts: ~ +- EID: 4 + Name: PlayerCamera + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -2.98023224e-08, z: 4.76837158e-07} + Rotate: {x: 0, y: 6.28318548, z: 2.23517329e-08} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Camera Component: + Position: {x: 2.12735963, y: 0.362327784, z: 7.98933029} + Pitch: 0 + Yaw: 360 + Roll: 1.28065994e-06 + Width: 1920 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + IsActive: true + Camera Arm Component: + Arm Pitch: 0 + Arm Yaw: 0 + Arm Length: 1 + Look At Camera Origin: true + IsActive: true + Scripts: + - Type: SHADE_Scripting.ThirdPersonCamera + Enabled: true + armLength: 1 + turnSpeedPitch: 0.300000012 + turnSpeedYaw: 0.5 + pitchClamp: 45 +- EID: 9 + Name: PlayerBag + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -2.98023224e-08, z: 4.76837158e-07} + 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: 239 Name: RespawnPoint IsActive: true @@ -8568,7 +8628,7 @@ Components: Transform Component: Translate: {x: 2.5, y: 0.660660267, z: 7} - Rotate: {x: -0, y: 0, z: -0} + Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true Scripts: ~ \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs index 3d2e4ffc..b9737685 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs @@ -2,6 +2,7 @@ using SHADE_Scripting; using System; using static PlayerController; +using static Item; public class PickAndThrow : Script { @@ -17,6 +18,7 @@ public class PickAndThrow : Script private RigidBody itemRidibody; private Transform raccoonHoldLocation; private Transform playerTran; + private Item itemScript; private ThirdPersonCamera tpc; private float lastXDir; private float lastZDir; @@ -59,7 +61,6 @@ public class PickAndThrow : Script if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) { - Debug.Log("AIMING"); pc.isAiming = true; pc.camArm.ArmLength = aimingLength; } @@ -73,19 +74,36 @@ public class PickAndThrow : Script pc.holdItem = false; inRange = false; itemRidibody.IsGravityEnabled = true; - itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir)); + if (itemScript) + { + Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir); + if (itemScript.currCategory == ItemCategory.LIGHT) + itemRidibody.AddForce(vec * 0.3f); + if (itemScript.currCategory == ItemCategory.MEDIUM) + itemRidibody.AddForce(vec * 0.75f); + if (itemScript.currCategory == ItemCategory.HEAVY) + itemRidibody.AddForce(vec); + } itemRidibody.LinearVelocity += pc.rb.LinearVelocity; ResetItemObject(); timer = 0.0f; } - if (Input.GetMouseButtonDown(Input.MouseCode.RightButton)) + if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && !pc.isAiming) { pc.holdItem = false; inRange = false; itemRidibody.IsGravityEnabled = true; ResetItemObject(); } + + if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && pc.isAiming) + { + pc.isAiming = false; + if (tpc) + pc.camArm.ArmLength = tpc.armLength; + } + } else if (!pc.holdItem) itemRidibody.IsGravityEnabled = true; @@ -105,6 +123,7 @@ public class PickAndThrow : Script { itemRidibody = null; itemTransform = null; + itemScript = null; item = new GameObject(); } @@ -131,6 +150,10 @@ public class PickAndThrow : Script itemTransform.LocalEulerAngles = Vector3.Zero; } + itemScript = item.GetScript(); + if(!itemScript) + Debug.Log("Item script EMPTY"); + } } diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index ff3a3160..b21bee42 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -29,20 +29,19 @@ public class GameManager : Script private IEnumerable listOfItems; private IEnumerable listOfZone; + public GameObject scoreText; + public GameObject timeText; + + private bool once = true; + + protected override void awake() { + Audio.PlayBGMOnce2D("event:/Music/player_undetected"); totalItemCount = 0; Score = 0; currGameState = GameState.START; - if (itemPool) - { - listOfItems = itemPool.GetScriptsInChildren(); - if (listOfItems != null) - foreach (Item i in listOfItems) - totalItemCount += 1; - } - if (zonePool) { listOfZone = zonePool.GetScriptsInChildren(); @@ -54,19 +53,36 @@ public class GameManager : Script protected override void update() { - if (timer > 0 && currGameState == GameState.START) + if (once) + { + if (itemPool) + { + listOfItems = itemPool.GetScriptsInChildren(); + if (listOfItems != null) + foreach (Item i in listOfItems) + totalItemCount += 1; + } + once = false; + } + + if (currGameState == GameState.START) { timer -= Time.DeltaTimeF; - if (totalItemCount <= 0) + if(scoreText) + scoreText.GetComponent().Text = $"Score: {Score}"; + if(timeText) + timeText.GetComponent().Text = $"Time Left: {timer.ToString("0.00")}"; + + if (timer > 0 && totalItemCount <= 0) { currGameState = GameState.WIN; SceneManager.ChangeScene(winScene); } - } - else - { - currGameState = GameState.LOSE; - SceneManager.ChangeScene(loseScene); + else if(timer < 0) + { + currGameState = GameState.LOSE; + SceneManager.ChangeScene(loseScene); + } } } diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index 48150d4a..e1cb8181 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -365,7 +365,7 @@ namespace YAML if (!gfxSystem) return false; - rhs.SetFont(SHResourceManager::LoadOrGet(node[TEXT_YAML_TAG.data()].as())); + rhs.SetFont(SHResourceManager::LoadOrGet(node[FONT_YAML_TAG.data()].as())); } return true; }