private void CheckCollisionWithHeroProjectile() { foreach (var h in heroes) { IReadOnlyList <(Entity Collider1, Entity Collider2)> collisions = CollisionCheck.GetCollisions(enemies, h.Projectiles); foreach ((var Collider1, var Collider2) in collisions) { var enemy = Collider1 as Enemy; var projectile = Collider2 as Projectile; enemy.DecreaseHealthPoints(projectile.Damage); // Removing projectile and enemy (if it's dead) if (enemy.Hp <= 0) { enemies.TryRemove(enemy); //h.Points += (int)Math.Ceiling(enemy.Damage); h.Points += enemy.KillReward; } h.TryRemoveProjectile(projectile); } } }
private void CheckCollisionWithEnemyProjectile() { IReadOnlyList <(Entity Collider1, Entity Collider2)> collisions = CollisionCheck.GetCollisions(heroes, enemyProjectiles); foreach ((var Collider1, var Collider2) in collisions) { var hero = Collider1 as Hero; var projectile = Collider2 as Projectile; hero.DecreaseHealthPoints(projectile.Damage); enemyProjectiles.TryRemove(projectile); } }
private void CheckCollisionEnemyHero() { foreach (var h in heroes) { var heroList = new List <Entity> { h }; var collisionsWithHero = CollisionCheck.GetCollisions(heroList, enemies); foreach ((var Collider1, var Collider2) in collisionsWithHero) { var hero = Collider1 as Hero; var enemy = Collider2 as Enemy; enemy.DecreaseHealthPoints(hero.Damage); // Remove kamikaze from the game enemies.TryRemove(enemy); h.DecreaseHealthPoints(enemy.Damage); } } }