Basic player select screen

This commit is contained in:
RochesterX
2025-02-16 16:47:45 -05:00
parent f688173770
commit 543590347a
27 changed files with 8706 additions and 142 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using NUnit.Framework.Constraints;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -8,10 +7,13 @@ public class PlayerManager : MonoBehaviour
public static PlayerManager Instance;
public List<GameObject> players;
public List<PlayerJoinCard> cards;
[SerializeField] private InputActionAsset playerActions;
public List<Color> playerColors;
public GameObject playerSelect;
private Vector2 spawnPosition;
private void Awake()
@@ -27,9 +29,15 @@ public class PlayerManager : MonoBehaviour
private void OnPlayerJoined(PlayerInput playerInput)
{
playerInput.transform.SetParent(transform);
PlayerJoinCard card = PlayerCardCreator.Instance.CreateCard(playerInput);
card.playerNumber = players.Count + 1;
cards.Add(card);
playerInput.transform.position = spawnPosition;
players.Add(playerInput.gameObject);
Colorize(playerInput.gameObject);
Colorize(players.Count - 1);
print("Player joined");
}
@@ -55,21 +63,45 @@ public class PlayerManager : MonoBehaviour
spawnPosition = transform.position;
}
private void Colorize(GameObject player)
public void StartGame()
{
foreach (Camera camera in FindObjectsByType<Camera>(FindObjectsSortMode.None))
{
camera.enabled = !camera.enabled;
}
foreach (GameObject player in players)
{
player.transform.position = spawnPosition;
player.GetComponent<Damageable>().damage = 0f;
}
Destroy(playerSelect);
}
private void Colorize(int index)
{
GameObject player = players[index];
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 _))
ApplyColor(player, color);
ApplyColor(cards[players.IndexOf(player)].playerPreview, color);
}
private void ApplyColor(GameObject obj, Color color)
{
if (obj.TryGetComponent<SpriteRenderer>(out _))
{
player.GetComponent<SpriteRenderer>().color = color;
obj.GetComponent<SpriteRenderer>().color = color;
}
foreach (Transform child in player.transform)
foreach (Transform child in obj.transform)
{
if (child.TryGetComponent<SpriteRenderer>(out _))
{
Colorize(child.gameObject);
ApplyColor(child.gameObject, color);
}
}
}

View File

@@ -1,7 +1,6 @@
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(PlayerMovement))]
[RequireComponent(typeof(PlayerInput))]
[RequireComponent(typeof(AnimationPlayer))]
public class Punch : MonoBehaviour
@@ -35,12 +34,12 @@ public class Punch : MonoBehaviour
public void EnableHurtbox()
{
hurtbox.enabled = true;
if (hurtbox != null) hurtbox.enabled = true;
}
public void DisableHurtbox()
{
hurtbox.enabled = false;
if (hurtbox != null) hurtbox.enabled = false;
}
public void DisableCancellation()