Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        playerGO    = GameObject.FindGameObjectWithTag("Player");
        playerSkill = playerGO.GetComponent <PlayerSkill>();

        anim        = GetComponent <Animator>();
        rb          = GetComponent <Rigidbody2D>();
        spriteRen   = GetComponent <SpriteRenderer>();
        sandworm_HP = GetComponent <SandwormHealth>();

        // Initialise values
        currMoveTime      = 0.0f;
        rangedAttackTimer = 0.0f;
        stateTimeTracker  = 0.0f;
        // Guard & Defaulted Values
        if (distThreshold <= 0)
        {
            distThreshold = 1.0f;
        }

        if (moveTime <= 0)
        {
            moveTime = 3.0f;
        }

        // Default state at the start
        currState = Sandworm_State.IDLE;

        healthTracker = sandworm_HP.health;
    }
Exemplo n.º 2
0
    public void ChangeState(int newState)
    {
        currState = (Sandworm_State)newState;

        if ((Sandworm_State)newState == Sandworm_State.RANGE_ATTACK)
        {
            stateTimeTracker = rangeStateTimer;
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        // Sandworm got damaged
        if (healthTracker > sandworm_HP.health)
        {
            healthTracker = sandworm_HP.health;

            // Change sandworm state
            currState = Sandworm_State.DIGGING;
        }

        if (stateTimeTracker > 0)
        {
            stateTimeTracker -= Time.deltaTime;
        }

        switch (currState)
        {
        case Sandworm_State.IDLE:
        {
            // Reset all attack relevant data
            rangedAttackTimer = 0.0f;

            rb.constraints = RigidbodyConstraints2D.FreezeAll;

            FaceDirection(playerGO.transform);
            break;
        }

        case Sandworm_State.DIGGING:
        {
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;

            if (anim.GetBool("Desurface") == false)
            {
                // Reset status condition
                sandworm_HP.TakeDamage();
                isDigging = true;
                Desurfacing();
            }
            else if (anim.enabled == false && spriteRen.enabled == false)
            {
                if (Move(playerGO.transform) == false || isDigging == false)
                {
                    isDigging = false;

                    // Re-render the sandworm
                    showSandworm();

                    // Play the resurfacing animation
                    Resurfacing();

                    // Change the state
                    currState = Sandworm_State.IDLE;

                    // Change animation
                    anim.SetBool("Desurface", false);
                }
            }
            break;
        }

        case Sandworm_State.RANGE_ATTACK:
        {
            rb.constraints = RigidbodyConstraints2D.FreezeAll;

            FaceDirection(playerGO.transform);

            // Timing to shoot
            if (rangedAttackTimer <= 0.0f)
            {
                RangeAttack();

                //if(RangeAttack())
                //    Debug.Log("Shoot at player");
            }
            else
            {
                rangedAttackTimer -= Time.deltaTime;
            }

            if (stateTimeTracker < 0)
            {
                currState = Sandworm_State.DIGGING;
            }

            break;
        }
        }

        // Testing purposes
        if (Input.GetKeyDown(KeyCode.P))
        {
            Resurfacing();
        }
        else if (Input.GetKeyDown(KeyCode.O))
        {
            Desurfacing();
        }
        else if (Input.GetKeyDown(KeyCode.L))
        {
            currState = Sandworm_State.RANGE_ATTACK;
        }
        else if (Input.GetKeyDown(KeyCode.I))
        {
            currState = Sandworm_State.DIGGING;
        }
        else if (Input.GetKeyDown(KeyCode.M))
        {
            Move(playerGO.transform);
        }
    }