Set game over for character condition
This commit is contained in:
@@ -8,9 +8,9 @@ public partial class GameManager : Node
|
||||
public bool IsP2SelectingCharacter = true;
|
||||
|
||||
[Export]
|
||||
private Array<PackedScene> _p1Characters;
|
||||
public Array<PackedScene> _p1Characters;
|
||||
[Export]
|
||||
private Array<PackedScene> _p2Characters;
|
||||
public Array<PackedScene> _p2Characters;
|
||||
|
||||
[Export]
|
||||
public Character _p1SelectedCharacter;
|
||||
@@ -18,6 +18,8 @@ public partial class GameManager : Node
|
||||
[Export]
|
||||
public Character _p2SelectedCharacter;
|
||||
|
||||
public bool P1GameOver = false;
|
||||
|
||||
private int _p1CharacterIndex = 0;
|
||||
private int _p2CharacterIndex = 0;
|
||||
|
||||
@@ -27,15 +29,19 @@ public partial class GameManager : Node
|
||||
|
||||
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 void RemoveP1Character()
|
||||
{
|
||||
_p1Characters.Remove(_p1Characters.ElementAt(_p1CharacterIndex));
|
||||
_p1SelectedCharacter?.QueueFree();
|
||||
_p1CharacterIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Character : CharacterBody3D
|
||||
|
||||
@@ -82,8 +82,19 @@ public partial class Player1 : Character
|
||||
CanShoot = true;
|
||||
}
|
||||
|
||||
private void HitDebug()
|
||||
{
|
||||
var node = new Node3D();
|
||||
OnHit(node);
|
||||
}
|
||||
|
||||
private void OnHit(Node3D node)
|
||||
{
|
||||
QueueFree();
|
||||
_gameManager.RemoveP1Character();
|
||||
if (_gameManager._p1Characters.Count == 0)
|
||||
{
|
||||
GD.Print("Game over for P1");
|
||||
_gameManager.P1GameOver = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ public partial class StageGUI : Control
|
||||
|
||||
public void OnCharacterSelect()
|
||||
{
|
||||
if (_gameManager.P1GameOver)
|
||||
return;
|
||||
|
||||
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
||||
var wheel2 = GetNode<TextureRect>("CharacterSelect/Wheel2");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user