public void Ping() { if (!ping.finished) return; ping = new TempPing(numPings, body.Position, pingDuration, color); ping.finished = false; ping.timer.Start(); if (ping.pings.Count > 0) return; float rotation = 0; for (int i = 0; i < ping.pingCount; i++) { float pingX = (float)Math.Cos(rotation); float pingY = (float)Math.Sin(rotation); Vector2 position = body.Position + new Vector2(pingX, pingY) * ConvertUnits.ToSimUnits(pingDistance); rotation += MathHelper.TwoPi / ping.pingCount; world.RayCast(PingRay, body.Position, position); points = (from p in points orderby Vector2.Distance(p.currentPosition, body.Position) select p).ToList(); if (points.Count > 0) ping.pings.Add(new TempPingInstance(body.Position, points[0].currentPosition, points[0].color, points[0].finalColor)); else ping.pings.Add(new TempPingInstance(body.Position, position, color)); points = new List<TempPingInstance>(); } pinged = true; game.ResourceManager.Sounds["sonar"].Play(); }
public Player(MainGameScreen game, Vector2 position, World world, Color color) { this.game = game; this.world = world; this.color = color; texture = game.ResourceManager.Sprites["Submarine"]; body = ResourceManager.CreateBodyFromTexture(texture, position, world, out origin); sonarPings = new List<TempPingInstance>(); sonarPoints = new List<TempPingInstance>(); points = new List<TempPingInstance>(); horizontalSpeed = 0.002f; verticalSpeed = 0.001f; sonarDistance = 1000f; sonarIterations = 800f; sonarRotation = 0; numPings = 550; pingDuration = 10000f; pingDistance = 3000f; ping = new TempPing(0); pingMines = new List<PingMine>(); }