public void Equip(Item itemToEquip)
    {
        if (itemToEquip.itemType == Item.ItemType.JUNK)
        {
            print("You can't equip junk!");
            return;
        }

        if (itemToEquip.itemType == Item.ItemType.WEAPON)
        {
            if (currentWeapon != null)
            {
                AddItem(currentWeapon);
            }
            currentWeapon = itemToEquip;

            // SFX
            SoundEffectsSystem.PlaySFX("sword_equip");
        }
        else
        {
            if (currentArmor != null)
            {
                AddItem(currentArmor);
            }
            currentArmor = itemToEquip;

            // SFX
            SoundEffectsSystem.PlaySFX("armor_equip");
        }
    }
    public void GetAttacked(Vector2 position, int howMuch)
    {
        if (playerMove.isInvincible)
        {
            return;
        }

        // Can escape bool
        StopCoroutine("CanEscapeCoroutine");
        StartCoroutine("CanEscapeCoroutine");

        // Spawn blooderino
        FindObjectOfType <GameMaster>().SpawnSlashBlood(transform.position);

        // Other effects
        cam.LightShake();
        SoundEffectsSystem.PlaySFX("player_damaged");

        int damage = ConvertToPlayerDamage(howMuch);

        HP -= damage;
        if (HP <= 0)
        {
            FindObjectOfType <GameMaster>().GameOver();
        }

        StartCoroutine(AttackedCoroutine(position));
    }
    private IEnumerator ShootAtPlayer()
    {
        while (true)
        {
            yield return(new WaitForSeconds(fireRateInSeconds));

            if (HP > 0)
            {
                // SFX
                SoundEffectsSystem.PlaySFX("goblin_attack");

                // Shoot projectile!
                GameObject projectile = Instantiate(projectilePrefab, transform.position, Quaternion.identity) as GameObject;

                // Shoot the projectile towards the player
                Vector2 dir = playerTransform.position - transform.position;
                dir.Normalize();
                projectile.GetComponent <Rigidbody2D>().velocity = dir * projectileSpeed;

                // Make sure the projectile deals the correct amount of damage!
                projectile.GetComponent <Projectile>().damage = attack;

                // Make sure the projectile is destroyed after some amount of time!
                Destroy(projectile, 6);
            }
        }
    }
Example #4
0
 public void GameOver()
 {
     // Disable everything neccesary, fade out, load title screen scene
     // SFX
     audio_source.Stop();
     SoundEffectsSystem.PlaySFX("game_over");
     StartCoroutine("GameOverCoroutine");
 }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.GetComponent <Item>() != null)
        {
            AddItem(other.GetComponent <Item>());

            SoundEffectsSystem.PlaySFX("pickup_item");
        }
    }
Example #6
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.GetComponent <PlayerMove>() != null)
     {
         other.gameObject.GetComponent <PlayerCombat>().GetAttacked(this);
         animator.SetTrigger("attack_trigger");
         // SFX
         SoundEffectsSystem.PlaySFX("spider_attack");
     }
 }
Example #7
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        // @ Knockback factor is based on what???
        if (other.GetComponent <EnemyBase>() != null && !other.isTrigger)
        {
            other.GetComponent <EnemyBase>().TakeDamage(playerCombat.GetPlayerAttack(), 400f);
        }
        if (other.tag == "LootCrate")
        {
            other.GetComponent <LootCrate>().GetDestroyed();
            cam.LightShake();

            // SFX
            SoundEffectsSystem.PlaySFX("box_break");
        }
    }
    public override void TakeDamage(int howMuch, float knockBack)
    {
        HP -= howMuch;

        // Spawn blooderino
        FindObjectOfType <GameMaster>().SpawnSlashBlood(transform.position);

        StopCoroutine("GetKnockedBack");
        StartCoroutine(GetKnockedBack(knockBack));

        if (HP <= 0)
        {
            SoundEffectsSystem.PlaySFX("goblin_death");
            StopCoroutine("ShootAtPlayer");
            Die();
        }
    }
Example #9
0
    public override void TakeDamage(int howMuch, float knockBack)
    {
        HP -= howMuch;

        // Spawn blooderino
        FindObjectOfType <GameMaster>().SpawnSlashBlood(transform.position);

        // Knockback away from the player
        StopCoroutine("GetKnockedBack");
        StartCoroutine(GetKnockedBack(knockBack));

        // Did we die?
        if (HP <= 0)
        {
            SoundEffectsSystem.PlaySFX("spider_death");
            Die();
        }
    }
Example #10
0
    protected IEnumerator GetKnockedBack(float knockBack)
    {
        // Enemy damaged SFX
        SoundEffectsSystem.PlaySFX("enemy_damaged");

        knockedBack    = true;
        rBody.velocity = Vector2.zero;

        Vector2 dir = playerTransform.position - transform.position;

        dir.Normalize();
        dir *= -1;
        rBody.AddForce(dir * knockBack);

        yield return(new WaitForSeconds(knockStunTime));

        knockedBack = false;
    }
    private void Attack()
    {
        // If we're already attacking, STOP and return
        if (isAttacking || playerMove.isDodging || attackInvincibility)
        {
            return;
        }

        animController.SetTrigger("attack_trigger");

        // Can escape bool
        StopCoroutine("CanEscapeCoroutine");
        StartCoroutine("CanEscapeCoroutine");

        // SFX
        SoundEffectsSystem.PlaySFX("player_attack");

        StopCoroutine("AttackCoroutine");
        StartCoroutine("AttackCoroutine");
    }
Example #12
0
    private IEnumerator AttackCoroutine()
    {
        isAttacking = true;

        // SFX
        SoundEffectsSystem.PlaySFX("ogre_attack");

        // Check which direction we want to attack
        int bestIndex = 0;

        for (int i = 1; i < 4; i++)
        {
            float newDistance  = Vector2.Distance((Vector2)transform.position + ogreAttackPositions[i], playerTransform.position);
            float bestDistance = Vector2.Distance((Vector2)transform.position + ogreAttackPositions[bestIndex], playerTransform.position);
            if (newDistance < bestDistance)
            {
                bestIndex = i;
            }
        }

        animator.SetTrigger("attack_trigger");
        animator.SetFloat("attack_x", ogreAttackPositions[bestIndex].normalized.x);
        animator.SetFloat("attack_y", ogreAttackPositions[bestIndex].normalized.y);

        // Animaton wait time before actual attack
        // Attacking "wind-up" time
        yield return(new WaitForSeconds(0.9f));

        // Perform attack!
        attackCollider.transform.localPosition = ogreAttackPositions[bestIndex];
        attackCollider.enabled = true;

        yield return(new WaitForSeconds(0.4f));

        attackCollider.enabled = false;

        isAttacking = false;
    }
Example #13
0
    public void SellCurrentItem()
    {
        if (desiredIndex == -1)
        {
            return;
        }

        Item itemToSell = playerInventory.itemList[desiredIndex];

        // Transfer currency to the player
        if (currentBuyer.IsHappyWithItem(itemToSell.itemName))
        {
            int extraPay = (int)((itemToSell.value * Buyer.payFactor) - itemToSell.value);
            playerCombat.HP += itemToSell.value + extraPay;

            //SFX
            SoundEffectsSystem.PlaySFX("sold_expensive_item");
        }
        else
        {
            playerCombat.HP += itemToSell.value;

            // SFX
            SoundEffectsSystem.PlaySFX("sold_item");
        }

        // Remove the item!
        playerInventory.itemList.Remove(itemToSell);
        Destroy(itemToSell.gameObject);

        desiredIndex = 0;

        // New buyer
        SelectRandomBuyer();

        // Update UI
        UpdateCurrentItem();
    }
Example #14
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.I))
        {
            if (!inventoryGameObject.activeInHierarchy)
            {
                OpenInventory();
            }
            else
            {
                CloseInventory();
            }
        }

        if (inventoryGameObject.activeInHierarchy)
        {
            // Freeze time!
            Time.timeScale = 0.0f;
        }

        if (inventoryGameObject.activeInHierarchy && playerInventory.itemList.Count > 0)
        {
            // Navigating the inventory
            if (Input.GetKeyDown(KeyCode.D))
            {
                if (desiredIndex < playerInventory.itemList.Count - 1)
                {
                    desiredIndex++;
                }
                else
                {
                    desiredIndex = 0;
                }

                SelectInventory(desiredIndex);

                // SFX
                SoundEffectsSystem.PlaySFX("ui_scroll_up");
            }
            else if (Input.GetKeyDown(KeyCode.A))
            {
                if (desiredIndex != 0)
                {
                    desiredIndex--;
                }
                else
                {
                    desiredIndex = playerInventory.itemList.Count - 1;
                }

                SelectInventory(desiredIndex);

                // SFX
                SoundEffectsSystem.PlaySFX("ui_scroll_up");
            }
            else if (Input.GetKeyDown(KeyCode.W))
            {
                int newIndex = desiredIndex - 4;
                if (newIndex >= 0)
                {
                    desiredIndex = newIndex;
                }
                SelectInventory(desiredIndex);

                // SFX
                SoundEffectsSystem.PlaySFX("ui_scroll_down");
            }
            else if (Input.GetKeyDown(KeyCode.S))
            {
                int newIndex = desiredIndex + 4;
                if (newIndex < playerInventory.itemList.Count)
                {
                    desiredIndex = newIndex;
                }
                SelectInventory(desiredIndex);

                // SFX
                SoundEffectsSystem.PlaySFX("ui_scroll_down");
            }

            if (Input.GetKeyDown(InputKeys.INTERACT))
            {
                ClickedEquip();
            }
        }
    }
Example #15
0
    private void Update()
    {
        if (shopHolderObject.activeInHierarchy && playerInventory.itemList.Count != 0)
        {
            // Navigating the inventory
            if (Input.GetKeyDown(KeyCode.W))
            {
                if (desiredIndex == 0)
                {
                    desiredIndex = playerInventory.itemList.Count - 1;
                }
                else
                {
                    desiredIndex--;
                }

                // SFX
                SoundEffectsSystem.PlaySFX("ui_scroll_up");

                UpdateCurrentItem();
            }
            if (Input.GetKeyDown(KeyCode.S))
            {
                if (desiredIndex < playerInventory.itemList.Count - 1)
                {
                    desiredIndex++;
                }
                else
                {
                    desiredIndex = 0;
                }

                // SFX
                SoundEffectsSystem.PlaySFX("ui_scroll_down");

                UpdateCurrentItem();
            }
            if (Input.GetKeyDown(InputKeys.INTERACT))
            {
                SellCurrentItem();
            }
        }
        playerValueText.text = playerCombat.HP.ToString();

        if (Input.GetKeyDown(InputKeys.ESCAPE_KEY) && shopHolderObject.activeInHierarchy)
        {
            FindObjectOfType <GameMaster>().GotoDungeon();
        }

        for (int i = 0; i < allPossibleBuyers.Length; i++)
        {
            Color c = allPossibleBuyers[i].GetComponent <SpriteRenderer>().color;

            if (currentBuyer == allPossibleBuyers[i])
            {
                currentBuyer.GetComponent <SpriteRenderer>().color = Color.white;
            }
            else
            {
                allPossibleBuyers[i].GetComponent <SpriteRenderer>().color = Color.clear;
            }
        }
    }