コード例 #1
0
    public void Execute()
    {
        foreach (var entity in _entities)
        {
            var position = entity.position.value;
            var level    = _levelContext.GetEntityWithLevel(position.levelId).level;
            var x        = GetRandomPosition(position.x, level.columns);
            var y        = GetRandomPosition(position.x, level.rows);

            entity.ReplaceMoveCommand(new IntVector2(x - position.x, y - position.y), GameBoardElementPosition.Create(position.levelId, x, y));
        }
    }
コード例 #2
0
    private void HandleEntity(GameEntity entity)
    {
        var targetPosition = entity.moveCommand.targetPosition;

        entity.RemoveMoveCommand();

        var level = _levelContext.GetEntityWithLevel(targetPosition.levelId).level;

        if (targetPosition.x < 0 || targetPosition.x >= level.columns || targetPosition.y < 0 ||
            targetPosition.x >= level.rows)
        {
            entity.ReplaceMoveCanceled("out of bounds");
            return;
        }

//    UnityEngine.Profiling.Profiler.BeginSample("Retrieve Blockers 2");
//
//    var hasBlockers1 = CheckForBlockers2(targetPosition);
//
////      .Any(targetEntity => targetEntity.isPhysicalBarrier);
//    UnityEngine.Profiling.Profiler.EndSample();

        UnityEngine.Profiling.Profiler.BeginSample("Retrieve Blockers");

        var hasBlockers = CheckForBlockers2(targetPosition);

//      .Any(targetEntity => targetEntity.isPhysicalBarrier);
        UnityEngine.Profiling.Profiler.EndSample();

        if (hasBlockers)
        {
            entity.ReplaceMoveCanceled("blocked");
//      entity.RemoveMoveCommand();
            return;
        }

        entity.AddMoveAction(targetPosition);
    }