Пример #1
0
 private void CheckRemainingDistance()
 {
     if (Vector3.Distance(transform.position, agent.destination) <= REPORT_REACHED_DISTANCE)
     {
         OnReachDestination?.Invoke();
     }
 }
Пример #2
0
 public override void OnTurn()
 {
     base.OnTurn();
     if (moving && !fighting)
     {
         Queue <Unit> queue;
         if (!Game.UnitPositionQueues.ContainsKey(blockingPos))
         {
             queue = new Queue <Unit>();
             Game.UnitPositionQueues[blockingPos] = queue;
         }
         else
         {
             queue = Game.UnitPositionQueues[blockingPos];
         }
         if (!queue.Contains(this))
         {
             queue.Enqueue(this);
         }
         if (Game.UnitBlockedPositions.Contains(blockingPos) || queue.Peek() != this)
         {
             OnIdle?.Invoke();
             idle = true;
             Game.UnitBlockedPositions.Add(blockingPos - areaRangeDelta);
             return;
         }
         if (idle)
         {
             Game.UnitBlockedPositions.Remove(blockingPos - areaRangeDelta);
         }
         Position += moveDelta;
         if (Position == blockingPos)
         {
             queue.Dequeue();
             blockingPos += areaRangeDelta;
         }
         if (Position == destination)
         {
             moving = false;
             OnReachDestination?.Invoke();
             if (Position == Game.Map.Bounds.LeftDown && Owner == Game.RightPlayer ||
                 Position == Game.Map.Bounds.RightDown && Owner == Game.LeftPlayer)
             {
                 Game.EndGame(Owner);
             }
         }
     }
 }
Пример #3
0
        public override void Update()
        {
            if (!direction.HasValue)
            {
                GetDirection();
            }

            Vec2D nextPoint = gameObject.transform.position;

            nextPoint += direction.Value * Speed * GameEngine.Instance.DeltaTime;

            gameObject.transform.LookAt(nextPoint);

            gameObject.transform.position = nextPoint;

            if (OnReachDestination != null && gameObject.transform.position > Destination)
            {
                OnReachDestination?.Invoke();
            }
        }
Пример #4
0
        public void Tick()
        {
            UpdateRotation();
            float x = mPlayer.transform.position.x;
            float y = mPlayer.transform.position.y;

            int i = (int)Mathf.Floor(x + 0.5f) - mGenerator.START_X;
            int j = (int)Mathf.Floor(y + 0.5f) - mGenerator.START_Y;

            if (i < 0 || j < 0 || i > mGenerator.cols - 1 || j > mGenerator.rows - 1)
            {
                return;
            }

            Maze.Cell cell = mGenerator.maze.GetCell(i, j);

            if (player_moving)
            {
                return;
            }

            //mPlayer.transform.rotation = Quaternion.Lerp(
            //    mPlayer.transform.rotation, Quaternion.Euler(0.0f, 0.0f, mCurrentAngle),
            //    Time.deltaTime * 10.0f);

            if (!cell.flag[0])
            {
                if (j < mGenerator.rows - 1 && my > 0.0f /* && Mathf.Abs(my) > Mathf.Abs(mx)*/)
                {
                    StartCoroutine(Coroutine_MoveOverSeconds(mPlayer,
                                                             new Vector3(
                                                                 i + mGenerator.START_X,
                                                                 j + mGenerator.START_Y +
                                                                 1, 0.0f),
                                                             1.0f / mSpeed));
                }
            }
            if (!cell.flag[1])
            {
                // can go right.
                if (i < mGenerator.cols - 1 && mx > 0.0f /* && Mathf.Abs(mx) > Mathf.Abs(my)*/)
                {
                    StartCoroutine(Coroutine_MoveOverSeconds(mPlayer,
                                                             new Vector3(
                                                                 i + mGenerator.START_X + 1,
                                                                 j + mGenerator.START_Y,
                                                                 0.0f),
                                                             1.0f / mSpeed));
                }
            }
            if (!cell.flag[2])
            {
                if (j > 0 && my < 0.0f /* && Mathf.Abs(my) > Mathf.Abs(mx)*/)
                {
                    Vector3 a = mPlayer.transform.position;
                    Vector3 b = new Vector3(i + mGenerator.START_X, j + mGenerator.START_Y - 1, 0.0f);

                    StartCoroutine(Coroutine_MoveOverSeconds(mPlayer,
                                                             new Vector3(
                                                                 i + mGenerator.START_X,
                                                                 j + mGenerator.START_Y - 1,
                                                                 0.0f),
                                                             1.0f / mSpeed));
                }
            }
            if (!cell.flag[3])
            {
                // can go left.
                if (i > 0 && mx < 0.0f /* && Mathf.Abs(mx) > Mathf.Abs(my)*/)
                {
                    StartCoroutine(Coroutine_MoveOverSeconds(mPlayer,
                                                             new Vector3(
                                                                 i + mGenerator.START_X - 1,
                                                                 j + mGenerator.START_Y,
                                                                 0.0f),
                                                             1.0f / mSpeed));
                }
            }

            if (cell.x == mGenerator.cols - 1 && cell.y == mGenerator.rows - 1)
            {
                Debug.Log("Win");

                StartCoroutine(Coroutine_MoveOverSeconds(mPlayer, new Vector3(i + mGenerator.START_X + 4,
                                                                              j + mGenerator.START_Y, 0.0f), 1.0f / mSpeed));
                mOnReachDestination?.Invoke();
            }
        }