public override void ResolveCollision(KeeseCollisionResponse other)
        {
            Entity enemy = other.entity;

            // sound effect
            Sound.PlaySound(Sound.SoundEffects.Enemy_Hit, enemy, !Sound.SOUND_LOOPS);

            // take damage
            if (enemy.GetType().Equals(typeof(Stalfo)))
            {
                enemy.GetComponent <StalfoHealthManagement>().Damage(Constants.LINK_SWORD_DAMAGE);
            }
            else if (enemy.GetType().Equals(typeof(Aquamentus)))
            {
                enemy.GetComponent <AquamentusHealthManagement>().Damage(Constants.LINK_SWORD_DAMAGE);
            }
            else
            {
                enemy.GetComponent <EnemyHealthManagement>().Damage(Constants.LINK_SWORD_DAMAGE);
            }

            // Push back
            enemy.AddComponent(new EnemyKnockback(((SwordProjectile)entity).direction, Constants.ENEMY_KNOCKBACK_DISTANCE, Constants.ENEMY_KNOCKBACK_FRAMES));

            Entity.Destroy(entity);
        }
Esempio n. 2
0
        public override void ResolveCollision(KeeseCollisionResponse other)
        {
            LinkBehavior linkBehavior = entity.GetComponent <LinkBehavior>();

            if (!linkBehavior.attacking)
            {
                // Change to Hurt Sprite (enables and disables immunity inside)
                if (!entity.GetComponent <LinkHealthManagement>().immune)
                {
                    // Take Damage
                    entity.GetComponent <LinkHealthManagement>().Damage(other.damage);

                    // decrease xp
                    entity.GetComponent <LinkXPManager>().LinkDamaged_XPDecrease();

                    // Push back
                    Vector2 linkPos  = entity.GetComponent <Transform>().position;
                    Vector2 enemyPos = other.entity.GetComponent <Transform>().position;
                    Vector2 diff     = linkPos - enemyPos;
                    int     distance = Constants.ENEMY_KNOCKBACK_DISTANCE;
                    int     frames   = Constants.ENEMY_KNOCKBACK_FRAMES;

                    // Enemy is Up from Link
                    // UPWARD && MORE VERTICAL THAN HORIZONTAL
                    if (enemyPos.Y <= linkPos.Y && Math.Abs(diff.Y) >= Math.Abs(diff.X))
                    {
                        entity.AddComponent(new LinkKnockback(Constants.Direction.DOWN, distance, frames));
                        // Console.WriteLine("Enemy is up from link!");
                    }

                    // Enemy is Right from Link
                    // RIGHTWARD && MORE HORIZONTAL THAN VERTICAL
                    else if (enemyPos.X >= linkPos.X && Math.Abs(diff.X) >= Math.Abs(diff.Y))
                    {
                        entity.AddComponent(new LinkKnockback(Constants.Direction.LEFT, distance, frames));
                        // Console.WriteLine("Enemy is right from link!");
                    }

                    // Enemy is Down from Link
                    // DOWNWARD && MORE VERTICAL THAN HORIZONTAL
                    else if (enemyPos.Y >= linkPos.Y && Math.Abs(diff.Y) >= Math.Abs(diff.X))
                    {
                        entity.AddComponent(new LinkKnockback(Constants.Direction.UP, distance, frames));
                        // Console.WriteLine("Enemy is down from link!");
                    }

                    // Enemy is Left from Link
                    // LEFTWARD && MORE HORIZONTAL THAN VERTICAL
                    else if (enemyPos.X <= linkPos.X && Math.Abs(diff.X) >= Math.Abs(diff.Y))
                    {
                        entity.AddComponent(new LinkKnockback(Constants.Direction.RIGHT, distance, frames));
                        // Console.WriteLine("Enemy is left from link!");
                    }

                    // Debug; If this ever gets output, something is wrong.
                    else
                    {
                        Console.WriteLine("Enemy was unrecognized direction!");
                    }
                }
            }
        }