Unstable 1.1.14.0
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Barotrauma.Lights;
|
||||
using Barotrauma.Particles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -28,36 +30,60 @@ namespace Barotrauma
|
||||
underwaterExplosion.StartDelay = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Attack.Range * 0.1f; i++)
|
||||
if (!underwater && (flames || smoke))
|
||||
{
|
||||
if (!underwater)
|
||||
for (int i = 0; i < Attack.Range * 0.025f; i++)
|
||||
{
|
||||
float particleSpeed = Rand.Range(0.0f, 1.0f);
|
||||
particleSpeed = particleSpeed * particleSpeed * Attack.Range;
|
||||
float distFactor = 0.0f;
|
||||
|
||||
if (i > 0 && Attack.Range > 100.0f)
|
||||
{
|
||||
distFactor = Rand.Range(0.0f, 1.0f);
|
||||
//sqrt to make larger values more common (= more particles spawn further away from the origin)
|
||||
distFactor = MathF.Sqrt(distFactor);
|
||||
}
|
||||
float sizeFactor = MathHelper.Clamp(Attack.Range / 1000.0f, 0.0f, 1.0f);
|
||||
float minScale = MathHelper.Lerp(0.2f, 1.0f, sizeFactor);
|
||||
float maxScale = MathUtils.InverseLerp(2.0f, 3.0f, sizeFactor);
|
||||
//larger particles closer to the origin
|
||||
float particleScale = MathHelper.Clamp(1.0f - distFactor, minScale, maxScale);
|
||||
|
||||
var particlePrefab = ParticleManager.FindPrefab("explosionfire");
|
||||
Vector2 pos = worldPosition;
|
||||
if (i > 0)
|
||||
{
|
||||
pos = ClampParticlePos(worldPosition + Rand.Vector(Attack.Range * distFactor * 0.3f), hull, particlePrefab);
|
||||
}
|
||||
|
||||
if (flames)
|
||||
{
|
||||
float particleScale = MathHelper.Clamp(Attack.Range * 0.0025f, 0.5f, 2.0f);
|
||||
var flameParticle = GameMain.ParticleManager.CreateParticle("explosionfire",
|
||||
ClampParticlePos(worldPosition + Rand.Vector((float)System.Math.Sqrt(Rand.Range(0.0f, Attack.Range))), hull),
|
||||
Rand.Vector(Rand.Range(0.0f, particleSpeed)), 0.0f, hull);
|
||||
if (flameParticle != null) flameParticle.Size *= particleScale;
|
||||
var flameParticle = GameMain.ParticleManager.CreateParticle(particlePrefab,
|
||||
pos,
|
||||
velocity: Vector2.Zero, hullGuess: hull);
|
||||
if (flameParticle != null)
|
||||
{
|
||||
//brief delay to particles futher from origin
|
||||
flameParticle.StartDelay = distFactor * sizeFactor;
|
||||
flameParticle.Size *= particleScale;
|
||||
}
|
||||
}
|
||||
if (smoke)
|
||||
{
|
||||
GameMain.ParticleManager.CreateParticle(Rand.Range(0.0f, 1.0f) < 0.5f ? "explosionsmoke" : "smoke",
|
||||
ClampParticlePos(worldPosition + Rand.Vector((float)System.Math.Sqrt(Rand.Range(0.0f, Attack.Range))), hull),
|
||||
Rand.Vector(Rand.Range(0.0f, particleSpeed)), 0.0f, hull);
|
||||
GameMain.ParticleManager.CreateParticle(
|
||||
ParticleManager.FindPrefab(Rand.Range(0.0f, 1.0f) < 0.5f ? "explosionsmoke" : "smoke"),
|
||||
pos, velocity: Vector2.Zero, hullGuess: hull);
|
||||
}
|
||||
}
|
||||
else if (underwaterBubble)
|
||||
}
|
||||
|
||||
for (int i = 0; i < Attack.Range * 0.1f; i++)
|
||||
{
|
||||
if (underwater && underwaterBubble)
|
||||
{
|
||||
Vector2 bubblePos = Rand.Vector(Rand.Range(0.0f, Attack.Range * 0.5f));
|
||||
|
||||
GameMain.ParticleManager.CreateParticle("risingbubbles", worldPosition + bubblePos,
|
||||
Vector2.Zero, 0.0f, hull);
|
||||
|
||||
velocity: Vector2.Zero, hullGuess: hull);
|
||||
if (i < Attack.Range * 0.02f)
|
||||
{
|
||||
var underwaterExplosion = GameMain.ParticleManager.CreateParticle("underwaterexplosion", worldPosition + bubblePos,
|
||||
@@ -66,33 +92,46 @@ namespace Barotrauma
|
||||
{
|
||||
underwaterExplosion.Size *= MathHelper.Clamp(Attack.Range / 300.0f, 0.5f, 2.0f) * Rand.Range(0.8f, 1.2f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (sparks)
|
||||
{
|
||||
GameMain.ParticleManager.CreateParticle("spark", worldPosition,
|
||||
Rand.Vector(Rand.Range(1200.0f, 2400.0f)), 0.0f, hull);
|
||||
Rand.Vector(Rand.Range(800.0f, 1500.0f)), 0.0f, hull);
|
||||
}
|
||||
if (debris)
|
||||
{
|
||||
GameMain.ParticleManager.CreateParticle("explosiondebris", worldPosition,
|
||||
Rand.Vector(Rand.Range(800.0f, 2000.0f)), 0.0f, hull);
|
||||
}
|
||||
}
|
||||
|
||||
if (flash)
|
||||
{
|
||||
float displayRange = flashRange ?? Attack.Range;
|
||||
float displayRange = flashRange ?? (Attack.Range * 2);
|
||||
if (displayRange < 0.1f) { return; }
|
||||
var light = new LightSource(worldPosition, displayRange, flashColor, null);
|
||||
CoroutineManager.StartCoroutine(DimLight(light));
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 ClampParticlePos(Vector2 particlePos, Hull hull)
|
||||
private static Vector2 ClampParticlePos(Vector2 particlePos, Hull hull, ParticlePrefab particlePrefab)
|
||||
{
|
||||
if (hull == null) return particlePos;
|
||||
float minX = hull.WorldRect.X;
|
||||
float maxX = hull.WorldRect.Right;
|
||||
float minY = hull.WorldRect.Y - hull.WorldRect.Height;
|
||||
float maxY = hull.WorldRect.Y;
|
||||
if (particlePrefab != null)
|
||||
{
|
||||
minX = Math.Min(minX + particlePrefab.CollisionRadius, hull.WorldRect.Center.X);
|
||||
maxX = Math.Max(maxX - particlePrefab.CollisionRadius, hull.WorldRect.Center.X);
|
||||
minY = Math.Min(minY + particlePrefab.CollisionRadius, hull.WorldRect.Y - hull.WorldRect.Height / 2);
|
||||
maxY = Math.Max(maxY - particlePrefab.CollisionRadius, hull.WorldRect.Y - hull.WorldRect.Height / 2);
|
||||
}
|
||||
|
||||
return new Vector2(
|
||||
MathHelper.Clamp(particlePos.X, hull.WorldRect.X, hull.WorldRect.Right),
|
||||
MathHelper.Clamp(particlePos.Y, hull.WorldRect.Y - hull.WorldRect.Height, hull.WorldRect.Y));
|
||||
MathHelper.Clamp(particlePos.X, minX, maxX),
|
||||
MathHelper.Clamp(particlePos.Y, minY, maxY));
|
||||
}
|
||||
|
||||
private IEnumerable<CoroutineStatus> DimLight(LightSource light)
|
||||
@@ -100,9 +139,11 @@ namespace Barotrauma
|
||||
float currBrightness = 1.0f;
|
||||
while (light.Color.A > 0.0f && flashDuration > 0.0f && currBrightness > 0.0f)
|
||||
{
|
||||
light.Color = new Color(light.Color.R, light.Color.G, light.Color.B, (byte)(currBrightness * 255));
|
||||
currBrightness -= 1.0f / flashDuration * CoroutineManager.DeltaTime;
|
||||
|
||||
if (!CoroutineManager.Paused)
|
||||
{
|
||||
light.Color = new Color(light.Color.R, light.Color.G, light.Color.B, (byte)(currBrightness * 255));
|
||||
currBrightness -= 1.0f / flashDuration * CoroutineManager.DeltaTime;
|
||||
}
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user