public static int SpawnWave(this GameScene scene, WaveType type, Rectangle zone) { int numberOfPlayers = scene.Game.CurrentGameMode.PlayerInfos.Count; int numberOfBoars; int numberOfChicken; switch (type) { case WaveType.Fighting: if (RandomExt.GetRandomFloat(0, 1) >= 0.5f) { numberOfBoars = numberOfPlayers - 1; numberOfChicken = 0; } else { numberOfBoars = 0; numberOfChicken = RandomExt.GetRandomInt(5 + numberOfPlayers, 12 + numberOfPlayers); } break; default: case WaveType.Collecting: numberOfBoars = RandomExt.GetRandomInt(numberOfPlayers, numberOfPlayers * 2); numberOfChicken = RandomExt.GetRandomInt(numberOfPlayers * 3, numberOfPlayers * 5); break; } scene.SpawnCattleInZone(zone, numberOfBoars, numberOfChicken); return(numberOfBoars + numberOfChicken); }
private void FleeingTrigger(BoarState currentState, Entity entity, float elapsedSeconds, float totalElapsedSeconds) { // Only allow fleeing if the animal is not in following mode but when it is, only has a distance of smaller than 1 meters if (hearingSensor.SensedEntities.Any() && (aiComponent.CurrentState != BoarState.Following || (followingBehaviour.EntityToFollow.Body.Position - Body.Position).Length() > 1f)) { fleeingBehaviour.FleeingPoint = hearingSensor.SensedEntities.Average(e => e.Body.Position); if (currentState != BoarState.Fleeing) { var randI = RandomExt.GetRandomInt(1, 5); var delay = RandomExt.GetRandomFloat(0, 0.25f); this.Scene.Dispatcher.Delay(delay, () => GetComponent <AudioSourceComponent>().PlaySound($"Audio/PigScared{randI}")); } aiComponent.ChangeState(BoarState.Fleeing); } }
// this is just a wrapper around playerEntity.SwitchToState(..), but it prevents switching away from dizzy private void SwitchState(PlayerState newState) { // don't allow switching while dizzy if (playerEntity.State == PlayerState.Dizzy) { return; } if (newState == PlayerState.Luring) { playerEntity.GetComponent <AudioSourceComponent>().PlaySoundIfNotAlreadyPlaying("Audio/Lure"); } else if (newState == PlayerState.Shouting) { var randI = RandomExt.GetRandomInt(1, 5); Entity.GetComponent <AudioSourceComponent>().PlaySound($"Audio/Shout{randI}"); } playerEntity.SwitchToState(newState); }
private bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { var other = (Entity)fixtureB.Body.UserData; if (playerEntity.State == PlayerState.Dashing) { var velocity = Entity.Body.LinearVelocity; if (velocity.LengthSquared() < 0.01f) { velocity = VectorExtensions.AngleToUnitVector(Entity.Body.Rotation); } Vector2 worldNormal; FixedArray2 <Vector2> worldPoints; contact.CalculateContactPoints(out worldNormal, out worldPoints); Vector2 collisionPoint = worldPoints[0]; var dirToOther = collisionPoint - Entity.Body.Position; dashCollisionPoint = collisionPoint; // if one of our vectors somehow got 0, cancel, as otherwise NaNs can crash farseer if (dirToOther.LengthSquared() < 0.01f) { return(true); } var dirToOtherNorm = dirToOther.Normalized(); dashCollisionDirection = dirToOther; var velocityNorm = velocity.Normalized(); // if the other is not in the direction of the dash, cancel if (velocityNorm.AngleBetween(dirToOtherNorm) > MathHelper.PiOver2 - 0.09f) { return(true); } (other as BoarEntity)?.Hit(Entity); (other as ChickenEntity)?.Hit(Entity); other.Body.ApplyLinearImpulse(dirToOtherNorm * 10.0f, other.Body.Position); if ((other as ChickenEntity) != null) { return(true); } var reflectedDir = Vector2.Reflect(Entity.Body.LinearVelocity, contact.Manifold.LocalNormal); if (reflectedDir.LengthSquared() > 0.1f) { Entity.Body.ApplyLinearImpulse((-reflectedDir).Normalized() * 10.0f, Entity.Body.Position); } // SHAKE THAT SCREEN!!! Entity.Game.Camera.Shake(TimeSpan.FromSeconds(0.5f), 20f); var randI = RandomExt.GetRandomInt(1, 4); Entity.GetComponent <AudioSourceComponent>().PlaySound($"Audio/Hit{randI}"); var otherPlayer = other as PlayerEntity; if (otherPlayer != null) { otherPlayer.GetComponent <AudioSourceComponent>().PlaySound("Audio/Dizzy"); otherPlayer.SwitchToState(PlayerState.Dizzy); // since the other player becomes dizzy, it should vibrate stronger Entity.Game.InputManager.SetRumble(otherPlayer.PlayerInfo, 1.0f, 0.7f, 0.6f); } if (other.Body.IsStatic) { ResetDash(); playerEntity.GetComponent <AudioSourceComponent>().PlaySound("Audio/Dizzy"); playerEntity.SwitchToState(PlayerState.Dizzy); Entity.Game.InputManager.SetRumble(playerEntity.PlayerInfo, 1.0f, 0.7f, 0.6f); } else { Entity.Game.InputManager.SetRumble(playerEntity.PlayerInfo, 0.75f, 0.25f, 0.3f); } } return(true); }
private void SetRandomName(JoinState joinState) { SetName(joinState, RandomExt.GetRandomInt(0, availablePlayerNames.Length, players.Select(p => p.NameIndex).ToArray())); }