Esempio n. 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Nonharmful"))
        {
            // Debug.Log("Point or dialog");
            return;
        }
        col_sound.Play();
        Creature enemy = collision.gameObject.GetComponent <Creature>(); // Templatize with enemy when class is made

        if (enemy != null)                                               // we have found an enemy in our collision look up damage
        {
            currPlayerHealth -= enemy.damagePenalty;
            enemy.Collided(collision); // ESCAPE!!!
            Debug.Log("Ouch avoid that next time!");
        }
        else // we ran into a wall damage based on speed
        {
            Vector2 collision_velocity = collision.relativeVelocity;
            if (collision_velocity.magnitude < .75f)
            {
                currPlayerHealth -= 1;
            }
            else if (collision_velocity.magnitude < 1.25f && collision_velocity.magnitude >= .75f)
            {
                currPlayerHealth -= 2;
            }
            else
            {
                currPlayerHealth -= 3;
            }
            // Debug.Log("WallCollision");
        }

        HealthLost?.Invoke(currPlayerHealth);

        if (currPlayerHealth <= 0)
        {
            Die();
        }
        // add invuln frames health damage or free phasing movement?
    }
Esempio n. 2
0
 public void HealthLostAction()
 {
     HealthLost?.Invoke();
 }