66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public partial class Main : Node
|
|
{
|
|
public bool _isCommanderTurn = true;
|
|
public Commander _commander;
|
|
public GridMap2D _grid;
|
|
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
|
public List<Enemy> _enemies = new();
|
|
public Random _rng = new();
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
_commander = GetNode<Commander>("Commander");
|
|
_grid = GetNode<GridMap2D>("GridMap2D");
|
|
_commander.GlobalPosition = _grid.GlobalPosition;
|
|
_commander.TurnDone += ChangeTurn;
|
|
AddEnemy();
|
|
_commander.StartTurn();
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
base._Process(delta);
|
|
if (Input.IsActionJustPressed("escape"))
|
|
{
|
|
GetTree().Quit();
|
|
}
|
|
}
|
|
|
|
public void ChangeTurn()
|
|
{
|
|
_isCommanderTurn = !_isCommanderTurn;
|
|
if (_isCommanderTurn)
|
|
{
|
|
GD.Print("Starting Commander turn");
|
|
_commander.StartTurn();
|
|
}
|
|
else
|
|
{
|
|
GD.Print("Starting Enemy turn");
|
|
for (int i = 0; i < _enemies.Count; i++)
|
|
{
|
|
_enemies[i].TakeTurn();
|
|
}
|
|
|
|
AddEnemy();
|
|
ChangeTurn();
|
|
}
|
|
}
|
|
|
|
public void AddEnemy()
|
|
{
|
|
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
|
newEnemy.TurnDone += ChangeTurn;
|
|
newEnemy.PlaceOrMove(_grid._gridMarkers.Last()[_rng.Next(_grid._gridMarkers.Last().Count)]);
|
|
newEnemy._commander = _commander;
|
|
newEnemy._grid = _grid;
|
|
_enemies.Add(newEnemy);
|
|
AddChild(newEnemy);
|
|
}
|
|
}
|