I am doing a CHAOS check in. showing support for one another. I need SIX jacks to post, not share, this message to show you are always there to kill chaos if someone needs it. let's go gentlemen...
This commit is contained in:
@@ -21,11 +21,7 @@ public partial class AreaExit : Node3D
|
||||
if (node.GetType() == typeof(Character2))
|
||||
_gameManager.RemoveCharacterAndAddToExit((Character2)node);
|
||||
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
if (!_gameManager.Players.ElementAt(0).CharactersLeftOnStage.Any())
|
||||
{
|
||||
if (!_gameManager.Players.Any(x => x.CharactersLeftOnStage.Any()))
|
||||
_gameManager.OnLevelClear();
|
||||
main.LoadNextLevel(_levelIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,8 @@ public partial class BasicEnemy : Node3D
|
||||
|
||||
public void OnEnemyHit(Node3D node)
|
||||
{
|
||||
var currentLevel = (Level)GetTree().GetFirstNodeInGroup("Level");
|
||||
currentLevel.OnEnemyDefeated((Node3D)GetParent());
|
||||
QueueFree();
|
||||
if (_gameManager.CheckAllEnemiesDefeated())
|
||||
{
|
||||
_gameManager.OnAllEnemiesDefeated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,14 @@ public partial class GameManager : Node
|
||||
|
||||
public IEnumerable<Player> Players = new List<Player>();
|
||||
|
||||
private int _levelIndex;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
foreach (var playerScene in PlayerScenes)
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
for (var i = 0; i < main.NumberOfPlayers; i++)
|
||||
{
|
||||
var player = playerScene.Instantiate();
|
||||
var player = PlayerScenes[i].Instantiate();
|
||||
Players = Players.Append((Player)player);
|
||||
GetTree().Root.AddChild(player);
|
||||
}
|
||||
@@ -34,15 +37,11 @@ public partial class GameManager : Node
|
||||
{
|
||||
GD.Print("All enemies defeated");
|
||||
P1CharactersOut.AddRange(Players.ElementAt(0).CharactersLeftOnStage);
|
||||
P2CharactersOut.AddRange(Players.ElementAt(1).CharactersLeftOnStage);
|
||||
if (Players.Count() == 2)
|
||||
P2CharactersOut.AddRange(Players.ElementAt(1).CharactersLeftOnStage);
|
||||
OnLevelClear();
|
||||
}
|
||||
|
||||
public bool CheckAllEnemiesDefeated()
|
||||
{
|
||||
return !GetTree().GetNodesInGroup("Enemy").Any();
|
||||
}
|
||||
|
||||
public void OnHandleCharacterSelectUI(Player player)
|
||||
{
|
||||
EmitSignal(SignalName.ReselectCharacter, player);
|
||||
@@ -115,15 +114,27 @@ public partial class GameManager : Node
|
||||
public void OnLevelClear()
|
||||
{
|
||||
Players.ElementAt(0).CharactersLeftOnStage.AddRange(P1CharactersOut);
|
||||
Players.ElementAt(1).CharactersLeftOnStage.AddRange(P2CharactersOut);
|
||||
if (Players.Count() == 2)
|
||||
Players.ElementAt(1).CharactersLeftOnStage.AddRange(P2CharactersOut);
|
||||
|
||||
P1CharactersOut.Clear();
|
||||
P2CharactersOut.Clear();
|
||||
if (Players.Count() == 2)
|
||||
P2CharactersOut.Clear();
|
||||
|
||||
Players.ElementAt(0)._characterIndex = 0;
|
||||
Players.ElementAt(1)._characterIndex = 0;
|
||||
if (Players.Count() == 2)
|
||||
Players.ElementAt(1)._characterIndex = 0;
|
||||
|
||||
EmitSignal(SignalName.ReselectCharacter, Players.ElementAt(0));
|
||||
var players = GetTree().GetNodesInGroup("Player");
|
||||
foreach (var player in players)
|
||||
GetTree().Root.RemoveChild(player);
|
||||
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
|
||||
main.LoadNextLevel(_levelIndex++);
|
||||
|
||||
foreach (var player in Players)
|
||||
EmitSignal(SignalName.ReselectCharacter, player);
|
||||
}
|
||||
|
||||
public bool IsGameOver => _gameOver;
|
||||
|
||||
@@ -1,6 +1,35 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Level : Node3D
|
||||
{
|
||||
[Export]
|
||||
private Array<PackedScene> _enemyScenes;
|
||||
[Export]
|
||||
private Array<Node3D> _spawnPoints;
|
||||
|
||||
private Array<Node3D> _enemies = new Array<Node3D>();
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
for (var i = 0; i < _enemyScenes.Count; i++)
|
||||
{
|
||||
var enemy = _enemyScenes[i].Instantiate();
|
||||
var convertedNode = (Node3D)enemy;
|
||||
GetTree().Root.AddChild(convertedNode);
|
||||
_enemies.Add(convertedNode);
|
||||
//convertedNode.Transform = _spawnPoints[i].Transform;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnemyDefeated(Node3D enemyDefeated)
|
||||
{
|
||||
_enemies.Remove(enemyDefeated);
|
||||
if (!_enemies.Any())
|
||||
_gameManager.OnAllEnemiesDefeated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,20 @@ public partial class Main : Node
|
||||
[Export]
|
||||
public PackedScene GameManager;
|
||||
|
||||
public int NumberOfPlayers = 0;
|
||||
|
||||
public void LoadLevel(int indexToLoad, int numberOfPlayers)
|
||||
{
|
||||
var sceneToLoad = Levels.ElementAt(indexToLoad);
|
||||
CallDeferred(nameof(DeferredGoToScene), sceneToLoad);
|
||||
|
||||
NumberOfPlayers = numberOfPlayers;
|
||||
|
||||
var gameManager = GameManager.Instantiate();
|
||||
AddChild(gameManager);
|
||||
var gameManagerInstance = (GameManager)gameManager;
|
||||
|
||||
gameManagerInstance.OnHandleCharacterSelectUI(gameManagerInstance.Players.ElementAt(0));
|
||||
|
||||
if (numberOfPlayers == 2)
|
||||
gameManagerInstance.OnHandleCharacterSelectUI(gameManagerInstance.Players.ElementAt(1));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class MainMenu : Node2D
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ public partial class StageGUI : Control
|
||||
}
|
||||
}
|
||||
|
||||
if (player == _gameManager.Players.ElementAt(1))
|
||||
if (_gameManager.Players.Count() == 2 && player == _gameManager.Players.ElementAt(1))
|
||||
{
|
||||
if (Input.IsActionJustPressed("p2_right"))
|
||||
_gameManager.SetToNextCharacter(_gameManager.Players.ElementAt(1));
|
||||
|
||||
Reference in New Issue
Block a user