public ShotAndMovingItemInteraction(World world, Shot shot, MovingItem movingItem) { if (world == null) throw new ArgumentNullException("world"); if (shot == null) throw new ArgumentNullException("shot"); if (movingItem == null) throw new ArgumentNullException("movingItem"); this._world = world; this._shot = shot; this._movingItem = movingItem; }
public ShotAndStaticItemInteraction(World world, Shot shot, StaticItem staticItem) { if (world == null) throw new ArgumentNullException("world"); if (shot == null) throw new ArgumentNullException("shot"); if (staticItem == null) throw new ArgumentNullException("staticItem"); if (staticItem is MovingItem) throw new ArgumentOutOfRangeException("staticItem"); this._world = world; this._shot = shot; this._staticItem = staticItem; }
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; }
/// <summary> /// Place short bang at a shot's position and remove the shot /// </summary> /// <param name="s">An instance of a shot to convert</param> public void ConvertShotToBang(Shot s) { AddBang(s.Position, BangType.Short); s.InstantlyExpire(); }