private void TryMove() { if (Constance.RUNNING == false) { return; } if (this.running == false) { return; } this.nextPosition = GetNextPosition(); Vector2 nextPoint = BattleUtils.PositionToGrid(this.nextPosition.x, this.nextPosition.y); if (BattleControllor.IsMoveable(nextPoint) == false) { if (this.currentDirection != this.direction) { this.currentDirection = this.direction; if (this.follower != null) { follower.SetNextPosition(this._transform.localPosition); } } return; } //下个格子中的物体 ArrayList monsterList = BattleControllor.GetMonstersByPoint(nextPoint); if (this.position != nextPoint && monsterList.Count > 0) { //前方有障碍物 需要停止 if (this.currentDirection != this.direction) { this.currentDirection = this.direction; if (this.follower != null) { follower.SetNextPosition(this._transform.localPosition); } } return; } float moveDistance = Time.deltaTime * speed; if (this.currentDirection != this.direction) { this.currentDirection = this.direction; if (this.follower != null) { follower.SetNextPosition(this._transform.localPosition); } } Move(moveDistance); if (follower != null) { follower.Move(moveDistance); } }
private bool MoveAble() { switch (this.currentDirection) { case MoveDirection.DOWN: Vector2 v = nextPathPoint.point; v.y = v.y + this.attribute.volume - 1; for (int i = 0; i < this.attribute.volume; i++) { v.x = v.x + i; if (BattleControllor.IsMoveable(v) == false) { return(false); } if (BattleControllor.GetGameObjectsByPosition(v).Count > 0) { return(false); } } break; case MoveDirection.UP: v = nextPathPoint.point; for (int i = 0; i < this.attribute.volume; i++) { v.x = v.x + i; if (BattleControllor.IsMoveable(v) == false) { return(false); } if (BattleControllor.GetGameObjectsByPosition(v).Count > 0) { return(false); } } break; case MoveDirection.LEFT: v = nextPathPoint.point; for (int i = 0; i < this.attribute.volume; i++) { v.y = v.y + i; if (BattleControllor.IsMoveable(v) == false) { return(false); } if (BattleControllor.GetGameObjectsByPosition(v).Count > 0) { return(false); } } break; case MoveDirection.RIGHT: v = nextPathPoint.point; v.x = v.x + this.attribute.volume - 1; for (int i = 0; i < this.attribute.volume; i++) { v.y = v.y + i; if (BattleControllor.IsMoveable(v) == false) { return(false); } if (BattleControllor.GetGameObjectsByPosition(v).Count > 0) { return(false); } } break; } return(true); }