Merge branch 'main' into trick-enhancements

This commit is contained in:
hz
2026-02-01 15:44:48 -06:00
37 changed files with 982 additions and 154 deletions
+63
View File
@@ -0,0 +1,63 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
public class CreditsInputHandler : MonoBehaviour
{
[SerializeField] private List<string> buttonNames = new List<string> { "Back" };
[SerializeField] private List<string> sceneNames = new List<string> { "MainMenu" };
private UIDocument uiDocument;
private List<Button> buttons;
private void OnEnable()
{
uiDocument ??= GetComponent<UIDocument>();
if (uiDocument == null)
{
return;
}
var root = uiDocument.rootVisualElement;
if (root == null)
{
return;
}
buttons = new List<Button> { new Button() };
for (int i = 0; i < buttons.Count; i++)
{
int buttonIndex = i;
buttons[i] = root.Q<Button>(buttonNames[i]);
if (buttons[i] == null)
{
continue;
}
buttons[i].clicked += () => HandleStartClicked(sceneNames[buttonIndex]);
}
}
private void OnDisable()
{
for (int i = 0; i < buttons.Count; i++)
{
if (buttons[i] == null)
{
continue;
}
buttons[i].clicked -= () => HandleStartClicked(buttonNames[i]);
}
}
private void HandleStartClicked(string sceneName)
{
if (!string.IsNullOrWhiteSpace(sceneName))
{
SceneManager.LoadScene(sceneName);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: df3455d232d364f4b809e3308d7b42b2
+3 -3
View File
@@ -5,8 +5,8 @@ using UnityEngine.UIElements;
public class MainMenuController : MonoBehaviour
{
[SerializeField] private List<string> buttonNames = new List<string> { "Start", "Experiment", "Level2" };
[SerializeField] private List<string> sceneNames = new List<string> { "Level1", "Experiment", "Level2" };
[SerializeField] private List<string> buttonNames = new List<string> { "Start", "Experiment", "Level2", "Credits" };
[SerializeField] private List<string> sceneNames = new List<string> { "Level1", "Experiment", "Level2", "Credits" };
private UIDocument uiDocument;
private List<Button> buttons;
@@ -24,7 +24,7 @@ public class MainMenuController : MonoBehaviour
return;
}
buttons = new List<Button> { new Button(), new Button(), new Button() };
buttons = new List<Button> { new Button(), new Button(), new Button(), new Button() };
for (int i = 0; i < buttons.Count; i++)
{
int buttonIndex = i;
@@ -0,0 +1,10 @@
using UnityEngine;
public class PlayerAnimationController : MonoBehaviour
{
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fdb391b004c27a64da8f6922aab5512e
+1 -1
View File
@@ -205,7 +205,7 @@ public class PlayerPickupController : MonoBehaviour
}
}
void DropObject(bool applyThrow)
public void DropObject(bool applyThrow)
{
// Re-enable physics
if (heldBody != null)
+72 -2
View File
@@ -10,7 +10,7 @@ public class PlayerPlatformerController : MonoBehaviour
[SerializeField] private string actionMapName = "Player";
[SerializeField] private string moveActionName = "Move";
[SerializeField] private string jumpActionName = "Jump";
[SerializeField] private string healActionName = "Crouch";
[SerializeField] private string healActionName = "Heal";
[SerializeField] private string controlSchemeName = "";
[SerializeField] private int gamepadIndex = -1;
[SerializeField] private float moveSpeed = 6f;
@@ -19,6 +19,8 @@ public class PlayerPlatformerController : MonoBehaviour
[SerializeField] private float groundCheckDistance = 0.05f;
private PlayerStressController playerStressController;
private PlayerPickupController playerPickupController;
private Animator animator;
private Rigidbody2D body;
private BoxCollider2D bodyCollider;
@@ -28,12 +30,17 @@ public class PlayerPlatformerController : MonoBehaviour
private InputAction healAction;
public float LastMoveX { get; private set; }
private bool deviceFilterEnabled;
private int healCoolDownTicks = 15;
private int currentHealCoolDown = 0;
private bool canHeal = true;
private void Awake()
{
body = GetComponent<Rigidbody2D>();
bodyCollider = GetComponent<BoxCollider2D>();
playerStressController = GetComponent<PlayerStressController>();
playerPickupController = GetComponent<PlayerPickupController>();
animator = GetComponent<Animator>();
}
private void OnEnable()
@@ -56,10 +63,12 @@ public class PlayerPlatformerController : MonoBehaviour
var map = runtimeActions.FindActionMap(actionMapName, true);
moveAction = map.FindAction(moveActionName, true);
jumpAction = map.FindAction(jumpActionName, true);
healAction = map.FindAction(healActionName, true);
moveAction.Enable();
jumpAction.Enable();
jumpAction.performed += OnJumpPerformed;
healAction.Enable();
}
private void OnDisable()
@@ -75,6 +84,11 @@ public class PlayerPlatformerController : MonoBehaviour
moveAction.Disable();
}
if (healAction != null)
{
healAction.Disable();
}
if (runtimeActions != null)
{
runtimeActions.Disable();
@@ -86,6 +100,21 @@ public class PlayerPlatformerController : MonoBehaviour
private void FixedUpdate()
{
if(IsGrounded())
{
animator.SetBool("isJumping", false);
}
if (healAction == null) return;
currentHealCoolDown++;
if (currentHealCoolDown >= healCoolDownTicks)
{
currentHealCoolDown = 0;
canHeal = true;
}
if (moveAction == null)
{
return;
@@ -93,6 +122,28 @@ public class PlayerPlatformerController : MonoBehaviour
if (playerStressController.isPanicking) return;
if (healAction.IsPressed())
{
animator.SetBool("isBreathing", true);
if (playerPickupController.heldObject != null)
{
playerPickupController.DropObject(false);
}
if (canHeal)
{
playerStressController.ReduceStress(3f);
canHeal = false;
}
return;
}
else
{
animator.SetBool("isBreathing", false);
}
var input = moveAction.ReadValue<Vector2>();
if (Mathf.Abs(input.x) > 0.01f)
{
@@ -101,11 +152,28 @@ public class PlayerPlatformerController : MonoBehaviour
var velocity = body.linearVelocity;
velocity.x = input.x * moveSpeed;
body.linearVelocity = velocity;
if(velocity.x != 0)
{
animator.SetBool("isRunning", true);
if (velocity.x > 0 && IsGrounded())
{
transform.localScale = new Vector3(.25f, .25f, .25f);
}
else
{
transform.localScale = new Vector3(-.25f, .25f, .25f);
}
}
else
{
animator.SetBool("isRunning", false);
}
}
private void OnJumpPerformed(InputAction.CallbackContext context)
{
if (playerStressController.isPanicking) return;
if (playerStressController.isPanicking || healAction.IsPressed()) return;
if (!IsGrounded())
{
@@ -116,6 +184,8 @@ public class PlayerPlatformerController : MonoBehaviour
velocity.y = 0f;
body.linearVelocity = velocity;
body.AddForce(Vector2.up * jumpImpulse, ForceMode2D.Impulse);
animator.SetBool("isJumping", true);
}
private bool ShouldFilterDevices()
+5 -1
View File
@@ -7,7 +7,8 @@ using UnityEngine;
public class PlayerStressController : MonoBehaviour
{
public PlayerPickupController pickupController;
private Animator animator;
[Header("Stress Settings")]
public float currentStress = 0f;
public float maxStress = 100f;
@@ -25,6 +26,7 @@ public class PlayerStressController : MonoBehaviour
void Start()
{
animator = GetComponent<Animator>();
// Start the repeating loop
StartCoroutine(StressCheckLoop());
}
@@ -76,6 +78,8 @@ public class PlayerStressController : MonoBehaviour
{
isPanicking = true;
animator.SetBool("isCollapsed", true);
Debug.Log("Player is freaking out man!");
// Add effects like screen shake or slowing down the player here
OnPlayerPanic?.Invoke(); // Trigger the panic event
+8
View File
@@ -5,6 +5,8 @@ public class TrickCollisionManager : MonoBehaviour
[SerializeField] private string trickLayerName = "Trick";
[SerializeField] private string playerLayerName = "Player";
[SerializeField] private string treatLayerName = "Treat";
[SerializeField] private string destroyTag = "Destroy";
private bool initialized;
private void Awake()
@@ -43,4 +45,10 @@ public class TrickCollisionManager : MonoBehaviour
Physics2D.IgnoreLayerCollision(trickLayer, otherLayer, true);
}
private void onTriggerEnter2D(Collider2D destroy){
if (destroy.CompareTag(destroyTag))
{
Destroy(gameObject);
}
}
}