public Vector2 GetOffset(ref float offsetState, Vector2 randomOffsetMultiplier, float rotation = 0.0f) { Vector2 offset = Offset; if (OffsetAnimSpeed > 0.0f) { switch (OffsetAnim) { case AnimationType.Sine: offsetState %= (MathHelper.TwoPi / OffsetAnimSpeed); offset *= (float)Math.Sin(offsetState * OffsetAnimSpeed); break; case AnimationType.Noise: offsetState %= 1.0f / (OffsetAnimSpeed * 0.1f); float t = offsetState * 0.1f * OffsetAnimSpeed; offset = new Vector2( offset.X * (PerlinNoise.GetPerlin(t, t) - 0.5f), offset.Y * (PerlinNoise.GetPerlin(t + 0.5f, t + 0.5f) - 0.5f)); break; } } offset += new Vector2( RandomOffset.X * randomOffsetMultiplier.X, RandomOffset.Y * randomOffsetMultiplier.Y); if (Math.Abs(rotation) > 0.01f) { Matrix transform = Matrix.CreateRotationZ(rotation); offset = Vector2.Transform(offset, transform); } return(offset); }
public float GetSpawnProbability(LevelObjectPrefab prefab) { if (prefab.ClusteringAmount <= 0.0f) { return(Length); } float noise = (noiseVal + PerlinNoise.GetPerlin(prefab.ClusteringGroup, prefab.ClusteringGroup * 0.3f)) % 1.0f; return(Length * (float)Math.Pow(noise, prefab.ClusteringAmount)); }
public float GetRotation(ref float rotationState) { RotationSpeed = -Math.Abs(RotationSpeed); switch (RotationAnim) { case AnimationType.Sine: rotationState %= MathHelper.TwoPi / absRotationSpeedRadians; return(rotationRadians * (float)Math.Sin(rotationState * rotationSpeedRadians)); case AnimationType.Noise: rotationState %= 1.0f / absRotationSpeedRadians; return(rotationRadians * (PerlinNoise.GetPerlin(rotationState * absRotationSpeedRadians, rotationState * absRotationSpeedRadians) - 0.5f)); default: return(rotationState * rotationSpeedRadians); } }
public float GetRotation(ref float rotationState) { if (rotationSpeedRadians <= 0.0f) { return(Rotation); } switch (OffsetAnim) { case AnimationType.Sine: rotationState = rotationState % (MathHelper.TwoPi / rotationSpeedRadians); return(Rotation * (float)Math.Sin(rotationState * rotationSpeedRadians)); case AnimationType.Noise: rotationState = rotationState % (1.0f / rotationSpeedRadians); return(Rotation * PerlinNoise.GetPerlin(rotationState * rotationSpeedRadians, rotationState * rotationSpeedRadians)); default: return(rotationState * rotationSpeedRadians); } }
public Vector2 GetOffset(ref float offsetState) { if (OffsetAnimSpeed <= 0.0f) { return(Offset); } switch (OffsetAnim) { case AnimationType.Sine: offsetState = offsetState % (MathHelper.TwoPi / OffsetAnimSpeed); return(Offset * (float)Math.Sin(offsetState * OffsetAnimSpeed)); case AnimationType.Noise: offsetState = offsetState % (1.0f / (OffsetAnimSpeed * 0.1f)); float t = offsetState * 0.1f * OffsetAnimSpeed; return(new Vector2( Offset.X * (PerlinNoise.GetPerlin(t, t) - 0.5f), Offset.Y * (PerlinNoise.GetPerlin(t + 0.5f, t + 0.5f) - 0.5f))); default: return(Offset); } }
void UpdateDying(float deltaTime) { if (deathAnimDuration <= 0.0f) { return; } float noise = (PerlinNoise.GetPerlin(WalkPos * 0.002f, WalkPos * 0.003f) - 0.5f) * 5.0f; float animStrength = (1.0f - deathAnimTimer / deathAnimDuration); Limb head = GetLimb(LimbType.Head); if (head != null && head.IsSevered) { return; } Limb tail = GetLimb(LimbType.Tail); if (head != null && !head.IsSevered) { head.body.ApplyTorque((float)(Math.Sqrt(head.Mass) * Dir * (Math.Sin(WalkPos) + noise)) * 30.0f * animStrength); } if (tail != null && !tail.IsSevered) { tail.body.ApplyTorque((float)(Math.Sqrt(tail.Mass) * -Dir * (Math.Sin(WalkPos) + noise)) * 30.0f * animStrength); } WalkPos += deltaTime * 10.0f * animStrength; Vector2 centerOfMass = GetCenterOfMass(); foreach (Limb limb in Limbs) { if (limb.IsSevered) { continue; } #if CLIENT if (limb.LightSource != null) { limb.LightSource.Color = Color.Lerp(limb.InitialLightSourceColor, Color.TransparentBlack, deathAnimTimer / deathAnimDuration); if (limb.InitialLightSpriteAlpha.HasValue) { limb.LightSource.OverrideLightSpriteAlpha = MathHelper.Lerp(limb.InitialLightSpriteAlpha.Value, 0.0f, deathAnimTimer / deathAnimDuration); } } #endif if (limb.type == LimbType.Head || limb.type == LimbType.Tail || limb.IsSevered || !limb.body.Enabled) { continue; } if (limb.Mass <= 0.0f) { string errorMsg = "Creature death animation error: invalid limb mass on character \"" + character.SpeciesName + "\" (type: " + limb.type + ", mass: " + limb.Mass + ")"; DebugConsole.ThrowError(errorMsg); GameAnalyticsManager.AddErrorEventOnce("FishAnimController.UpdateDying:InvalidMass" + character.ID, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); deathAnimTimer = deathAnimDuration; return; } Vector2 diff = (centerOfMass - limb.SimPosition); if (!MathUtils.IsValid(diff)) { string errorMsg = "Creature death animation error: invalid diff (center of mass: " + centerOfMass + ", limb position: " + limb.SimPosition + ")"; DebugConsole.ThrowError(errorMsg); GameAnalyticsManager.AddErrorEventOnce("FishAnimController.UpdateDying:InvalidDiff" + character.ID, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); deathAnimTimer = deathAnimDuration; return; } limb.body.ApplyForce(diff * (float)(Math.Sin(WalkPos) * Math.Sqrt(limb.Mass)) * 30.0f * animStrength, maxVelocity: 10.0f); } }
public void Draw(SpriteBatch spriteBatch, GUICustomComponent mapContainer) { Rectangle rect = mapContainer.Rect; Vector2 viewSize = new Vector2(rect.Width / zoom, rect.Height / zoom); Vector2 edgeBuffer = rect.Size.ToVector2() / 2; DrawOffset.X = MathHelper.Clamp(DrawOffset.X, -Width - edgeBuffer.X + viewSize.X / 2.0f, edgeBuffer.X - viewSize.X / 2.0f); DrawOffset.Y = MathHelper.Clamp(DrawOffset.Y, -Height - edgeBuffer.Y + viewSize.Y / 2.0f, edgeBuffer.Y - viewSize.Y / 2.0f); drawOffsetNoise = new Vector2( (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.1f % 255, Timing.TotalTime * 0.1f % 255, 0) - 0.5f, (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.2f % 255, Timing.TotalTime * 0.2f % 255, 0.5f) - 0.5f) * 10.0f; Vector2 viewOffset = DrawOffset + drawOffsetNoise; Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y); Rectangle prevScissorRect = GameMain.Instance.GraphicsDevice.ScissorRectangle; spriteBatch.End(); spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, rect); spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable); Vector2 topLeft = rectCenter + viewOffset; Vector2 bottomRight = rectCenter + (viewOffset + new Vector2(Width, Height)); Vector2 mapTileSize = mapTiles[0, 0].size * generationParams.MapTileScale; int startX = (int)Math.Floor(-topLeft.X / mapTileSize.X) - 1; int startY = (int)Math.Floor(-topLeft.Y / mapTileSize.Y) - 1; int endX = (int)Math.Ceiling((-topLeft.X + rect.Width) / mapTileSize.X); int endY = (int)Math.Ceiling((-topLeft.Y + rect.Height) / mapTileSize.Y); float noiseT = (float)(Timing.TotalTime * 0.01f); cameraNoiseStrength = (float)PerlinNoise.CalculatePerlin(noiseT, noiseT * 0.5f, noiseT * 0.2f); float noiseScale = (float)PerlinNoise.CalculatePerlin(noiseT * 5.0f, noiseT * 2.0f, 0) * 5.0f; for (int x = startX; x <= endX; x++) { for (int y = startY; y <= endY; y++) { int tileX = Math.Abs(x) % mapTiles.GetLength(0); int tileY = Math.Abs(y) % mapTiles.GetLength(1); Vector2 tilePos = rectCenter + (viewOffset + new Vector2(x, y) * mapTileSize) * zoom; mapTiles[tileX, tileY].Draw(spriteBatch, tilePos, Color.White, origin: Vector2.Zero, scale: generationParams.MapTileScale * zoom); if (GameMain.DebugDraw) { continue; } if (!tileDiscovered[tileX, tileY] || x < 0 || y < 0 || x >= tileDiscovered.GetLength(0) || y >= tileDiscovered.GetLength(1)) { generationParams.FogOfWarSprite?.Draw(spriteBatch, tilePos, Color.White * cameraNoiseStrength, origin: Vector2.Zero, scale: generationParams.MapTileScale * zoom); noiseOverlay.DrawTiled(spriteBatch, tilePos, mapTileSize * zoom, startOffset: new Vector2(Rand.Range(0.0f, noiseOverlay.SourceRect.Width), Rand.Range(0.0f, noiseOverlay.SourceRect.Height)), color: Color.White * cameraNoiseStrength * 0.2f, textureScale: Vector2.One * noiseScale); } } } if (GameMain.DebugDraw) { if (topLeft.X > rect.X) { GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, (int)(topLeft.X - rect.X), rect.Height), Color.Black * 0.5f, true); } if (topLeft.Y > rect.Y) { GUI.DrawRectangle(spriteBatch, new Rectangle((int)topLeft.X, rect.Y, (int)(bottomRight.X - topLeft.X), (int)(topLeft.Y - rect.Y)), Color.Black * 0.5f, true); } if (bottomRight.X < rect.Right) { GUI.DrawRectangle(spriteBatch, new Rectangle((int)bottomRight.X, rect.Y, (int)(rect.Right - bottomRight.X), rect.Height), Color.Black * 0.5f, true); } if (bottomRight.Y < rect.Bottom) { GUI.DrawRectangle(spriteBatch, new Rectangle((int)topLeft.X, (int)bottomRight.Y, (int)(bottomRight.X - topLeft.X), (int)(rect.Bottom - bottomRight.Y)), Color.Black * 0.5f, true); } } float rawNoiseScale = 1.0f + PerlinNoise.GetPerlin((int)(Timing.TotalTime * 1 - 1), (int)(Timing.TotalTime * 1 - 1)); cameraNoiseStrength = PerlinNoise.GetPerlin((int)(Timing.TotalTime * 1 - 1), (int)(Timing.TotalTime * 1 - 1)); noiseOverlay.DrawTiled(spriteBatch, rect.Location.ToVector2(), rect.Size.ToVector2(), startOffset: new Vector2(Rand.Range(0.0f, noiseOverlay.SourceRect.Width), Rand.Range(0.0f, noiseOverlay.SourceRect.Height)), color: Color.White * cameraNoiseStrength * 0.1f, textureScale: Vector2.One * rawNoiseScale); noiseOverlay.DrawTiled(spriteBatch, rect.Location.ToVector2(), rect.Size.ToVector2(), startOffset: new Vector2(Rand.Range(0.0f, noiseOverlay.SourceRect.Width), Rand.Range(0.0f, noiseOverlay.SourceRect.Height)), color: new Color(20, 20, 20, 50), textureScale: Vector2.One * rawNoiseScale * 2); noiseOverlay.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight), startOffset: new Vector2(Rand.Range(0.0f, noiseOverlay.SourceRect.Width), Rand.Range(0.0f, noiseOverlay.SourceRect.Height)), color: Color.White * cameraNoiseStrength * 0.1f, textureScale: Vector2.One * noiseScale); Pair <Rectangle, string> tooltip = null; if (generationParams.ShowLocations) { foreach (LocationConnection connection in Connections) { if (IsInFogOfWar(connection.Locations[0]) && IsInFogOfWar(connection.Locations[1])) { continue; } DrawConnection(spriteBatch, connection, rect, viewOffset); } for (int i = 0; i < Locations.Count; i++) { Location location = Locations[i]; if (IsInFogOfWar(location)) { continue; } Vector2 pos = rectCenter + (location.MapPosition + viewOffset) * zoom; Rectangle drawRect = location.Type.Sprite.SourceRect; drawRect.X = (int)pos.X - drawRect.Width / 2; drawRect.Y = (int)pos.Y - drawRect.Width / 2; if (!rect.Intersects(drawRect)) { continue; } if (location == CurrentDisplayLocation) { generationParams.CurrentLocationIndicator.Draw(spriteBatch, rectCenter + (currLocationIndicatorPos + viewOffset) * zoom, generationParams.IndicatorColor, generationParams.CurrentLocationIndicator.Origin, 0, Vector2.One * (generationParams.LocationIconSize / generationParams.CurrentLocationIndicator.size.X) * 1.7f * zoom); } if (location == SelectedLocation) { generationParams.SelectedLocationIndicator.Draw(spriteBatch, rectCenter + (location.MapPosition + viewOffset) * zoom, generationParams.IndicatorColor, generationParams.SelectedLocationIndicator.Origin, 0, Vector2.One * (generationParams.LocationIconSize / generationParams.SelectedLocationIndicator.size.X) * 1.7f * zoom); } Color color = location.Type.SpriteColor; if (!location.Discovered) { color = Color.White; } if (location.Connections.Find(c => c.Locations.Contains(CurrentDisplayLocation)) == null) { color *= 0.5f; } float iconScale = location == CurrentDisplayLocation ? 1.2f : 1.0f; if (location == HighlightedLocation) { iconScale *= 1.2f; } location.Type.Sprite.Draw(spriteBatch, pos, color, scale: generationParams.LocationIconSize / location.Type.Sprite.size.X * iconScale * zoom); if (location.TypeChangeTimer <= 0 && !string.IsNullOrEmpty(location.LastTypeChangeMessage) && generationParams.TypeChangeIcon != null) { Vector2 typeChangeIconPos = pos + new Vector2(1.35f, -0.35f) * generationParams.LocationIconSize * 0.5f * zoom; float typeChangeIconScale = 18.0f / generationParams.TypeChangeIcon.SourceRect.Width; generationParams.TypeChangeIcon.Draw(spriteBatch, typeChangeIconPos, GUI.Style.Red, scale: typeChangeIconScale * zoom); if (Vector2.Distance(PlayerInput.MousePosition, typeChangeIconPos) < generationParams.TypeChangeIcon.SourceRect.Width * zoom) { tooltip = new Pair <Rectangle, string>( new Rectangle(typeChangeIconPos.ToPoint(), new Point(30)), location.LastTypeChangeMessage); } } if (location != CurrentLocation && CurrentLocation.AvailableMissions.Any(m => m.Locations.Contains(location)) && generationParams.MissionIcon != null) { Vector2 missionIconPos = pos + new Vector2(1.35f, 0.35f) * generationParams.LocationIconSize * 0.5f * zoom; float missionIconScale = 18.0f / generationParams.MissionIcon.SourceRect.Width; generationParams.MissionIcon.Draw(spriteBatch, missionIconPos, generationParams.IndicatorColor, scale: missionIconScale * zoom); if (Vector2.Distance(PlayerInput.MousePosition, missionIconPos) < generationParams.MissionIcon.SourceRect.Width * zoom) { var availableMissions = CurrentLocation.AvailableMissions.Where(m => m.Locations.Contains(location)); tooltip = new Pair <Rectangle, string>( new Rectangle(missionIconPos.ToPoint(), new Point(30)), TextManager.Get("mission") + '\n' + string.Join('\n', availableMissions.Select(m => "- " + m.Name))); } } if (GameMain.DebugDraw && location == HighlightedLocation && (!location.Discovered || !location.Type.HasOutpost)) { if (location.Reputation != null) { Vector2 dPos = pos; dPos.Y += 48; string name = $"Reputation: {location.Name}"; Vector2 nameSize = GUI.SmallFont.MeasureString(name); GUI.DrawString(spriteBatch, dPos, name, Color.White, Color.Black * 0.8f, 4, font: GUI.SmallFont); dPos.Y += nameSize.Y + 16; Rectangle bgRect = new Rectangle((int)dPos.X, (int)dPos.Y, 256, 32); bgRect.Inflate(8, 8); Color barColor = ToolBox.GradientLerp(location.Reputation.NormalizedValue, Color.Red, Color.Yellow, Color.LightGreen); GUI.DrawRectangle(spriteBatch, bgRect, Color.Black * 0.8f, isFilled: true); GUI.DrawRectangle(spriteBatch, new Rectangle((int)dPos.X, (int)dPos.Y, (int)(location.Reputation.NormalizedValue * 255), 32), barColor, isFilled: true); string reputationValue = ((int)location.Reputation.Value).ToString(); Vector2 repValueSize = GUI.SubHeadingFont.MeasureString(reputationValue); GUI.DrawString(spriteBatch, dPos + (new Vector2(256, 32) / 2) - (repValueSize / 2), reputationValue, Color.White, Color.Black, font: GUI.SubHeadingFont); GUI.DrawRectangle(spriteBatch, new Rectangle((int)dPos.X, (int)dPos.Y, 256, 32), Color.White); } } } } DrawDecorativeHUD(spriteBatch, rect); if (HighlightedLocation != null) { Vector2 pos = rectCenter + (HighlightedLocation.MapPosition + viewOffset) * zoom; pos.X += 50 * zoom; Vector2 nameSize = GUI.LargeFont.MeasureString(HighlightedLocation.Name); Vector2 typeSize = GUI.Font.MeasureString(HighlightedLocation.Type.Name); Vector2 size = new Vector2(Math.Max(nameSize.X, typeSize.X), nameSize.Y + typeSize.Y); bool showReputation = HighlightedLocation.Discovered && HighlightedLocation.Type.HasOutpost && HighlightedLocation.Reputation != null; string repLabelText = null, repValueText = null; Vector2 repLabelSize = Vector2.Zero, repBarSize = Vector2.Zero; if (showReputation) { repLabelText = TextManager.Get("reputation"); repLabelSize = GUI.Font.MeasureString(repLabelText); size.X = Math.Max(size.X, repLabelSize.X); repBarSize = new Vector2(Math.Max(0.75f * size.X, 100), repLabelSize.Y); size.X = Math.Max(size.X, (4.0f / 3.0f) * repBarSize.X); size.Y += 2 * repLabelSize.Y + 4 + repBarSize.Y; repValueText = ((int)HighlightedLocation.Reputation.Value).ToString(); } GUI.Style.GetComponentStyle("OuterGlow").Sprites[GUIComponent.ComponentState.None][0].Draw( spriteBatch, new Rectangle((int)(pos.X - 60 * GUI.Scale), (int)(pos.Y - size.Y), (int)(size.X + 120 * GUI.Scale), (int)(size.Y * 2.2f)), Color.Black * hudVisibility); var topLeftPos = pos - new Vector2(0.0f, size.Y / 2); GUI.DrawString(spriteBatch, topLeftPos, HighlightedLocation.Name, GUI.Style.TextColor * hudVisibility * 1.5f, font: GUI.LargeFont); topLeftPos += new Vector2(0.0f, nameSize.Y); GUI.DrawString(spriteBatch, topLeftPos, HighlightedLocation.Type.Name, GUI.Style.TextColor * hudVisibility * 1.5f); if (showReputation) { topLeftPos += new Vector2(0.0f, typeSize.Y + repLabelSize.Y); GUI.DrawString(spriteBatch, topLeftPos, repLabelText, GUI.Style.TextColor * hudVisibility * 1.5f); topLeftPos += new Vector2(0.0f, repLabelSize.Y + 4); Rectangle repBarRect = new Rectangle(new Point((int)topLeftPos.X, (int)topLeftPos.Y), new Point((int)repBarSize.X, (int)repBarSize.Y)); RoundSummary.DrawReputationBar(spriteBatch, repBarRect, HighlightedLocation.Reputation.NormalizedValue); GUI.DrawString(spriteBatch, new Vector2(repBarRect.Right + 4, repBarRect.Top), repValueText, GUI.Style.TextColor); } } if (tooltip != null) { GUIComponent.DrawToolTip(spriteBatch, tooltip.Second, tooltip.First); } spriteBatch.End(); GameMain.Instance.GraphicsDevice.ScissorRectangle = prevScissorRect; spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable); }
void UpdateDying(float deltaTime) { if (deathAnimDuration <= 0.0f) { return; } float noise = (PerlinNoise.GetPerlin(WalkPos * 0.002f, WalkPos * 0.003f) - 0.5f) * 5.0f; float animStrength = (1.0f - deathAnimTimer / deathAnimDuration); Limb baseLimb = GetLimb(LimbType.Head); //if head is the main limb, it technically can't be severed - the rest of the limbs are considered severed if the head gets cut off if (baseLimb == MainLimb) { int connectedToHeadCount = GetConnectedLimbs(baseLimb).Count; //if there's nothing connected to the head, don't make it wiggle by itself if (connectedToHeadCount == 1) { baseLimb = null; } Limb torso = GetLimb(LimbType.Torso, excludeSevered: false); if (torso != null) { //if there are more limbs connected to the torso than to the head, make the torso wiggle instead int connectedToTorsoCount = GetConnectedLimbs(torso).Count; if (connectedToTorsoCount > connectedToHeadCount) { baseLimb = torso; } } } else if (baseLimb == null) { baseLimb = GetLimb(LimbType.Torso, excludeSevered: true); if (baseLimb == null) { return; } } var connectedToBaseLimb = GetConnectedLimbs(baseLimb); Limb tail = GetLimb(LimbType.Tail); if (baseLimb != null) { baseLimb.body.ApplyTorque((float)(Math.Sqrt(baseLimb.Mass) * Dir * (Math.Sin(WalkPos) + noise)) * 30.0f * animStrength); } if (tail != null && connectedToBaseLimb.Contains(tail)) { tail.body.ApplyTorque((float)(Math.Sqrt(tail.Mass) * -Dir * (Math.Sin(WalkPos) + noise)) * 30.0f * animStrength); } WalkPos += deltaTime * 10.0f * animStrength; Vector2 centerOfMass = GetCenterOfMass(); foreach (Limb limb in Limbs) { if (!connectedToBaseLimb.Contains(limb)) { continue; } #if CLIENT if (limb.LightSource != null) { limb.LightSource.Color = Color.Lerp(limb.InitialLightSourceColor, Color.TransparentBlack, deathAnimTimer / deathAnimDuration); if (limb.InitialLightSpriteAlpha.HasValue) { limb.LightSource.OverrideLightSpriteAlpha = MathHelper.Lerp(limb.InitialLightSpriteAlpha.Value, 0.0f, deathAnimTimer / deathAnimDuration); } } #endif if (limb.type == LimbType.Head || limb.type == LimbType.Tail || limb.IsSevered || !limb.body.Enabled) { continue; } if (limb.Mass <= 0.0f) { string errorMsg = "Creature death animation error: invalid limb mass on character \"" + character.SpeciesName + "\" (type: " + limb.type + ", mass: " + limb.Mass + ")"; DebugConsole.ThrowError(errorMsg); GameAnalyticsManager.AddErrorEventOnce("FishAnimController.UpdateDying:InvalidMass" + character.ID, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); deathAnimTimer = deathAnimDuration; return; } Vector2 diff = (centerOfMass - limb.SimPosition); if (!MathUtils.IsValid(diff)) { string errorMsg = "Creature death animation error: invalid diff (center of mass: " + centerOfMass + ", limb position: " + limb.SimPosition + ")"; DebugConsole.ThrowError(errorMsg); GameAnalyticsManager.AddErrorEventOnce("FishAnimController.UpdateDying:InvalidDiff" + character.ID, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); deathAnimTimer = deathAnimDuration; return; } limb.body.ApplyForce(diff * (float)(Math.Sin(WalkPos) * Math.Sqrt(limb.Mass)) * 30.0f * animStrength, maxVelocity: 10.0f); } }
public void Update(float deltaTime) { position += new Vector2(velocity.X, velocity.Y) * deltaTime; depth = MathHelper.Clamp(depth + velocity.Z * deltaTime, Prefab.MinDepth, Prefab.MaxDepth * 10); if (Prefab.FlashInterval > 0.0f) { flashTimer -= deltaTime; if (flashTimer > 0.0f) { alpha = 0.0f; } else { //value goes from 0 to 1 and back to 0 during the flash alpha = (float)Math.Sin(-flashTimer / Prefab.FlashDuration * MathHelper.Pi) * PerlinNoise.GetPerlin((float)Timing.TotalTime * 0.1f, (float)Timing.TotalTime * 0.2f); if (flashTimer < -Prefab.FlashDuration) { flashTimer = Prefab.FlashInterval; } } } checkWallsTimer -= deltaTime; if (checkWallsTimer <= 0.0f && Level.Loaded != null) { checkWallsTimer = CheckWallsInterval; obstacleDiff = Vector2.Zero; if (position.Y > Level.Loaded.Size.Y) { obstacleDiff = Vector2.UnitY; } else if (position.Y < 0.0f) { obstacleDiff = -Vector2.UnitY; } else if (position.X < 0.0f) { obstacleDiff = Vector2.UnitX; } else if (position.X > Level.Loaded.Size.X) { obstacleDiff = -Vector2.UnitX; } else { var cells = Level.Loaded.GetCells(position, 1); if (cells.Count > 0) { int cellCount = 0; foreach (Voronoi2.VoronoiCell cell in cells) { Vector2 diff = cell.Center - position; if (diff.LengthSquared() > 5000.0f * 5000.0f) { continue; } obstacleDiff += diff; cellCount++; } if (cellCount > 0) { obstacleDiff /= cellCount; obstacleDist = obstacleDiff.Length(); obstacleDiff = Vector2.Normalize(obstacleDiff); } } } } if (Swarm != null) { Vector2 midPoint = Swarm.MidPoint(); float midPointDist = Vector2.Distance(SimPosition, midPoint) * 100.0f; if (midPointDist > Swarm.MaxDistance) { steeringManager.SteeringSeek(midPoint, ((midPointDist / Swarm.MaxDistance) - 1.0f) * Prefab.Speed); } steeringManager.SteeringManual(deltaTime, Swarm.AvgVelocity() * Swarm.Cohesion); } if (Prefab.WanderAmount > 0.0f) { steeringManager.SteeringWander(Prefab.Speed); } if (obstacleDiff != Vector2.Zero) { steeringManager.SteeringManual(deltaTime, -obstacleDiff * (1.0f - obstacleDist / 5000.0f) * Prefab.Speed); } steeringManager.Update(Prefab.Speed); if (Prefab.WanderZAmount > 0.0f) { wanderZPhase += Rand.Range(-Prefab.WanderZAmount, Prefab.WanderZAmount); velocity.Z = (float)Math.Sin(wanderZPhase) * Prefab.Speed; } velocity = Vector3.Lerp(velocity, new Vector3(Steering.X, Steering.Y, velocity.Z), deltaTime); UpdateDeformations(deltaTime); }