Ejemplo n.º 1
0
    public void TakeDamage(int damage)
    {
        currHealth = Mathf.Clamp(currHealth - damage, 0, maxHealth);
        UpdateHealthBar();

        if (currHealth <= 0)
        {
            // 죽는 로직
            status = STATUS.DEAD;
            animState.ChangeAnimState(3);
            GetComponent <Collider2D>().enabled = false;


            // grid blinking cancel
            List <Grid> gridsToCancelBlinking = new List <Grid>();
            switch (code)
            {
            case "P0":
                GridMgr.PawnMoveOnGrid(GetComponent <FriendlyPieceMover>().currGrid, out gridsToCancelBlinking);
                break;

            case "K0":
                GridMgr.KnightMoveOnGrid(GetComponent <FriendlyPieceMover>().currGrid, out gridsToCancelBlinking);
                break;

            case "R0":
                GridMgr.RookMoveOnGrid(GetComponent <FriendlyPieceMover>().currGrid, out gridsToCancelBlinking);
                break;

            default:
                break;
            }

            if (gridsToCancelBlinking.Count > 0)
            {
                foreach (var grid in gridsToCancelBlinking)
                {
                    grid.isBlinking = false;
                }
            }
        }

        else if (currHealth / (float)maxHealth <= 0.3f)
        {
            // 30% 이하일 경우 기물의 모습이 변함.
            status = STATUS.BAD;
            if (doesHealthStateChangeSprite)
            {
                SetColor(true);
            }
            // Pawn Exception
            if (code == "P0")
            {
                FeatherDisplayHandle();
            }
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (isMovingModeOfThisPiece_next != isMovingModeOfThisPiece)
        {
            if (isMovingModeOfThisPiece_next && !isMovingModeOfThisPiece) // {???}Mode -> MovingMode
            {
                isMovingModeOfThisPiece = isMovingModeOfThisPiece_next;

                // 이동 가능한 grid들을 구하고
                switch (GetComponent <Health>().code)
                {
                case "P0":
                    GridMgr.PawnMoveOnGrid(currGrid, out blinkingGrid);
                    break;

                case "K0":
                    GridMgr.KnightMoveOnGrid(currGrid, out blinkingGrid);
                    break;

                case "R0":
                    GridMgr.RookMoveOnGrid(currGrid, out blinkingGrid);
                    break;

                default:
                    break;
                }

                // 갈수 있는 grid가 없을경우
                if (blinkingGrid.Count == 0)
                {
                    pointerMgr.selectedMovingPiece = null;
                    isMovingModeOfThisPiece_next   = false;
                    pointerMgr.PointerMode         = PointerMgr.Mode.None;
                }

                // grid들을 blinking
                foreach (var grid in blinkingGrid)
                {
                    grid.isBlinking = true;
                }
            }
            else if (!isMovingModeOfThisPiece_next && isMovingModeOfThisPiece) // MovingMode -> {???}Mode
            {
                isMovingModeOfThisPiece = isMovingModeOfThisPiece_next;

                foreach (var grid in blinkingGrid)
                {
                    grid.isBlinking = false;
                }

                blinkingGrid.Clear();
            }


            myAnim.SetBool("MovingBlinking", isMovingModeOfThisPiece);
        }
    }