public void FireIfYouLike(StaticItem source, World world) { Direction firingDirection = DetermineFiringDirection(source.TilePosition, world.Player.TilePosition); if (firingDirection == Direction.None) return; if (!DoesMonsterHaveClearShotAtPlayer(world, source.TilePosition, firingDirection)) return; var startPos = source.TilePosition.ToPosition() + firingDirection.ToVector() * new Vector2(Tile.Width, Tile.Height) / 2; var shot = new StandardShot(world, startPos, firingDirection, source.Energy >> 2, ShotType.Monster); world.AddShot(shot); world.Game.SoundPlayer.Play(GameSound.MonsterShoots); }
public void Fire(StaticItem source, World world, FiringState firingState, Direction direction) { if (direction == Direction.None) throw new ArgumentOutOfRangeException("direction"); if (firingState != FiringState.Pulse || source.Energy < 4) return; var startPos = source.TilePosition.ToPosition(); var shot = new StandardShot(world, startPos, direction, source.Energy >> 2, ShotType.Player); if (!shot.CanMoveInDirection(direction)) return; startPos += direction.ToVector() * Tile.Size / 2; shot.SetPosition(startPos); world.AddShot(shot); world.Game.SoundPlayer.Play(GameSound.PlayerShoots); _countOfShotsBeforeCostingEnergy--; if (_countOfShotsBeforeCostingEnergy < 0) { _countOfShotsBeforeCostingEnergy = 3; source.ReduceEnergy(1); } }
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; }
public void AddShot(StandardShot s) { this.GameObjects.Add(s); }