Potential fix for incorrect collision states #350

Merged
direnbharwani merged 5 commits from SP3-2-Physics into main 2023-02-04 15:20:14 +08:00
31 changed files with 1260 additions and 734 deletions
Showing only changes of commit 385b34fea4 - Show all commits

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false Start in Fullscreen: false
Starting Scene ID: 97086054 Starting Scene ID: 86098106
Window Size: {x: 1920, y: 1080} Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine Window Title: SHADE Engine

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,10 +1,10 @@
0 1 0000000000000000 0 StaticObject 1110000000000000
1 2 0000000000000000 1 Player 1100000000000000
2 3 0000000000000000 2 Food 1000000000000000
3 4 0000000000000000 3 Breakable 1100000000000000
4 5 0000000000000000 4 ScoringWallCollider 0110000000000000
5 6 0000000000000000 5 Homeowner 1100000000000000
6 7 0000000000000000 6 Camera 0010000000000000
7 8 0000000000000000 7 8 0000000000000000
8 9 0000000000000000 8 9 0000000000000000
9 10 0000000000000000 9 10 0000000000000000

View File

@ -1,4 +1,4 @@
Start Maximized: true Start Maximized: true
Working Scene ID: 91685359 Working Scene ID: 86098106
Window Size: {x: 1920, y: 1013} Window Size: {x: 1920, y: 1013}
Style: 0 Style: 0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,9 @@
Mesh: 141771688 Mesh: 141771688
Material: 129138332 Material: 129138332
IsActive: true IsActive: true
UI Component:
Canvas ID: 1
IsActive: true
Scripts: ~ Scripts: ~
- EID: 5 - EID: 5
Name: Main Menu Button Name: Main Menu Button
@ -56,6 +59,9 @@
Hovered Texture: 55999018 Hovered Texture: 55999018
Clicked Texture: 66382894 Clicked Texture: 66382894
IsActive: true IsActive: true
UI Component:
Canvas ID: 1
IsActive: true
Scripts: Scripts:
- Type: ChangeSceneButton - Type: ChangeSceneButton
Enabled: true Enabled: true
@ -79,6 +85,9 @@
Hovered Texture: 65045286 Hovered Texture: 65045286
Clicked Texture: 58607560 Clicked Texture: 58607560
IsActive: true IsActive: true
UI Component:
Canvas ID: 1
IsActive: true
Scripts: Scripts:
- Type: QuitButton - Type: QuitButton
Enabled: true Enabled: true

View File

@ -0,0 +1,23 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.Audio
{
public static class AudioHandler
{
public static Dictionary<string, AudioClipHandler> audioClipHandlers = new Dictionary<string, AudioClipHandler>();
//Functions here, maybe
public static void stopAllSounds(bool fadeOut)
{
foreach (KeyValuePair<string, AudioClipHandler> h in audioClipHandlers)
{
h.Value.Stop(fadeOut);
}
}
}
}

View File

@ -0,0 +1,3 @@
Name: AudioHandler
ID: 159235425
Type: 9

View File

@ -14,6 +14,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -99,6 +100,17 @@ public partial class Homeowner1 : BehaviourTree
SetData("turningSpeed", turningSpeed); SetData("turningSpeed", turningSpeed);
SetData("distanceToCapture", distanceToCapture); SetData("distanceToCapture", distanceToCapture);
SetData("baseCaptureTime", captureTime);*/ SetData("baseCaptureTime", captureTime);*/
//These should be somewhere else
//Debug.Log("TESTING");
AudioHandler.audioClipHandlers["BGMUnalert"] = Audio.CreateAudioClip("event:/Music/player_undetected");
AudioHandler.audioClipHandlers["BGMAlert"] = Audio.CreateAudioClip("event:/Music/player_detected");
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["SFXFootstep"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
AudioHandler.audioClipHandlers["SFXDetectAh"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_detect_raccoon");
AudioHandler.audioClipHandlers["SFXDetectSting"] = Audio.CreateAudioClip("event:/Music/stingers/player_detected");
} }
//Called every tick //Called every tick
@ -132,7 +144,6 @@ public partial class Homeowner1 : BehaviourTree
if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime) if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime)
SetData("baseCaptureTime", captureTime); SetData("baseCaptureTime", captureTime);
events.Tick(); events.Tick();
//Footsteps SFX, move them somewhere else soon //Footsteps SFX, move them somewhere else soon
@ -141,7 +152,8 @@ public partial class Homeowner1 : BehaviourTree
footstepTimeRemaining -= velocity * Time.DeltaTimeF; footstepTimeRemaining -= velocity * Time.DeltaTimeF;
if (footstepTimeRemaining < 0.0f) if (footstepTimeRemaining < 0.0f)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_footsteps"); //Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_footsteps");
//AudioHandler.audioClipHandlers["SFXFootstep"].Play();
footstepTimeRemaining = footstepSFXIntervalMultiplier; footstepTimeRemaining = footstepSFXIntervalMultiplier;
} }
//Debug.Log("Ticked"); //Debug.Log("Ticked");

View File

@ -11,6 +11,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -111,7 +112,9 @@ public partial class LeafChase : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/humming"); //AudioHandler.audioClipHandlers["BGMAdpative"].SetParameter("Detected", 0.0f);
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);

View File

@ -11,6 +11,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -239,9 +240,12 @@ public partial class LeafPatrol : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert")) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert"))
{ {
//Debug.Log("Unalert"); //Debug.Log("Unalert");
Audio.PlaySFXOnce2D("event:/Homeowner/humming"); //AudioHandler.audioClipHandlers["BGMAlert"].Stop(true);
Audio.StopAllSounds(); //Audio.PlaySFXOnce2D("event:/Homeowner/humming");
Audio.PlayBGMOnce2D("event:/Music/player_undetected"); AudioHandler.audioClipHandlers["SFXHumming"].Play();
//AudioHandler.audioClipHandlers["BGMUnalert"].Play();
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
Audio.SetParameter("Detected", 0.0f);
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);
} }

View File

@ -11,6 +11,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -65,7 +66,9 @@ public partial class LeafSearch : BehaviourTreeNode
{ {
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/humming"); //AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
reevaluateWaypoint(); reevaluateWaypoint();
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);
@ -185,19 +188,27 @@ public partial class LeafSearch : BehaviourTreeNode
if (GetNodeData("isAlert") == null) if (GetNodeData("isAlert") == null)
{ {
SetNodeData("isAlert", true); SetNodeData("isAlert", true);
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon"); //Audio.StopAllSounds();
Audio.PlaySFXOnce2D("event:/Music/stingers/player_detected"); AudioHandler.audioClipHandlers["SFXDetectAh"].Play();
Audio.StopAllSounds(); AudioHandler.audioClipHandlers["SFXDetectSting"].Play();
Audio.PlayBGMOnce2D("event:/Music/player_detected"); //AudioHandler.audioClipHandlers["BGMAlert"].Play();
AudioHandler.audioClipHandlers["SFXHumming"].Stop(false);
//AudioHandler.audioClipHandlers["BGMUnalert"].Stop(true);
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 1.0f);
Audio.SetParameter("Detected", 1.0f);
} }
else else
{ {
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon"); //Audio.StopAllSounds();
Audio.PlaySFXOnce2D("event:/Music/stingers/player_detected"); AudioHandler.audioClipHandlers["SFXDetectAh"].Play();
Audio.StopAllSounds(); AudioHandler.audioClipHandlers["SFXDetectSting"].Play();
Audio.PlayBGMOnce2D("event:/Music/player_detected"); //AudioHandler.audioClipHandlers["BGMAlert"].Play();
AudioHandler.audioClipHandlers["SFXHumming"].Stop(false);
//AudioHandler.audioClipHandlers["BGMUnalert"].Stop(true);
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 1.0f);
Audio.SetParameter("Detected", 1.0f);
} }
SetNodeData("isAlert", true); SetNodeData("isAlert", true);
} }

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -12,6 +13,7 @@ public class Breakable : Script
private Transform trans; private Transform trans;
public bool isBreak { get; set; } public bool isBreak { get; set; }
private List<GameObject> itemPieces = new List<GameObject>(); private List<GameObject> itemPieces = new List<GameObject>();
public bool print = false;
protected override void awake() protected override void awake()
{ {
@ -30,6 +32,8 @@ public class Breakable : Script
} }
isBreak = false; isBreak = false;
AudioHandler.audioClipHandlers["SFXBreak"] = Audio.CreateAudioClip("event:/Props/impact_break");
} }
protected override void update() protected override void update()
@ -43,6 +47,9 @@ public class Breakable : Script
if (ignoreRaccoon && info.GameObject.GetScript<PlayerController>()) if (ignoreRaccoon && info.GameObject.GetScript<PlayerController>())
return; return;
if (print)
Debug.Log($"{info.GameObject.Name}");
if (rb.LinearVelocity.GetSqrMagnitude() > threshHold && !info.GameObject.GetScript<PlayerController>()) if (rb.LinearVelocity.GetSqrMagnitude() > threshHold && !info.GameObject.GetScript<PlayerController>())
{ {
isBreak = true; isBreak = true;
@ -68,7 +75,7 @@ public class Breakable : Script
} }
isBreak = false; isBreak = false;
Audio.PlaySFXOnce2D("event:/Props/impact_break"); AudioHandler.audioClipHandlers["SFXBreak"].Play();
GameObject.SetActive(false); GameObject.SetActive(false);
} }
} }

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
public class Item : Script public class Item : Script
{ {
@ -14,6 +15,7 @@ public class Item : Script
public ItemCategory currCategory; public ItemCategory currCategory;
public bool returnBack { get; set; } public bool returnBack { get; set; }
private Transform transform; private Transform transform;
private RigidBody rb;
private bool playSound = false; private bool playSound = false;
private bool caputurePos = false; private bool caputurePos = false;
private Vector3 firstPostion; private Vector3 firstPostion;
@ -24,11 +26,15 @@ public class Item : Script
protected override void awake() protected override void awake()
{ {
transform = GetComponent<Transform>(); transform = GetComponent<Transform>();
rb = GetComponent<RigidBody>();
collider = GetComponent<Collider>(); collider = GetComponent<Collider>();
if(collider) if(collider)
collider.GetCollisionShape(0).Density = density; collider.GetCollisionShape(0).Density = density;
returnBack = false; returnBack = false;
AudioHandler.audioClipHandlers["SFXImpactElastic"] = Audio.CreateAudioClip("event:/Props/impact_elastic");
AudioHandler.audioClipHandlers["SFXImpactHard"] = Audio.CreateAudioClip("event:/Props/impact_hard");
} }
protected override void start() protected override void start()
@ -40,7 +46,12 @@ public class Item : Script
{ {
if (returnBack && !dontReturn) if (returnBack && !dontReturn)
{ {
transform.LocalPosition = firstPostion; if(transform)
transform.LocalPosition = firstPostion;
if (rb)
rb.LinearVelocity = Vector3.Zero;
returnBack = false; returnBack = false;
} }
} }
@ -54,11 +65,11 @@ public class Item : Script
} }
if (playSound) if (playSound)
{ {
if(currCategory == ItemCategory.LIGHT) if (currCategory == ItemCategory.LIGHT)
Audio.PlaySFXOnce2D("event:/Props/impact_elastic"); AudioHandler.audioClipHandlers["SFXImpactElastic"].Play();
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY) else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
Audio.PlaySFXOnce2D("event:/Props/impact_hard"); AudioHandler.audioClipHandlers["SFXImpactHard"].Play();
playSound = false; playSound = false;
} }

View File

@ -1,5 +1,6 @@
using SHADE; using SHADE;
using SHADE_Scripting; using SHADE_Scripting;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using static PlayerController; using static PlayerController;
@ -43,6 +44,8 @@ public class PickAndThrow : Script
if(!tpc) if(!tpc)
Debug.LogError("TPC EMPTY"); Debug.LogError("TPC EMPTY");
AudioHandler.audioClipHandlers["SFXThrow"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_throw");
timer = delayTimer; timer = delayTimer;
} }
protected override void update() protected override void update()
@ -72,7 +75,7 @@ public class PickAndThrow : Script
if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming) if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming)
{ {
Audio.PlaySFXOnce2D("event:/Raccoon/raccoon_throw"); AudioHandler.audioClipHandlers["SFXThrow"].Play();
itemRidigBody.IsGravityEnabled = true; itemRidigBody.IsGravityEnabled = true;
itemCollider.GetCollisionShape(0).IsTrigger = false; itemCollider.GetCollisionShape(0).IsTrigger = false;
pc.isAiming = false; pc.isAiming = false;

View File

@ -150,7 +150,13 @@ public class PlayerController : Script
if(!camArm) if(!camArm)
camArm = GetComponentInChildren<CameraArm>(); camArm = GetComponentInChildren<CameraArm>();
//tempFix
if (tranform)
tranform.LocalEulerAngles = new Vector3(0.0f, tranform.LocalEulerAngles.y, 0.0f);
Rotation(); Rotation();
MoveKey();
Sprint();
Jump(); Jump();
GotCaught(); GotCaught();
//Debug.Log($"{currentState}"); //Debug.Log($"{currentState}");
@ -161,10 +167,7 @@ public class PlayerController : Script
protected override void fixedUpdate() protected override void fixedUpdate()
{ {
MoveKey();
Move(); Move();
Sprint();
Gravity(); Gravity();
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}"); //Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
} }

View File

@ -17,6 +17,7 @@ namespace SHADE_Scripting
public float pitchClamp = 45.0f; public float pitchClamp = 45.0f;
public bool inverseXControls = false; public bool inverseXControls = false;
public bool inverseYControls = false; public bool inverseYControls = false;
public float lowerClamp = 5.0f;
protected override void awake() protected override void awake()
{ {
@ -58,9 +59,9 @@ namespace SHADE_Scripting
{ {
arm.Pitch = pitchClamp; arm.Pitch = pitchClamp;
} }
else if (arm.Pitch < 0) else if (arm.Pitch < lowerClamp)
{ {
arm.Pitch = 0; arm.Pitch = lowerClamp;
} }
} }
} }

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -38,6 +39,23 @@ public class GameManager : Script
public static GameManager Instance { get; private set; } public static GameManager Instance { get; private set; }
protected override void start()
{
base.start();
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["KitchenAmbience"] = Audio.CreateAudioClip("event:/Ambience/roomtone_kitchen");
AudioHandler.audioClipHandlers["KitchenAmbience"].Play();
AudioHandler.audioClipHandlers["SFXHumming"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_humming");
AudioHandler.audioClipHandlers["SFXHumming"].SetVolume(0.15f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
}
protected override void awake() protected override void awake()
{ {
if (Instance != null && Instance != this) if (Instance != null && Instance != this)
@ -45,8 +63,12 @@ public class GameManager : Script
else else
Instance = this; Instance = this;
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen"); //AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
//Audio.PlayBGMOnce2D("event:/Music/player_undetected");
//Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
totalItemCount = 0; totalItemCount = 0;
Score = 0; Score = 0;
currGameState = GameState.START; currGameState = GameState.START;
@ -54,6 +76,9 @@ public class GameManager : Script
currMultiplierCombo = 1; currMultiplierCombo = 1;
currMultiplierDuration = 0; currMultiplierDuration = 0;
fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration); fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration);
AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
} }
protected override void update() protected override void update()
@ -86,19 +111,25 @@ public class GameManager : Script
multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero; multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero;
} }
if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1)) if ((timer > 0 && totalItemCount <= 0) || Input.GetKeyDown(Input.KeyCode.F1))
{ {
currGameState = GameState.WIN; currGameState = GameState.WIN;
Audio.StopAllSounds(); //Audio.StopAllSounds(); //Calling this outright breaks audio clip handlers
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["BGMWin"].Play();
SceneManager.ChangeScene(winScene); SceneManager.ChangeScene(winScene);
Audio.PlaySFXOnce2D("event:/Music/stingers/game_win"); //Audio.PlaySFXOnce2D("event:/Music/stingers/game_win");
} }
else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2)) else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2))
{ {
currGameState = GameState.LOSE; currGameState = GameState.LOSE;
Audio.StopAllSounds(); //Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["BGMLose"].Play();
SceneManager.ChangeScene(loseScene); SceneManager.ChangeScene(loseScene);
Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose"); //Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose");
} }
} }
} }

View File

@ -1,19 +1,21 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
public class ScoringZone : Script public class ScoringZone : Script
{ {
protected override void awake() protected override void awake()
{ {
AudioHandler.audioClipHandlers["SFXItemScore"] = Audio.CreateAudioClip("event:/Music/stingers/item_scored");
} }
protected override void onTriggerEnter(CollisionInfo info) protected override void onTriggerEnter(CollisionInfo info)
{ {
if (GameManager.Instance && info.GameObject.GetScript<Item>()) if (GameManager.Instance && info.GameObject.GetScript<Item>() && info.GameObject.IsActiveSelf && !info.GameObject.GetComponent<Collider>().GetCollisionShape(0).IsTrigger )
{ {
Audio.PlaySFXOnce2D("event:/Music/stingers/item_scored"); AudioHandler.audioClipHandlers["SFXItemScore"].Play();
GameManager.Instance.ItemScored();
GameManager.Instance.Score += info.GameObject.GetScript<Item>().Score * GameManager.Instance.currMultiplierCombo; GameManager.Instance.Score += info.GameObject.GetScript<Item>().Score * GameManager.Instance.currMultiplierCombo;
GameManager.Instance.ItemScored();
info.GameObject.SetActive(false); info.GameObject.SetActive(false);
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
public class EndScene : Script public class EndScene : Script
{ {
@ -8,28 +9,36 @@ public class EndScene : Script
protected override void awake() protected override void awake()
{ {
AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");
} }
protected override void update() protected override void update()
{ {
if (Input.GetKeyDown(Input.KeyCode.R)) if (Input.GetKeyDown(Input.KeyCode.R))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); //Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXMouseDownElement"].Play();
} }
if (Input.GetKeyUp(Input.KeyCode.R)) if (Input.GetKeyUp(Input.KeyCode.R))
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds(); //Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(mainGameScene); SceneManager.ChangeScene(mainGameScene);
} }
if (Input.GetKeyDown(Input.KeyCode.M)) if (Input.GetKeyDown(Input.KeyCode.M))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); //Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXMouseDownElement"].Play();
} }
if (Input.GetKeyUp(Input.KeyCode.M)) if (Input.GetKeyUp(Input.KeyCode.M))
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds(); //Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(mainMainScene); SceneManager.ChangeScene(mainMainScene);
} }

View File

@ -1,23 +1,30 @@
using System; using System;
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
public class MainMenu : Script public class MainMenu : Script
{ {
public uint sceneID; public uint sceneID;
protected override void awake() protected override void awake()
{ {
Audio.PlayBGMOnce2D("event:/Music/main_menu"); AudioHandler.audioClipHandlers["BGMMainMenu"] = Audio.CreateAudioClip("event:/Music/main_menu");
AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");
//Audio.PlayBGMOnce2D("event:/Music/main_menu");
AudioHandler.audioClipHandlers["BGMMainMenu"].Play();
} }
protected override void update() protected override void update()
{ {
if (Input.GetKeyDown(Input.KeyCode.Space)) if (Input.GetKeyDown(Input.KeyCode.Space))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); //Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXMouseDownElement"].Play();
} }
if (Input.GetKeyUp(Input.KeyCode.Space)) if (Input.GetKeyUp(Input.KeyCode.Space))
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(sceneID); SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds(); Audio.StopAllSounds();
} }

View File

@ -171,6 +171,7 @@ namespace Sandbox
SHSceneManager::InitSceneManager<SBMainScene>(editorConfig.workingSceneID); SHSceneManager::InitSceneManager<SBMainScene>(editorConfig.workingSceneID);
#else #else
SHSceneManager::InitSceneManager<SBMainScene>(appConfig.startingSceneID); SHSceneManager::InitSceneManager<SBMainScene>(appConfig.startingSceneID);
window.SetMouseVisible(false);
#endif #endif
SHFrameRateController::UpdateFRC(); SHFrameRateController::UpdateFRC();
@ -199,7 +200,8 @@ namespace Sandbox
#ifdef SHEDITOR #ifdef SHEDITOR
if(editor->editorState == SHEditor::State::PLAY) if(editor->editorState == SHEditor::State::PLAY)
#else
window.ClipMouseCursor();
#endif #endif
SHSceneManager::SceneUpdate(0.016f); SHSceneManager::SceneUpdate(0.016f);
#ifdef SHEDITOR #ifdef SHEDITOR

View File

@ -23,6 +23,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/SHVkUtil.h" #include "Graphics/SHVkUtil.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "Tools/SHDebugDraw.h" #include "Tools/SHDebugDraw.h"
namespace SHADE namespace SHADE
@ -98,7 +99,7 @@ namespace SHADE
} }
} }
if (rig && currClip) if (rig && rig->GetRootNode() && currClip)
{ {
updatePoseWithClip(0.0f); updatePoseWithClip(0.0f);
} }
@ -109,8 +110,11 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHAnimatorComponent::Update(float dt) void SHAnimatorComponent::Update(float dt)
{ {
//Reset matrices
std::fill(boneMatrices.begin(), boneMatrices.end(), SHMatrix::Identity);
// Nothing to animate // Nothing to animate
if (!currClip || !isPlaying || !rig) if (!currClip || !isPlaying || !rig || !rig->GetRootNode())
return; return;
// Update time on the playback // Update time on the playback
@ -120,12 +124,6 @@ namespace SHADE
currPlaybackTime = currPlaybackTime - currClip->GetTotalTime(); currPlaybackTime = currPlaybackTime - currClip->GetTotalTime();
} }
// Reset all matrices
for (auto& mat : boneMatrices)
{
mat = SHMatrix::Identity;
}
// Play the clip // Play the clip
updatePoseWithClip(currPlaybackTime); updatePoseWithClip(currPlaybackTime);
} }

View File

@ -142,10 +142,10 @@ namespace SHADE
SHVec3 offset{ 0.0f,0.0f, pivot.GetArmLength() }; SHVec3 offset{ 0.0f,0.0f, 1.0f };
offset = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(pivot.GetPitch()))); offset = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(pivot.GetPitch())));
offset = SHVec3::RotateY(offset, (SHMath::DegreesToRadians(pivot.GetYaw()))); offset = SHVec3::RotateY(offset, (SHMath::DegreesToRadians(pivot.GetYaw())));
offset = SHVec3::Normalise(offset) * pivot.armLength;
//pivot.rtMatrix = SHMatrix::RotateX(SHMath::DegreesToRadians(pivot.GetPitch())) //pivot.rtMatrix = SHMatrix::RotateX(SHMath::DegreesToRadians(pivot.GetPitch()))
// * SHMatrix::RotateY(SHMath::DegreesToRadians(pivot.GetYaw())) // * SHMatrix::RotateY(SHMath::DegreesToRadians(pivot.GetYaw()))
@ -165,7 +165,7 @@ namespace SHADE
return; return;
/*if (SHComponentManager::HasComponent<SHTransformComponent>(camera->GetEID()) == true && camera != &editorCamera) if (SHComponentManager::HasComponent<SHTransformComponent>(camera->GetEID()) == true && camera != &editorCamera)
{ {
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(camera->GetEID()); auto transform = SHComponentManager::GetComponent<SHTransformComponent>(camera->GetEID());
SHVec3 rotation = transform->GetWorldRotation(); SHVec3 rotation = transform->GetWorldRotation();
@ -174,14 +174,47 @@ namespace SHADE
camera->roll = SHMath::RadiansToDegrees(rotation.z); camera->roll = SHMath::RadiansToDegrees(rotation.z);
camera->position = transform->GetWorldPosition(); camera->position = transform->GetWorldPosition();
camera->dirtyView = true; camera->dirtyView = true;
}*/ }
pivot.ray.position = camera->GetPosition() + pivot.targetOffset;
pivot.ray.direction = SHVec3::Normalise((camera->position + offset)- pivot.ray.position);
//SHLOG_INFO("Ray position: {},{},{} direction:{},{},{}",pivot.ray.position.x, pivot.ray.position.y, pivot.ray.position.z,pivot.ray.direction.x, pivot.ray.direction.y, pivot.ray.direction.z)
//auto result = physicsSystem->Raycast(pivot.ray); SHVec3 cameraPos = camera->position + pivot.offset;
SHVec3 cameraTarget = camera->position;
//SHLOG_INFO("Ray position: {},{},{} direction:{},{},{}",pivot.ray.position.x, pivot.ray.position.y, pivot.ray.position.z,pivot.ray.direction.x, pivot.ray.direction.y, pivot.ray.direction.z)
SHRaycaster::RaycastInfo info;
//info.layers = (SHCollisionTagMatrix::GetTag("7")->GetMask());
info.layers = (uint16_t)(SHCollisionTagMatrix::GetTag("Camera")->GetMask());
info.distance = pivot.armLength;
info.continuous = false;
info.ray.position = cameraTarget;
info.SetColliderID(2);
info.ray.direction = SHVec3::Normalise(cameraPos - cameraTarget);
auto result = physicsSystem->Raycast(info);
for (auto hitResult : result)
{
if (hitResult.distance < pivot.armLength)
{
SHVec3 newOffset{ 0.0f,0.0f, 1.0f };
newOffset = SHVec3::RotateX(newOffset, -(SHMath::DegreesToRadians(pivot.GetPitch())));
newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw())));
newOffset = SHVec3::Normalise(newOffset) * (hitResult.distance * 0.95f);
pivot.offset = newOffset;
//cameraPos = camera->position + pivot.offset;
//SHLOG_INFO("CAMERA COLLISION HIT, {} armlength: {}, true armlength: {}", hitResult.distance, hitResult.distance, (cameraPos - camera->position).Length());
//SHLOG_INFO("Racoon Position {}, {}, {}, Camera Position: {}, {}, {}, Distance {}", cameraTarget.x, cameraTarget.y, cameraTarget.z, cameraPos.x, cameraPos.y, cameraPos.z, SHVec3::Distance(cameraTarget, cameraPos));
//SHLOG_INFO("Camera Position: {}, {}, {}", cameraPos.x, cameraPos.y, cameraPos.z);
auto otherTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(hitResult.entityHit);
SHVec3 otherPos = hitResult.position;
//SHLOG_INFO("hit distance{} other pos: {},{},{}, distance between: {}", hitResult.distance, otherPos.x, otherPos.y, otherPos.z, SHVec3::Distance(cameraTarget,otherPos));
break;
}
}
////auto result = physicsSystem->Raycast(pivot.ray);
//if (result && result.distance < pivot.GetArmLength()) //if (result && result.distance < pivot.GetArmLength())
//{ //{
// //
@ -196,8 +229,6 @@ namespace SHADE
// //SHLOG_INFO("CAMERA COLLISION CANT HIT CAMERA"); // //SHLOG_INFO("CAMERA COLLISION CANT HIT CAMERA");
//} //}
//
//
// pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix); // pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix);
@ -234,7 +265,8 @@ namespace SHADE
{ {
camera.offset = arm->GetOffset(); camera.offset = arm->GetOffset();
if (arm->lookAtCameraOrigin) if (arm->lookAtCameraOrigin)
CameraLookAt(camera, camera.position + arm->GetTargetOffset()); CameraLookAt(camera, camera.position);
} }
} }
@ -418,7 +450,7 @@ namespace SHADE
} }
} }
void SHCameraSystem::DecomposeViewMatrix(SHMatrix const& viewMatrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept void SHCameraSystem::DecomposeViewMatrix(SHMatrix const& viewMatrix, float& pitch, float& yaw, float& roll, SHVec3& pos, bool takePos) noexcept
{ {
float initPitch = pitch; float initPitch = pitch;
@ -441,15 +473,18 @@ namespace SHADE
mtx = SHMatrix::Inverse(mtx); mtx = SHMatrix::Inverse(mtx);
SHVec4 translate = mtx* dotPos; SHVec4 translate = mtx* dotPos;
pos.x = translate.x; if (takePos)
pos.y = translate.y; {
pos.z = translate.z; pos.x = translate.x;
pos.y = translate.y;
pos.z = translate.z;
}
} }
void SHCameraSystem::SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept void SHCameraSystem::SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix, bool takePos) noexcept
{ {
SHVec3 pos; SHVec3 pos;
DecomposeViewMatrix(viewMatrix, camera.pitch, camera.yaw, camera.roll, camera.position); DecomposeViewMatrix(viewMatrix, camera.pitch, camera.yaw, camera.roll, camera.position, takePos);
camera.dirtyView = true; camera.dirtyView = true;
} }
@ -457,7 +492,7 @@ namespace SHADE
void SHCameraSystem::CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept void SHCameraSystem::CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept
{ {
if (camera.position == target) if (camera.position + camera.offset == target)
{ {
//lets off set it abit so the view is nt fked //lets off set it abit so the view is nt fked
target.z -= 0.0001f; target.z -= 0.0001f;
@ -499,7 +534,7 @@ namespace SHADE
viewMtx(2, 3) = -forward.Dot(camera.position + camera.offset); viewMtx(2, 3) = -forward.Dot(camera.position + camera.offset);
SetCameraViewMatrix(camera, viewMtx); SetCameraViewMatrix(camera, viewMtx,false);
} }
SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept

View File

@ -54,8 +54,8 @@ namespace SHADE
void ClampCameraRotation(SHCameraComponent& camera) noexcept; void ClampCameraRotation(SHCameraComponent& camera) noexcept;
void UpdateEditorCamera(double dt) noexcept; void UpdateEditorCamera(double dt) noexcept;
void SetMainCamera(EntityID eid, size_t directorIndex) noexcept; void SetMainCamera(EntityID eid, size_t directorIndex) noexcept;
void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept; void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos, bool takePos) noexcept;
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix, bool takePos) noexcept;
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept; void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept; void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;

View File

@ -185,12 +185,40 @@ namespace SHADE
void SHWindow::SetMouseVisible(bool show) void SHWindow::SetMouseVisible(bool show)
{ {
ShowCursor(show ? TRUE : FALSE); if (GetActiveWindow() == wndHWND)
ShowCursor(show);
} }
void SHWindow::SetMousePosition(unsigned x, unsigned y) void SHWindow::SetMousePosition(int x, int y)
{ {
SetCursorPos(x, y); if(GetActiveWindow() == wndHWND)
{
//if(x == -1)
// x = GetSystemMetrics(SM_CXSCREEN) * 0.5;
//if (y == -1)
// y = GetSystemMetrics(SM_CYSCREEN) * 0.5;
//SetCursorPos(x, y);
}
}
void SHWindow::ClipMouseCursor(int left, int top, int right, int bottom)
{
if (GetActiveWindow() == wndHWND)
{
RECT rect{};
if (left == 0 || right == 0)
{
GetClientRect(wndHWND, &rect);
}
else
{
rect.left = left;
rect.right = right;
rect.top = top;
rect.bottom = bottom;
}
ClipCursor(&rect);
}
} }
//unsigned SHWindow::GetBGColor() //unsigned SHWindow::GetBGColor()

View File

@ -106,7 +106,9 @@ namespace SHADE
void SetMouseVisible(bool show); void SetMouseVisible(bool show);
void SetMousePosition(unsigned x, unsigned y); void SetMousePosition(int x = -1, int y = -1);
void ClipMouseCursor(int left = 0, int top = 0, int right = 0, int bottom = 0);
//unsigned GetBGColor(); //unsigned GetBGColor();
@ -144,7 +146,6 @@ namespace SHADE
void SetHWND(HWND hwnd); void SetHWND(HWND hwnd);
HWND wndHWND = nullptr; HWND wndHWND = nullptr;
HINSTANCE hInstance = nullptr; HINSTANCE hInstance = nullptr;