Example #1
0
    /**
     * openChest()
     *
     * Adds the contents of the chest to the player's inventory and raises the
     *  signal attached to it
     */
    public void openChest()
    {
        // TODO dialogWindow.SetActive(true);
        // TODO dialogText.text = contents.itemDescription;

        /* add contents of the chest to the player's inventory */
        playerInventory.addItem(chestContents);
        playerInventory.currentItem = chestContents;

        /* raise the signal that the item is being grabbed */
        raiseItem.raise();

        /* set the chest as opened */
        isOpen = true;

        /* set the bool to open the chest */
        chestAnim.SetBool("isOpened", true);

        //TODO context.raise();
    }
Example #2
0
    /**
     * knockbackCoroutine(float)
     *
     * This is the knockback coroutine for the player. Same as the enemy knockback
     *  but just tailored for the player
     *
     * @param knockbackTime: The amount of time the player should be knocked back for
     */
    private IEnumerator knockbackCoroutine(float knockbackTime)
    {
        /* raise the signal to let everyone subscribed know the player was hit */
        playerHit.raise();

        if (playerRigidBody != null)
        {
            /* wait for the amount of time for the knockback */
            yield return(new WaitForSeconds(knockbackTime));

            /* set the player's velocity to zero after the knockback is done */
            playerRigidBody.velocity = Vector2.zero;

            /* after the knockback the player should be idle */
            currentState = PlayerState.idle;

            /* this prevents the player from sliding back forever */
            playerRigidBody.velocity = Vector2.zero;
        }
    }
Example #3
0
    /**
     * startKnockback(float)
     *
     * Applies damage after getting hit and decides whether to start the knockback
     *  coroutine. If the player is still alive, then start the coroutine
     *
     * @param knockbackTime:  The amount of time that we want the enemy be knocked back for
     */
    public void startKnockback(float knockbackTime, float damage)
    {
        /* take damage from the hit no matter what */
        currHealth.runtimeValue -= damage;

        /* raise the flag to let anything that subscribes to this signal know that
         *  the player got hit. This can later be something like a sound, a screen shake, ect */
        playerHealthSignal.raise();

        /* knockback if the player is still alive */
        if (currHealth.runtimeValue > 0)
        {
            /* run the coroutine for the knockback */
            StartCoroutine(knockbackCoroutine(knockbackTime));
        }
        /* player is dead, HP <= 0 */
        else
        {
            deathHandler();
        }
    }