Fix bugs and add Pause for the game in #364

Merged
glencelow merged 5 commits from PlayerController into main 2023-02-24 21:14:30 +08:00
24 changed files with 156 additions and 41 deletions
Showing only changes of commit 8d10c48645 - Show all commits

View File

@ -4,5 +4,5 @@
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 51995224
data.alpha: 0
data.alpha: 1
data.beta: {x: 1, y: 1, z: 1}

View File

@ -4,5 +4,5 @@
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 54429632
data.alpha: 0
data.alpha: 1
data.beta: {x: 1, y: 1, z: 1}

View File

@ -8540,6 +8540,7 @@
currCategory: 1
density: 1
dontReturn: false
soundDistance: 10
- EID: 157
Name: Mesh_Meat
IsActive: true
@ -8587,6 +8588,7 @@
currCategory: 1
density: 1
dontReturn: false
soundDistance: 10
- EID: 156
Name: Mesh_Meat
IsActive: true
@ -8634,6 +8636,7 @@
currCategory: 1
density: 1
dontReturn: false
soundDistance: 10
- EID: 155
Name: Mesh_Cheese
IsActive: true
@ -8681,6 +8684,7 @@
currCategory: 2
density: 1
dontReturn: false
soundDistance: 10
- EID: 154
Name: Mesh_Cheese
IsActive: true
@ -8728,6 +8732,7 @@
currCategory: 2
density: 1
dontReturn: false
soundDistance: 10
- EID: 153
Name: Mesh_Cheese
IsActive: true
@ -8775,6 +8780,7 @@
currCategory: 2
density: 1
dontReturn: false
soundDistance: 10
- EID: 65778
Name: Mesh_Apple
IsActive: true
@ -8822,6 +8828,7 @@
currCategory: 0
density: 1
dontReturn: false
soundDistance: 10
- EID: 152
Name: Mesh_Apple
IsActive: true
@ -8869,6 +8876,7 @@
currCategory: 0
density: 1
dontReturn: false
soundDistance: 10
- EID: 151
Name: Mesh_Apple
IsActive: true
@ -8916,6 +8924,7 @@
currCategory: 0
density: 1
dontReturn: false
soundDistance: 10
- EID: 65686
Name: Watermelon
IsActive: true
@ -8967,6 +8976,7 @@
currCategory: 2
density: 1
dontReturn: false
soundDistance: 10
- EID: 131220
Name: Piece1
IsActive: true
@ -9014,6 +9024,7 @@
currCategory: 1
density: 3
dontReturn: false
soundDistance: 10
- EID: 131219
Name: Piece2
IsActive: true
@ -9061,6 +9072,7 @@
currCategory: 1
density: 3
dontReturn: false
soundDistance: 10
- EID: 131221
Name: Piece3
IsActive: true
@ -9108,6 +9120,7 @@
currCategory: 0
density: 3
dontReturn: false
soundDistance: 10
- EID: 145
Name: Piece4
IsActive: true
@ -9155,6 +9168,7 @@
currCategory: 0
density: 3
dontReturn: false
soundDistance: 10
- EID: 196754
Name: Piece5
IsActive: true
@ -9202,6 +9216,7 @@
currCategory: 0
density: 3
dontReturn: false
soundDistance: 10
- EID: 144
Name: Egg
IsActive: true
@ -9253,6 +9268,7 @@
currCategory: 0
density: 2
dontReturn: false
soundDistance: 10
- EID: 143
Name: Piece1
IsActive: true
@ -9653,7 +9669,7 @@
Components:
Transform Component:
Translate: {x: 2.35245037, y: 0.38365531, z: 7.10571432}
Rotate: {x: -0, y: 0, z: -0}
Rotate: {x: 0, y: 0.326376587, z: 0.0698131472}
Scale: {x: 0.999999881, y: 1, z: 0.999999881}
IsActive: true
Renderable Component:
@ -9731,7 +9747,7 @@
Components:
Transform Component:
Translate: {x: 0, y: -5.96046448e-08, z: 0}
Rotate: {x: 0, y: 6.28318548, z: 2.23517329e-08}
Rotate: {x: 0, y: 5.95680904, z: -0.0698131248}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Camera Component:
@ -9739,8 +9755,8 @@
Pitch: 0
Yaw: 360
Roll: 1.28065994e-06
Width: 2560
Height: 1369
Width: 1055
Height: 604
Near: 0.00999999978
Far: 10000
Perspective: true
@ -10512,14 +10528,14 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.70000005, y: 0.100000001, z: -2}
Translate: {x: 0, y: 0, z: -2.64324665}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: false
IsActive: true
Renderable Component:
Mesh: 140697366
Material: 129495479
IsActive: false
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
@ -10533,7 +10549,7 @@
Freeze Rotation X: true
Freeze Rotation Y: false
Freeze Rotation Z: true
IsActive: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
@ -10545,7 +10561,7 @@
Density: 1
Position Offset: {x: 0, y: 0.899999976, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: false
IsActive: true
Scripts:
- Type: Homeowner1
Enabled: true
@ -10605,6 +10621,7 @@
currCategory: 1
density: 1
dontReturn: false
soundDistance: 10
- EID: 16
Name: JumpPad
IsActive: false
@ -10632,13 +10649,13 @@
Enabled: true
- EID: 10
Name: Canvas
IsActive: false
IsActive: true
NumberOfChildren: 3
Components:
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
IsActive: false
IsActive: true
Scripts: ~
- EID: 8
Name: ResumeButton

View File

@ -15,7 +15,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Translate: {x: 0, y: 0, z: 0.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
@ -35,7 +35,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 75, z: 0}
Translate: {x: 0, y: 75, z: 0.400000006}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
@ -63,7 +63,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -200, z: 0}
Translate: {x: 0, y: -200, z: 0.400000006}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
@ -113,8 +113,8 @@
Pitch: 0
Yaw: 0
Roll: 0
Width: 1319
Height: 622
Width: 1055
Height: 604
Near: 0.00999999978
Far: 10000
Perspective: true
@ -130,3 +130,4 @@
- Type: MainMenu
Enabled: true
sceneID: 96668835
obj: 1

View File

@ -111,6 +111,7 @@
Near: 0.00999999978
Far: 10000
Perspective: true
FOV: 90
IsActive: true
Scripts: ~
- EID: 4

View File

@ -74,6 +74,9 @@ public partial class Homeowner1 : BehaviourTree
private float footstepSFXIntervalMultiplier;
private float footstepTimeRemaining;
//singleton for AI
public static Homeowner1 aiInstance { get; private set; }
}
//AI tree
@ -111,6 +114,11 @@ public partial class Homeowner1 : BehaviourTree
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");
if (aiInstance != null && aiInstance != this)
RemoveScript<Homeowner1>();
else
aiInstance = this;
}
//Called every tick
@ -182,4 +190,10 @@ public partial class Homeowner1 : BehaviourTree
//Debug.Log("Tree Created");
return root;
}
protected override void onDestroy()
{
if (aiInstance == this)
aiInstance = null;
}
}

View File

@ -24,6 +24,10 @@ public class Item : Script
public bool dontReturn = false;
private bool checkSound = false;
public float soundDistance = 10;
protected override void awake()
{
transform = GetComponent<Transform>();
@ -55,10 +59,25 @@ public class Item : Script
returnBack = false;
}
if (checkSound)
{
/* //need to wait for collisionEnter Fix
Vector3 itemPos = transform.LocalPosition;
Vector3 len = Homeowner1.aiInstance.GetComponent<Transform>().LocalPosition - itemPos;
Debug.Log($"distance: {len.GetSqrMagnitude()}");
if (len.GetSqrMagnitude() <= soundDistance)
{
//set ai to alert
}
checkSound = false;*/
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (!caputurePos)
{
firstPostion = transform.LocalPosition;
@ -83,6 +102,7 @@ public class Item : Script
protected override void onCollisionExit(CollisionInfo info)
{
playSound = true;
checkSound = true;
}
}

View File

@ -26,6 +26,7 @@ public class PickAndThrow : Script
private float lastZDir;
private bool inRange = false;
public bool throwItem = false;
private Vector3 prevTargetOffSet;
[Tooltip("Lenght of ray")]
public float rayDistance = 1;
@ -56,8 +57,12 @@ public class PickAndThrow : Script
}
protected override void update()
{
if (GameManager.Instance.GamePause)
{
return;
}
if(timer <= delayTimer)
if (timer <= delayTimer)
timer += Time.DeltaTimeF;
CalculateDir();
@ -76,6 +81,7 @@ public class PickAndThrow : Script
{
pc.isAiming = true;
pc.camArm.ArmLength = aimingLength;
prevTargetOffSet = pc.camArm.TargetOffset;
pc.camArm.TargetOffset = cameraArmOffSet;
pc.cam.FOV = aimingFOV;
}
@ -86,7 +92,7 @@ public class PickAndThrow : Script
itemRidigBody.IsGravityEnabled = true;
itemCollider.GetCollisionShape(0).IsTrigger = false;
pc.isAiming = false;
pc.camArm.TargetOffset = Vector3.Zero;
pc.camArm.TargetOffset = prevTargetOffSet;
pc.cam.FOV = defaultFOV;
if (tpc)
pc.camArm.ArmLength = tpc.armLength;
@ -109,7 +115,7 @@ public class PickAndThrow : Script
{
pc.isAiming = false;
pc.cam.FOV = defaultFOV;
pc.camArm.TargetOffset = Vector3.Zero;
pc.camArm.TargetOffset = prevTargetOffSet;
if (tpc)
pc.camArm.ArmLength = tpc.armLength;
}
@ -134,6 +140,11 @@ public class PickAndThrow : Script
protected override void fixedUpdate()
{
if (GameManager.Instance.GamePause)
{
return;
}
if (throwItem && itemRidigBody && pc)
{
if (itemScript)

View File

@ -124,8 +124,14 @@ public class PlayerController : Script
protected override void lateUpdate()
{
}
protected override void update()
{
if (GameManager.Instance.GamePause)
{
return;
}
if (delayTimer <= 1)
delayTimer += Time.DeltaTimeF;
@ -158,22 +164,27 @@ public class PlayerController : Script
if (tranform)
tranform.LocalEulerAngles = new Vector3(0.0f, tranform.LocalEulerAngles.y, 0.0f);
GotCaught();
Rotation();
MoveKey();
Sprint();
Jump();
GotCaught();
//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()
{
if (GameManager.Instance.GamePause)
{
return;
}
Move();
Gravity();
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
}
@ -234,7 +245,7 @@ public class PlayerController : Script
private void Move()
{
if (rb != null)
if (rb != null && currentState != RaccoonStates.CAUGHT)
{
rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF;
@ -286,7 +297,6 @@ public class PlayerController : Script
}
}
//press and hold jump
private void Jump()
{
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE)

View File

@ -41,6 +41,11 @@ namespace SHADE_Scripting
protected override void update()
{
if (GameManager.Instance.GamePause)
{
return;
}
CameraArm arm = GetComponent<CameraArm>();
if (arm)
{

View File

@ -38,13 +38,11 @@ public class GameManager : Script
private Vector3 fontScalar;
public static GameManager Instance { get; private set; }
//public static int highScore { get; private set; } maybe need
public bool GamePause { get; set; }
protected override void start()
{
base.start();
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();

View File

@ -0,0 +1,3 @@
Name: SC_JumpPad
ID: 163951275
Type: 9

View File

@ -5,6 +5,10 @@ using SHADE_Scripting.Audio;
public class MainMenu : Script
{
public uint sceneID;
public GameObject obj;
private Renderable renderable;
protected override void awake()
{
AudioHandler.audioClipHandlers["BGMMainMenu"] = Audio.CreateAudioClip("event:/Music/main_menu");
@ -12,9 +16,31 @@ public class MainMenu : Script
AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");
//Audio.PlayBGMOnce2D("event:/Music/main_menu");
AudioHandler.audioClipHandlers["BGMMainMenu"].Play();
renderable = obj.GetComponent<Renderable>();
}
protected override void start()
{
}
protected override void update()
{
if (Input.GetKeyDown(Input.KeyCode.K) && obj)
{
if (renderable.Material.GetProperty<float>("data.alpha") == 1)
{
Debug.Log("ALPHA ZERO");
Debug.Log($"{obj.EntityId}");
obj.GetComponent<Renderable>().Material.SetProperty<float>("data.alpha", 0);
}
else if (renderable.Material.GetProperty<float>("data.alpha") == 0)
{
Debug.Log("ALPHA ONE");
Debug.Log($"{obj.EntityId}");
obj.GetComponent<Renderable>().Material.SetProperty<float>("data.alpha", 1);
}
}
if (Input.GetKeyDown(Input.KeyCode.Space))
{
//Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");

View File

@ -59,8 +59,7 @@ public class PauseMenu : Script
retry.OnClick.RegisterAction(() =>
{
Audio.StopAllSounds();
//get curr scene
//SceneManager.ChangeScene();
SceneManager.RestartScene();
});
}
else
@ -86,10 +85,6 @@ public class PauseMenu : Script
protected override void update()
{
if (GameManager.Instance.GamePause)
{
return;
}
if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause)
{

View File

@ -5,10 +5,8 @@
struct MatPropData
{
vec4 color;
int textureIndex;
float alpha;
vec3 beta;
};
layout(location = 0) in struct
@ -39,10 +37,12 @@ layout(location = 1) out uint outEntityID;
void main()
{
fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
fragColor.a = MatProp.data[In2.materialIndex].alpha;
if (fragColor.a < 0.01f)
{
discard;
}
// fragColor.a = 1.0f;
outEntityID = In2.eid;
}

Binary file not shown.

View File

@ -58,8 +58,11 @@ void main()
Out.normal.rgb = transposeInv * aNormal.rgb;
Out.normal.rgb = normalize (Out.normal.rgb);
vec3 vert = aVertexPos;
vert.z += 0.1f;
// clip space for rendering
gl_Position = cameraData.projMat * worldTransform * vec4 (aVertexPos, 1.0f);
gl_Position.z += 0.1f; // HAX
gl_Position = cameraData.projMat * worldTransform * vec4 (vert, 1.0f);
// gl_Position.z += 0.1f; // HAX
// gl_Position = vec4 (aVertexPos, 1.0f);
}

Binary file not shown.

View File

@ -345,7 +345,7 @@ namespace SHADE
else
{
// Should be deactivated
static const SHMatrix ZERO_MTX =
static const SHMatrix ZERO_MTX
{
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,

View File

@ -340,10 +340,11 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* SCREEN SPACE PASS */
/*-----------------------------------------------------------------------*/
auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data()});
auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data()});
auto uiSubpass = screenSpaceNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS.data(), worldViewport, screenRenderer);
uiSubpass->AddColorOutput("Scene");
uiSubpass->AddColorOutput("Entity ID");
uiSubpass->AddDepthOutput("Depth Buffer");
uiSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
{
textRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex);

View File

@ -312,7 +312,7 @@ namespace SHADE
{
auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID));
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID)->TextureArrayIndex);
}

View File

@ -22,4 +22,12 @@ namespace SHADE
{
SHSceneManager::RestartScene(sceneAssetID);
}
void SceneManager::RestartScene()
{
SHSceneManager::RestartScene();
}
AssetID SceneManager::GetCurrentSceneID()
{
return SHSceneManager::GetCurrentSceneAssetID();
}
}

View File

@ -23,5 +23,7 @@ namespace SHADE
{
public :
static void ChangeScene(AssetID sceneAssetID);
static void RestartScene();
static AssetID GetCurrentSceneID();
};
}