Initial character select implementation
This commit is contained in:
43
Scripts/GameManager.cs
Normal file
43
Scripts/GameManager.cs
Normal 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
|
||||
{
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class P1SpawnPoint : Marker3D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player1");
|
||||
if (players.Any())
|
||||
{
|
||||
var player = (TestCharacter)players.First();
|
||||
player.Position = Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class P2SpawnPoint : Marker3D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player2");
|
||||
if (players.Any())
|
||||
{
|
||||
var player = (Player2)players.First();
|
||||
player.Position = Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
public partial class TestCharacter : CharacterBody3D
|
||||
public partial class Player1 : Character
|
||||
{
|
||||
[Export]
|
||||
private float _speed = 5.0f;
|
||||
@@ -9,17 +9,23 @@ public partial class TestCharacter : CharacterBody3D
|
||||
[Export]
|
||||
private PackedScene _altFireProjectile;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public bool CanShoot { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CanShoot = true;
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Velocity = CalculateCharacterMovement(delta);
|
||||
MoveAndSlide();
|
||||
if (!_gameManager.IsP1SelectingCharacter)
|
||||
{
|
||||
Velocity = CalculateCharacterMovement(delta);
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
@@ -27,10 +33,13 @@ public partial class TestCharacter : CharacterBody3D
|
||||
if (Input.IsActionJustPressed("exit"))
|
||||
GetTree().Quit();
|
||||
|
||||
if (Input.IsActionJustPressed("p1_fire") && CanShoot)
|
||||
Fire();
|
||||
if (Input.IsActionJustPressed("p1_altfire") && CanShoot)
|
||||
AltFire();
|
||||
if (!_gameManager.IsP1SelectingCharacter)
|
||||
{
|
||||
if (Input.IsActionJustPressed("p1_fire") && CanShoot)
|
||||
Fire();
|
||||
if (Input.IsActionJustPressed("p1_altfire") && CanShoot)
|
||||
AltFire();
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 CalculateCharacterMovement(double delta)
|
||||
10
Scripts/SpawnPoint.cs
Normal file
10
Scripts/SpawnPoint.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Godot;
|
||||
|
||||
public partial class SpawnPoint : Marker3D
|
||||
{
|
||||
public void SetPlayerPosition(Character character)
|
||||
{
|
||||
GD.Print("Moving character to spawn point");
|
||||
character.Position = Position;
|
||||
}
|
||||
}
|
||||
47
Scripts/StageGUI.cs
Normal file
47
Scripts/StageGUI.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Godot;
|
||||
|
||||
public partial class StageGUI : Control
|
||||
{
|
||||
[Signal]
|
||||
public delegate void OnCharacterSelectionMadeEventHandler();
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
}
|
||||
|
||||
public void OnCharacterSelect()
|
||||
{
|
||||
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
||||
var wheel2 = GetNode<TextureRect>("CharacterSelect/Wheel2");
|
||||
|
||||
wheel1.FocusMode = FocusModeEnum.All;
|
||||
wheel1.GrabFocus();
|
||||
wheel1.Visible = true;
|
||||
_gameManager.IsP1SelectingCharacter = true;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
||||
|
||||
if (wheel1.HasFocus())
|
||||
{
|
||||
if (Input.IsActionJustPressed("p1_right"))
|
||||
_gameManager.SetP1ToNextCharacter();
|
||||
if (Input.IsActionJustPressed("p1_left"))
|
||||
_gameManager.SetP1ToPreviousCharacter();
|
||||
|
||||
if (Input.IsActionJustPressed("p1_fire"))
|
||||
{
|
||||
GD.Print("Selected character");
|
||||
wheel1.ReleaseFocus();
|
||||
wheel1.Hide();
|
||||
_gameManager.IsP1SelectingCharacter = false;
|
||||
EmitSignal(SignalName.OnCharacterSelectionMade);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public partial class TestEnemy : RigidBody3D
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var player = GetTree().GetFirstNodeInGroup("Player") as TestCharacter;
|
||||
var player = GetTree().GetFirstNodeInGroup("Player") as Player1;
|
||||
if (player != null)
|
||||
LookAt(player.Position);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public partial class TestLevel : Node3D
|
||||
public override void _Ready()
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player");
|
||||
foreach (TestCharacter player in players)
|
||||
foreach (Player1 player in players)
|
||||
player.Transform = _spawnPoint.Transform;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user