Exemplo n.º 1
0
        async private Task PerformMovement()
        {
            if (enemyList.Count == 0)
            {
                if (!playerService.PlayerDeathStatus())
                {
                    gameService.ChangeToPlayerState();
                }
                return;
            }

            List <IEnemyController> KillableEnemies = new List <IEnemyController>();
            List <Task>             taskToKill      = new List <Task>();

            Task moveTask;

            for (int i = 0; i < enemyList.Count; i++)
            {
                IEnemyController controller = enemyList[i];
                if (!playerService.PlayerDeathStatus())
                {
                    if (CheckForEnemyPresence(controller, playerService.GetPlayerNodeID()) && CheckForKillablePlayer(controller.GetEnemyType()))
                    {
                        KillableEnemies.Add(controller);
                        continue;
                    }
                    else
                    {
                        moveTask = controller.Move();
                        moveTaskList.Add(moveTask);
                    }
                }
            }
            await Task.WhenAll(moveTaskList.ToArray());

            moveTaskList.Clear();

            IEnemyController controllerToKill;

            for (int i = 0; i < KillableEnemies.Count; i++)
            {
                controllerToKill = KillableEnemies[i];
                KillEnemy(controllerToKill);
            }

            if (!playerService.PlayerDeathStatus())
            {
                gameService.ChangeToPlayerState();
            }
        }
Exemplo n.º 2
0
    private void Update()
    {
        if (target == null)
        {
            return;
        }
        CalculatePath();
        if (path == null)
        {
            return;
        }
        float   waypointDistance = GetWaypointDistance();
        var     speedFactor      = reachedEndOfPath ? Mathf.Sqrt(waypointDistance / nextWaypointDistance) : 1f;
        Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized;

        controller.Move(dir, speedFactor);
    }
Exemplo n.º 3
0
 public void Move(Rigidbody2D body, float speed, Vector2 direction)
 {
     enemyController.Move(body, speed, direction);
 }