Пример #1
0
    private void FixedUpdate()
    {
        // player is not ready, not player's turn or player already moved
        if (entity == null || !isInputEnabled || alreadyMovedInCurrentTurn)
        {
            return;
        }
        Vector2Int movementInput = GetMovementInputVector();

        // no input given
        if (movementInput == Vector2Int.zero)
        {
            return;
        }
        ICell nextCell = entity.cell.ConnectionAt(movementInput.ToSorcererDirection());

        // invalid movement direction
        if (nextCell == null || nextCell.isBlockingMovement)
        {
            return;
        }
        Entity enemy = map.FirstEntityAt(nextCell.position, e => e.isBlockingMovement);

        // entities are blocking movement
        if (enemy != null)
        {
            console.Append(entity.name + " attacked " + enemy.name);
        }
        else
        {
            entity.position = nextCell.position;
            console.Append(entity.name + " moved " + movementInput.ToSorcererDirection().ToString());
        }
        alreadyMovedInCurrentTurn = true;
    }
Пример #2
0
    public override IEnumerator WaitForAction()
    {
        Vector2Int movementInput;
        ICell      nextCell = null;

        while (nextCell == null || nextCell.isBlockingMovement)
        {
            movementInput = GetMovementInputVector();
            if (movementInput != Vector2Int.zero)
            {
                nextCell = entity.cell.ConnectionAt(movementInput.ToSorcererDirection());
            }
        }
        Entity enemy = map.FirstEntityAt(nextCell.position, e => e.isBlockingMovement);

        // entities are blocking movement
        if (enemy != null)
        {
            console.Append(entity.name + " attacks " + enemy.name);
        }
        else
        {
            entity.position = nextCell.position;
        }
        return(null);
    }