예제 #1
0
    void Update()
    {
        animUpdate();

        if (targetsMove.Count > 0)
        {
            curState = states.walk;
            Vector3 moveVector = targetsMove[0].transform.position - transform.position;
            ch.Move(moveVector.normalized * speed * Time.deltaTime);
            transform.LookAt(targetsMove[0].transform.position);

            float dist = Mathf.Abs(Vector3.Distance(transform.position, targetsMove[0].transform.position));

            if (dist < 0.05f)
            {
                GameObject toDestroy = targetsMove[0];
                targetsMove.Remove(toDestroy);
                Destroy(toDestroy);
                if (targetsMove.Count == 0)
                {
                    OnMoveFinish?.Invoke();
                }
            }
        }
        else
        {
            if (targetAttack != null)
            {
                if (curState != states.attack)
                {
                    //Поворачиваем игроков друг к другу
                    transform.LookAt(targetAttack.transform.position);
                    targetAttack.transform.LookAt(transform.position);
                    curState = states.attack;
                }
            }
            else
            {
                if (curState == states.attack)
                {
                    curState = states.idle;
                }
            }
            //if (curState == states.walk || curState == states.impact || curState == states.block)
            if (curState != states.attack && curState != states.death)
            {
                curState = states.idle;
            }
        }
    }
예제 #2
0
        public async void OurMoveWasFinished(ChessMove ourMove)
        {
            clock.StartMe();

            foreach (Vector2Int pos in Board.IteratePositions())
            {
                PieceId pieceId = board.GetPieceIdAt(pos);

                if (pieceId == null)
                {
                    continue;
                }

                if (pieceId.color != color)
                {
                    continue;
                }

                await Task.Delay(Random.Range(500, 5_000));

                float duration = clock.StopMe();

                if (clock.IsTimeOverForMe())
                {
                    OnOutOfTime?.Invoke();
                    return;
                }

                OnMoveFinish?.Invoke(new ChessMove {
                    origin   = pos,
                    target   = FindFreeSpot(),
                    duration = duration
                });
                return;
            }

            throw new Exception();
        }
예제 #3
0
 protected virtual void FinishMove(Cell cell)
 {
     OnMoveFinish?.Invoke(this);
 }
예제 #4
0
 public void OtherSideFinishedMove(string jsonMove)
 {
     OnMoveFinish?.Invoke(
         Serializer.FromJsonString <ChessMove>(jsonMove)
         );
 }