player movement
This commit is contained in:
parent
01a1278465
commit
46d2b7bc95
18 changed files with 1415 additions and 34 deletions
78
Assets/Scripts/TurnHandler.cs
Normal file
78
Assets/Scripts/TurnHandler.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class TurnHandler : MonoBehaviour
|
||||
{
|
||||
#region Statication
|
||||
|
||||
public static TurnHandler instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance != null && instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public List<PlayerEntity> playerEntities = new();
|
||||
public List<Enemy> enemyEntities = new();
|
||||
public enum GameState {PlayerTurn, EnemyTurn}
|
||||
public GameState currentGameState = GameState.PlayerTurn;
|
||||
|
||||
private int currentEnemy;
|
||||
|
||||
private void SortEnemies()
|
||||
{
|
||||
enemyEntities = enemyEntities.OrderBy(o=>o.turnSpeed).ToList();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SortEnemies();
|
||||
}
|
||||
|
||||
public void UpdateTurns()
|
||||
{
|
||||
if (currentGameState == GameState.PlayerTurn)
|
||||
{
|
||||
bool allDone = true;
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
if (!player.hasMoved || !player.hasAttacked)
|
||||
{
|
||||
allDone = false;
|
||||
}
|
||||
}
|
||||
if (allDone)
|
||||
{
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
player.hasMoved = false;
|
||||
player.hasAttacked = false;
|
||||
}
|
||||
//currentGameState = GameState.EnemyTurn;
|
||||
}
|
||||
}
|
||||
else if (currentGameState == GameState.EnemyTurn)
|
||||
{
|
||||
enemyEntities[currentEnemy].StartTurn();
|
||||
currentEnemy++;
|
||||
if (currentEnemy > enemyEntities.Count)
|
||||
{
|
||||
currentGameState = GameState.PlayerTurn;
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
player.hasMoved = false;
|
||||
player.hasAttacked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue