public static IndexDirection2 GetRandomTileDirection() { IndexDirection2[] allDirections = IndexDirection2.AllValidNonZeroDirections; IndexDirection2 dir = allDirections[Random.Range(0, allDirections.Length)]; return(dir); }
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; }
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); } } }
protected IndexDirection2 EnforceBoundary(IndexDirection2 desiredMoveDirection) { Vector3 vec = desiredMoveDirection.ToVector3(); vec = EnforceBoundary(vec); return(new IndexDirection2(vec)); }
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); } }
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); }
void PlayerEnteredNeighborSector(Index2 sector) { IndexDirection2 sectorDir = DirectionForNeighborSector(sector); IndexDirection2[] dirs = IndexDirection2.AllValidNonZeroDirections.Where(d => d != sectorDir).ToArray(); OverrideSectorsWithThisSector(dirs, true); }
public void MoveCursor(IndexDirection2 dir) { dir.FlipVertically(); if (_menuCursor.TryMoveCursor(dir)) { PlayCursorMoveSound(); } }
public void MoveCursor(IndexDirection2 dir) { dir.FlipVertically(); if (_cursor.TryMoveCursor(dir)) { //print("MoveCursor: " + dir); PlayCursorMoveSound(); } }
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; }
void Start() { _enemyMove.Mode = EnemyMove.MovementMode.Destination; _enemyMove.AlwaysFaceTowardsMoveDirection = faceTowardsMoveDirection; _enemyMove.targetPositionReached_Callback += OnTargetPositionReached; _baseSpeed = _enemyMove.speed; MoveDirection_Tile = new IndexDirection2(DetermineActualMoveDirection(GetRandomTileDirection())); }
void Awake() { _directionsList = new List <IndexDirection2>(); foreach (IndexDirection2.DirectionEnum dir in _directions) { _directionsList.Add(IndexDirection2.FromDirectionEnum(dir)); } PushingEnabled = true; }
void Slide(IndexDirection2 dir) { if (!CanSlideInDirection(dir)) { return; } Vector3 targetPos = transform.position + dir.ToVector3(); SlideToPosition(targetPos); }
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); }
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; }
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); }
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; }
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); }
protected bool CanMoveInDirection_Overworld(IndexDirection2 dir) { Index2 adjacentTile = _enemy.Tile + dir; return(CanOccupyTile_Overworld(adjacentTile)); }
protected bool DetectObstructions(IndexDirection2 dir, float distance) { return(DetectObstructions(dir.ToVector3(), distance)); }
bool CanSlideInDirection(IndexDirection2 dir) { return(_directionsList.Contains(dir)); }
LostSectorPortal DirectionToPortal(IndexDirection2 dir) { return(_directionToPortal[dir]); }
void Jump(IndexDirection2 dir) { MoveDirection_Tile = dir; _enemyMove.enabled = false; _enemy.Jump(MoveDirection_Tile.ToVector3()); }