Ejemplo n.º 1
0
        private ShootDirection GetShootDirection(Direction toDirection)
        {
            ShootDirection result;

            var moveDirection = UtilMapHelpers.GetDirectionVector(toDirection);

            //Calculate the length of move direction
            float shootsqrMagnitude = moveDirection.sqrMagnitude;

            float x, y;

            //Calculate the right side vector first
            if (moveDirection.x == 0)
            {
                y = 0;
                x = Mathf.Sqrt(shootsqrMagnitude - y * y);
            }
            else if (moveDirection.y == 0)
            {
                x = 0;
                y = Mathf.Sqrt(shootsqrMagnitude - x * x);
            }
            else
            {
                x = Mathf.Sqrt(shootsqrMagnitude / (1 + Mathf.Pow(moveDirection.x / moveDirection.y, 2)));
                y = -(moveDirection.x / moveDirection.y) * x;
            }

            result.leftSide  = new Vector2((int)x, (int)y);
            result.rightSide = -result.leftSide;

            return(result);
        }
Ejemplo n.º 2
0
        //Check for the position which enemy attend to move is movable (Obstacle or other Enemy boat placed on it)
        private bool IsMovable(Direction dir)
        {
            //Calculate the attended move position
            Vector2 attendedMovePos = (Vector2)transform.position + UtilMapHelpers.GetDirectionVector(dir) * MapConstantProvider.Instance.TileSize;

            //Debug.Log("Attend direction: " + dir);
            return(!MapConstantProvider.Instance.ContainsPosInUnitDictionary(attendedMovePos));
        }
Ejemplo n.º 3
0
        protected void MoveAndRotate(Direction dir)
        {
            if (BoatState == BoatState.MoveAndRotate)
            {
                return;
            }

            DataObjectMove obj = new DataObjectMove(Type, (Vector2)transform.position, transform.rotation, isometricModel.transform.localRotation, currentDirection);

            allPreviousMoves.Push(obj);

            //Get input: target position, target direction
            targetDirection = dir;
            targetPosition  = (Vector2)transform.position + MapConstantProvider.Instance.TileSize * UtilMapHelpers.GetDirectionVector(targetDirection);

            PlayMovementSound();

            if (moveAndRotateCR != null)
            {
                StopCoroutine(moveAndRotateCR);
            }
            moveAndRotateCR = StartCoroutine(CR_MoveAndRotate(targetPosition, targetDirection, () => OnCompletedRotateAndMove()));
        }