private bool isNearAnotherPlayer(Penguin a) { Vector2 aPos = a.Position; float minDist = 5000.0f; float currDist = 0.0f; foreach (Penguin p in players) { if (p == a) continue; currDist = Vector2.Distance(p.Position, aPos); if (currDist < minDist) minDist = currDist; } if (minDist <= SHARK_SPAWN_CLOSENESS_THRESHOLD) return true; return false; }
public void setSpawnParameters(Size s, int id, Penguin p, float rotation) { this.owner = p; this.CurrentSize = s; this.id = id; acceleration = Vector2.Normalize(Physics.AngleToVector(rotation)) * 50000F; velocity.X = p.Velocity.X; velocity.Y = p.Velocity.Y; }
private void TryToAddPlayers() { for (int i = 0; i < MAX_NUM_PLAYERS; ++i) { if (!isPlayerConnected[i]) { if (GamePad.GetState((PlayerIndex)i).IsConnected) { Penguin newPlayer = new Penguin((PlayerIndex)i, playerStartPositions[i], colorCodes[i]); newPlayer.loadContent(); newPlayer.respawn(); newPlayer.pauseAnimation(); players.Add(newPlayer); playerReadyTextPositions[i] = players[i].Position; playerReadyTextPositions[i].Y += players[i].getBufferedRectangleBounds(0).Height / 2.0f; playerReadyTextPositions[i].X -= players[i].getBufferedRectangleBounds(0).Width / 2.0f; isPlayerConnected[i] = true; } } } }
/// <summary> /// Sets the nearest threatening actors for this fish /// among the provided actors. /// </summary> public void SetNearestThreats(List<Penguin> players, List<Shark> sharks) { // dead finish don't need threats if (CurrState == state.Dying || !this.IsAlive) return; float distBetween = 0.0f; float distToNearestP = 5000.0f; float distToNearestS = 5000.0f; Penguin nearestP = null; Shark nearestS = null; foreach (Penguin p in players) { if (!p.IsAlive || p.CurrState == state.Dying) continue; distBetween = Actor.DistanceBetween(this, p); if (distBetween < distToNearestP) { distToNearestP = distBetween; nearestP = p; } } foreach (Shark s in sharks) { if (!s.IsAlive || s.CurrState == state.Dying) continue; distBetween = Actor.DistanceBetween(this, s); if (distBetween < distToNearestS) { distToNearestS = distBetween; nearestS = s; } } if (nearestP != null) this.nearestPlayer = nearestP; if (nearestS != null) this.nearestShark = nearestS; }