Initial character select implementation

This commit is contained in:
2023-09-03 15:06:39 -07:00
parent a15973a621
commit f7417d0afd
26 changed files with 269 additions and 154 deletions

43
Scripts/GameManager.cs Normal file
View File

@@ -0,0 +1,43 @@
using Godot;
using Godot.Collections;
using System.Linq;
public partial class GameManager : Node
{
public bool IsP1SelectingCharacter = true;
public bool IsP2SelectingCharacter = true;
[Export]
private Array<PackedScene> _p1Characters;
[Export]
private Array<PackedScene> _p2Characters;
[Export]
public Character _p1SelectedCharacter;
[Export]
public Character _p2SelectedCharacter;
private int _p1CharacterIndex = 0;
private int _p2CharacterIndex = 0;
public void SetP1ToNextCharacter() => _p1CharacterIndex = (++_p1CharacterIndex) % _p1Characters.Count();
public void SetP1ToPreviousCharacter() => _p1CharacterIndex = _p1CharacterIndex == 0 ? _p1Characters.Count() : --_p1CharacterIndex;
public void OnP1CharacterSelected()
{
if (_p1SelectedCharacter != null)
_p1SelectedCharacter.QueueFree();
var selectedPlayer = _p1Characters[_p1CharacterIndex].Instantiate();
_p1SelectedCharacter = selectedPlayer as Character;
GetTree().Root.AddChild(_p1SelectedCharacter);
var playerSpawnPoint = GetNode<SpawnPoint>("P1SpawnPoint");
playerSpawnPoint.SetPlayerPosition(_p1SelectedCharacter);
}
}
public partial class Character : CharacterBody3D
{
}