private static bool ShotHitsShot(World world, StandardShot standardShot1, StandardShot standardShot2) { if (standardShot2.ShotType == standardShot1.ShotType || standardShot2.Direction != standardShot1.Direction.Reversed()) { return false; } int minEnergy = Math.Min(standardShot2.Energy, standardShot1.Energy); world.Game.SoundPlayer.Play(GameSound.StaticObjectShotAndInjured); standardShot2.ReduceEnergy(minEnergy); if (!standardShot2.IsExtant) world.ConvertShotToBang(standardShot2); standardShot1.ReduceEnergy(minEnergy); if (!standardShot1.IsExtant) world.ConvertShotToBang(standardShot1); return true; }
private static bool InteractionInvolvingShot(World world, Shot shot, MovingItem movingItem) { if (movingItem is Player) { movingItem.ReduceEnergy(shot.Energy); if (movingItem.IsAlive()) world.Game.SoundPlayer.Play(GameSound.PlayerInjured); world.ConvertShotToBang(shot); return true; } var monster = movingItem as Monster.Monster; if (monster != null) { var result = ShotHitsMonster(world, shot, monster); return result; } var items = new[] { shot, movingItem }; var explosion = items.OfType<Explosion>().FirstOrDefault(); if (explosion != null) { var otherItem = items.Single(item => item != explosion); if (otherItem is Shot) { shot.ReduceEnergy(explosion.Energy); return true; } } var standardShot1 = shot as StandardShot; var standardShot2 = movingItem as StandardShot; if (standardShot1 != null && standardShot2 != null) { var result = ShotHitsShot(world, standardShot1, standardShot2); return result; } return false; }
private static bool ShotHitsMonster(World world, Shot shot, Monster.Monster monster) { if (!monster.IsActive) monster.IsActive = true; if (monster.Mobility == MonsterMobility.Patrolling) monster.Mobility = MonsterMobility.Placid; var standardShot = shot as StandardShot; if (standardShot != null && monster.ShotsBounceOff) { if (!standardShot.HasRebounded) standardShot.Reverse(); return false; } var score = ((Math.Min(shot.Energy, monster.Energy) >> 1) + 1)*10; world.IncreaseScore(score); monster.ReduceEnergy(shot.Energy); if (monster.IsAlive()) { var sound = monster.IsEgg ? GameSound.PlayerShootsAndInjuresEgg : GameSound.PlayerShootsAndInjuresMonster; world.Game.SoundPlayer.Play(sound); } world.ConvertShotToBang(shot); return true; }