51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public partial class Main : Node
|
|
{
|
|
public bool _isPlayerTurn = true;
|
|
public Player _player;
|
|
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
|
public List<Enemy> _enemies = new();
|
|
public Random _rng = new();
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
_player = GetNode<Player>("Player");
|
|
_player.TurnDone += ChangeTurn;
|
|
AddEnemy();
|
|
_player.StartTurn();
|
|
}
|
|
|
|
public void ChangeTurn()
|
|
{
|
|
_isPlayerTurn = !_isPlayerTurn;
|
|
if (_isPlayerTurn)
|
|
{
|
|
GD.Print("Starting Player turn");
|
|
_player.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.Position = new Vector2(_rng.Next((int)_player.GetViewportRect().Size.X), _player.GetViewportRect().Size.Y - 100);
|
|
newEnemy._player = _player;
|
|
_enemies.Add(newEnemy);
|
|
AddChild(newEnemy);
|
|
}
|
|
}
|