public override void ResolveCollision(BoomerangCollisionResponse other) { Sound.PlaySound(Sound.SoundEffects.Enemy_Hit, entity, !Sound.SOUND_LOOPS); if (other.owner == Scene.Find("link")) { entity.AddComponent(new EnemyFreeze()); } }
public override void ResolveCollision(BoomerangCollisionResponse other) { LinkBehavior linkBehavior = entity.GetComponent <LinkBehavior>(); if (other.owner != entity) { // Take Damage entity.GetComponent <LinkHealthManagement>().DeductHealth(other.damage); // decrease xp entity.GetComponent <LinkXPManager>().LinkDamaged_XPDecrease(); // Change to Hurt Sprite (enables and disables immunity inside) if (!entity.GetComponent <LinkHealthManagement>().immune) { linkBehavior.damaged = true; entity.GetComponent <LinkHealthManagement>().immune = true; // 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!"); } } } }