Demo Overhaul

This commit is contained in:
RochesterX
2025-02-08 18:54:21 -05:00
parent 16dec36792
commit 71a4f070d5
14 changed files with 3579 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ public class Damageable : MonoBehaviour
{
public float force = 50f;
public float damage = 0f;
public float maxDamage = 1000f;
private void OnTriggerEnter2D(Collider2D collision)
{
@@ -20,13 +21,14 @@ public class Damageable : MonoBehaviour
private void Recoil(GameObject damageSource)
{
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up) * damage, ForceMode2D.Force);
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * damage, ForceMode2D.Force);
//damageSource.transform.localScale *= 1.1f;
}
private void Damage()
{
damage += force;
damage = Mathf.Clamp(damage, 0f, maxDamage);
}
public void ResetDamage()

View File

@@ -10,6 +10,8 @@ public class PlayerManager : MonoBehaviour
public List<GameObject> players;
[SerializeField] private InputActionAsset playerActions;
public List<Color> playerColors;
private Vector2 spawnPosition;
private void Awake()
@@ -27,6 +29,7 @@ public class PlayerManager : MonoBehaviour
{
playerInput.transform.position = spawnPosition;
players.Add(playerInput.gameObject);
Colorize(playerInput.gameObject);
print("Player joined");
}
@@ -51,4 +54,23 @@ public class PlayerManager : MonoBehaviour
spawnPosition = transform.position;
}
private void Colorize(GameObject player)
{
Color color = playerColors[(players.Count - 1) % playerColors.Count];
float tint = Mathf.Floor((players.Count - 1) / playerColors.Count);
color = (color + color + Color.white * tint) / (tint + 2);
if (player.TryGetComponent<SpriteRenderer>(out _))
{
player.GetComponent<SpriteRenderer>().color = color;
}
foreach (Transform child in player.transform)
{
if (child.TryGetComponent<SpriteRenderer>(out _))
{
Colorize(child.gameObject);
}
}
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps;
@@ -20,6 +21,7 @@ public class PlayerMovement : MonoBehaviour
public float walkSpeed;
public float walkSpeedFactor = 1f;
public float maxSpeed = 5f;
public float maxSpeedOverride;
public float slowdownMultiplier = 10f;
public float virtualAxisX;
public float virtualButtonJump;
@@ -54,6 +56,7 @@ public class PlayerMovement : MonoBehaviour
void Start()
{
maxSpeedOverride = maxSpeed;
GetComponent<RespawnOnTriggerEnter>().spawnPoint = transform.position;
body = GetComponent<Rigidbody2D>();
@@ -119,7 +122,7 @@ public class PlayerMovement : MonoBehaviour
private void Jump()
{
if (!punch.cancelable) return;
//if (!punch.cancelable) return;
if (virtualButtonJumpLastFrame == 1f)
{
@@ -144,6 +147,10 @@ public class PlayerMovement : MonoBehaviour
{
if (body.linearVelocity.y < 0 || !IsPhysicallyGrounded()) body.linearVelocity = new Vector2(body.linearVelocity.x, 0);
body.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
if (Mathf.Abs(body.linearVelocityX) > maxSpeed)
{
body.linearVelocity = new Vector2(Mathf.Sign(body.linearVelocityX) * maxSpeed, body.linearVelocity.y);
}
jumpPhysics = false;
}
@@ -160,13 +167,18 @@ public class PlayerMovement : MonoBehaviour
private void HorizontalMovement()
{
if (!punch.cancelable) return;
float temporaryMax = IsPhysicallyGrounded() ? maxSpeedOverride : Mathf.Infinity;
float temporarySlowdown = IsPhysicallyGrounded() ? slowdownMultiplier : 1;
body.AddForce(new Vector2(virtualAxisX * walkSpeed * walkSpeedFactor, 0), ForceMode2D.Force);
if (Mathf.Abs(body.linearVelocityX) >= maxSpeed)
if (Mathf.Abs(body.linearVelocityX) <= maxSpeed || Mathf.Sign(body.linearVelocityX) != Mathf.Sign(virtualAxisX))
{
body.AddForce(new Vector2(-Mathf.Sign(body.linearVelocityX) * (Mathf.Abs(body.linearVelocityX) - maxSpeed) * slowdownMultiplier, 0));
body.AddForce(new Vector2(virtualAxisX * walkSpeed * walkSpeedFactor, 0), ForceMode2D.Force);
}
if (Mathf.Abs(body.linearVelocityX) >= temporaryMax)
{
//body.linearVelocity = new Vector2(Mathf.Sign(body.linearVelocityX) * temporaryMax, body.linearVelocity.y);
body.AddForce(new Vector2(-Mathf.Sign(body.linearVelocityX) * (Mathf.Abs(body.linearVelocityX) - temporaryMax) * temporarySlowdown, 0));
}
if (transform.position == positionLastFrame && (input.actions.FindAction("Move").ReadValue<Vector2>().x == 0))

View File

@@ -19,14 +19,21 @@ public class Punch : MonoBehaviour
private void Update()
{
if (actions.FindAction("Punch").ReadValue<float>() == 1f)
if (actions.FindAction("Punch").WasPressedThisFrame())
{
if (!cancelable) return;
GetComponent<AnimationPlayer>().Punch();
DisableCancellation();
ExecutePunch();
}
}
private void ExecutePunch()
{
print("Execution");
GetComponent<AnimationPlayer>().Punch();
DisableCancellation();
GetComponent<PlayerMovement>().maxSpeedOverride = 1f;
}
public void EnableHurtbox()
{
hurtbox.enabled = true;
@@ -46,4 +53,9 @@ public class Punch : MonoBehaviour
{
cancelable = true;
}
public void ReturnToMaxSpeed()
{
GetComponent<PlayerMovement>().maxSpeedOverride = GetComponent<PlayerMovement>().maxSpeed;
}
}