Beispiel #1
0
    public static IndexDirection2 GetRandomTileDirection()
    {
        IndexDirection2[] allDirections = IndexDirection2.AllValidNonZeroDirections;
        IndexDirection2   dir           = allDirections[Random.Range(0, allDirections.Length)];

        return(dir);
    }
Beispiel #2
0
    void DetermineNextAction()
    {
        DiscreteAction desiredAction = GetDesiredAction();

        if (desiredAction == DiscreteAction.Attack)
        {
            Attack();
        }
        else if (desiredAction == DiscreteAction.Idle)
        {
            EnterIdleState();
        }
        else
        {
            IndexDirection2 desiredMoveDir = GetDesiredMoveDirection(desiredAction);
            if (desiredAction == DiscreteAction.Jump)
            {
                Jump(desiredMoveDir);
            }
            else
            {
                MoveDirection_Tile = DetermineActualMoveDirection(desiredMoveDir);
            }
        }

        _justFinishedIdling = false;
    }
Beispiel #3
0
    void OverrideSectorsWithThisSector(IndexDirection2 dir, bool doOverride)
    {
        if (dir == EscapeExitDirection)
        {
            return;
        }

        Index2 s = Sector;

        for (int i = 0; i < OVERRIDE_SECTOR_DISTANCE; i++)
        {
            s = s + dir;

            OverrideSectorWithThisSectorsVoxels(s, doOverride);

            if (doOverride)
            {
                DisableEnemySpawningInSector(s);
            }
            else
            {
                EnableEnemySpawningInSector(s);
            }
        }
    }
Beispiel #4
0
    protected IndexDirection2 EnforceBoundary(IndexDirection2 desiredMoveDirection)
    {
        Vector3 vec = desiredMoveDirection.ToVector3();

        vec = EnforceBoundary(vec);
        return(new IndexDirection2(vec));
    }
Beispiel #5
0
    void OnTriggerStay(Collider otherCollider)
    {
        if (!PushingEnabled)
        {
            return;
        }
        if (_isSliding || _hasFinishedSliding)
        {
            return;
        }

        GameObject other = otherCollider.gameObject;

        if (!CommonObjects.IsPlayer(other))
        {
            return;
        }
        if (requiresPowerBracelet && !Inventory.Instance.HasItem("PowerBracelet"))
        {
            return;
        }

        Player          player = CommonObjects.Player_C;
        IndexDirection2 dir    = GetPushDirection(player);

        if (!dir.IsZero())
        {
            Slide(dir);
        }
    }
Beispiel #6
0
    IndexDirection2 DetermineActualMoveDirection(IndexDirection2 desiredMoveDirection)
    {
        Vector3 desiredMoveDirection_Vec = desiredMoveDirection.ToVector3();

        IndexDirection2 chosenDirection;
        bool            canMove;
        float           turnAngle = 0;

        do
        {
            Vector3 v = Quaternion.Euler(0, turnAngle, 0) * desiredMoveDirection_Vec;
            chosenDirection = new IndexDirection2(v);

            if (WorldInfo.Instance.IsOverworld)
            {
                // TODO: Use IndexDirection2.AllValidDirections instead of turnAngle += 90
                canMove = CanMoveInDirection_Overworld(chosenDirection);
            }
            else
            {
                canMove = !DetectObstructions(chosenDirection, feelerLength);
            }

            turnAngle += 90;
        }while (!canMove && turnAngle < 360);

        return(chosenDirection);
    }
Beispiel #7
0
    void PlayerEnteredNeighborSector(Index2 sector)
    {
        IndexDirection2 sectorDir = DirectionForNeighborSector(sector);

        IndexDirection2[] dirs = IndexDirection2.AllValidNonZeroDirections.Where(d => d != sectorDir).ToArray();

        OverrideSectorsWithThisSector(dirs, true);
    }
Beispiel #8
0
 public void MoveCursor(IndexDirection2 dir)
 {
     dir.FlipVertically();
     if (_menuCursor.TryMoveCursor(dir))
     {
         PlayCursorMoveSound();
     }
 }
Beispiel #9
0
 public void MoveCursor(IndexDirection2 dir)
 {
     dir.FlipVertically();
     if (_cursor.TryMoveCursor(dir))
     {
         //print("MoveCursor: " + dir);
         PlayCursorMoveSound();
     }
 }
Beispiel #10
0
    void Start()
    {
        _enemyMove.Mode = EnemyMove.MovementMode.Destination;
        _enemyMove.AlwaysFaceTowardsMoveDirection  = false;
        _enemyMove.targetPositionReached_Callback += OnTargetPositionReached;

        _forwardTileDirection = IndexDirection2.FromDirectionEnum(forwardDirection);
        transform.forward     = _forwardTileDirection.ToVector3();
        MoveDirection_Tile    = _forwardTileDirection;
    }
Beispiel #11
0
    void Start()
    {
        _enemyMove.Mode = EnemyMove.MovementMode.Destination;
        _enemyMove.AlwaysFaceTowardsMoveDirection  = faceTowardsMoveDirection;
        _enemyMove.targetPositionReached_Callback += OnTargetPositionReached;

        _baseSpeed = _enemyMove.speed;

        MoveDirection_Tile = new IndexDirection2(DetermineActualMoveDirection(GetRandomTileDirection()));
    }
Beispiel #12
0
    void Awake()
    {
        _directionsList = new List <IndexDirection2>();
        foreach (IndexDirection2.DirectionEnum dir in _directions)
        {
            _directionsList.Add(IndexDirection2.FromDirectionEnum(dir));
        }

        PushingEnabled = true;
    }
Beispiel #13
0
    void Slide(IndexDirection2 dir)
    {
        if (!CanSlideInDirection(dir))
        {
            return;
        }

        Vector3 targetPos = transform.position + dir.ToVector3();

        SlideToPosition(targetPos);
    }
Beispiel #14
0
    IndexDirection2 GetDesiredMoveDirection(DiscreteAction action)
    {
        IndexDirection2 desiredMoveDir = IndexDirection2.zero;
        IndexDirection2 toPlayer       = IndexDirection2.zero;

        _enemyMove.speed = _baseSpeed;

        if (_enemy.ShouldFollowBait())
        {
            desiredMoveDir = GetDirectionToBait();
        }
        else if (chasePlayerIfInSight && IsPlayerInSight(MAX_DISTANCE_PLAYER_CAN_BE_SEEN, out toPlayer))
        {
            _enemyMove.speed = _baseSpeed * chaseSpeedMultiplier;

            desiredMoveDir = toPlayer;
        }
        else
        {
            if (MoveDirection_Tile.IsZero())
            {
                desiredMoveDir = GetRandomTileDirection();
            }
            else
            {
                if (action == DiscreteAction.ChangeDirection)
                {
                    List <IndexDirection2> excludeDirections = new List <IndexDirection2>();
                    excludeDirections.Add(MoveDirection_Tile);
                    if (avoidsReversingDirections)
                    {
                        excludeDirections.Add(MoveDirection_Tile.Reversed);
                    }

                    desiredMoveDir = GetRandomTileDirectionExcluding(excludeDirections);
                }
                else if (action == DiscreteAction.Jump)
                {
                    desiredMoveDir = GetRandomTileDirection();
                }
                else
                {
                    desiredMoveDir = MoveDirection_Tile;
                }
            }
        }

        if (!WorldInfo.Instance.IsInDungeon)
        {
            desiredMoveDir = EnforceBoundary(desiredMoveDir);
        }

        return(desiredMoveDir);
    }
    void UpdateCursor()
    {
        if (ControlsViewActive)
        {
            return;
        }

        float           moveVert = ZeldaInput.GetCommand_Float(ZeldaInput.Cmd_Float.MenuNavVertical);
        IndexDirection2 dir      = new IndexDirection2(0, moveVert);

        _optionsView.MoveCursor(dir);
    }
Beispiel #16
0
    void SetNextMoveDirection()
    {
        Vector3 p = transform.position;

        IndexDirection2 newMoveDir = IndexDirection2.zero;

        if (MoveDirection_Tile.IsDown())
        {
            if (p.z <= Boundary.yMin)
            {
                newMoveDir = IndexDirection2.up;
            }
        }
        else if (MoveDirection_Tile.IsUp())
        {
            if (p.z >= Boundary.yMax)
            {
                newMoveDir = (Extensions.FlipCoin()) ? IndexDirection2.left : IndexDirection2.right;
            }
        }
        else
        {
            if (Extensions.FlipCoin(chanceToMoveDown))
            {
                newMoveDir = IndexDirection2.down;
            }
            else
            {
                if (MoveDirection_Tile.IsRight())
                {
                    if (p.x >= Boundary.xMax)
                    {
                        newMoveDir = IndexDirection2.left;
                    }
                }
                else if (MoveDirection_Tile.IsLeft())
                {
                    if (p.x <= Boundary.xMin)
                    {
                        newMoveDir = IndexDirection2.right;
                    }
                }
            }
        }

        if (newMoveDir.IsZero())
        {
            newMoveDir = MoveDirection_Tile;
        }

        MoveDirection_Tile = newMoveDir;
    }
Beispiel #17
0
    virtual protected bool IsPlayerInSight(float maxDistance, out IndexDirection2 direction)
    {
        foreach (IndexDirection2 dir in IndexDirection2.AllValidNonZeroDirections)
        {
            if (IsPlayerInLineOfSight(maxDistance, dir.ToVector3()))
            {
                direction = dir;
                return(true);
            }
        }

        direction = IndexDirection2.zero;
        return(false);
    }
    void UpdateCursor()
    {
        int numSelectableItems = GetSelectableItems().Count;

        if (numSelectableItems == 0)
        {
            return;
        }

        float           moveHorz = ZeldaInput.GetCommand_Float(ZeldaInput.Cmd_Float.MenuNavHorizontal);
        float           moveVert = ZeldaInput.GetCommand_Float(ZeldaInput.Cmd_Float.MenuNavVertical);
        IndexDirection2 dir      = new IndexDirection2(moveHorz, moveVert);

        View.MoveCursor(dir);
    }
Beispiel #19
0
    void InitPasswordLock()
    {
        List <LostSectorPortal> solutionPortals = new List <LostSectorPortal>();

        foreach (IndexDirection2.DirectionEnum d in _solution)
        {
            IndexDirection2  dir    = IndexDirection2.FromDirectionEnum(d);
            LostSectorPortal portal = DirectionToPortal(dir);
            solutionPortals.Add(portal);
        }
        _passwordLock = new PasswordLock(solutionPortals.ToArray());

        _passwordLock.CorrectEntryCallback           += OnCorrectEntryAddedToSequence;
        _passwordLock.IncorrectEntryCallback         += OnIncorrectEntryAddedToSequence;
        _passwordLock.CorrectPasswordEnteredCallback += OnSequenceCompleted;
    }
Beispiel #20
0
    public bool TryMoveCursor(IndexDirection2 dir)
    {
        if (dir.IsZero() || _cursorCooldownActive)
        {
            return(false);
        }

        Index2 n = _cursorIndex + dir;

        if (wraps)
        {
            if (n.x < 0)
            {
                n.x += numColumns;
            }
            else if (n.x >= numColumns)
            {
                n.x -= numColumns;
            }

            if (n.y < 0)
            {
                n.y += numRows;
            }
            else if (n.y >= numRows)
            {
                n.y -= numRows;
            }
        }

        CursorIndex = n;

        StartCursorCooldownTimer();

        return(true);
    }
Beispiel #21
0
    protected bool CanMoveInDirection_Overworld(IndexDirection2 dir)
    {
        Index2 adjacentTile = _enemy.Tile + dir;

        return(CanOccupyTile_Overworld(adjacentTile));
    }
Beispiel #22
0
 protected bool DetectObstructions(IndexDirection2 dir, float distance)
 {
     return(DetectObstructions(dir.ToVector3(), distance));
 }
Beispiel #23
0
 bool CanSlideInDirection(IndexDirection2 dir)
 {
     return(_directionsList.Contains(dir));
 }
Beispiel #24
0
 LostSectorPortal DirectionToPortal(IndexDirection2 dir)
 {
     return(_directionToPortal[dir]);
 }
Beispiel #25
0
 void Jump(IndexDirection2 dir)
 {
     MoveDirection_Tile = dir;
     _enemyMove.enabled = false;
     _enemy.Jump(MoveDirection_Tile.ToVector3());
 }