Fire improvements

This commit is contained in:
Regalis
2015-11-11 07:33:17 +02:00
parent 4d949e3be1
commit 9c2aec4c8e
18 changed files with 145 additions and 21 deletions

View File

@@ -79,6 +79,18 @@ namespace Barotrauma
if (force == 0.0f && attack.Stun == 0.0f && attack.GetDamage(1.0f) == 0.0f) return;
Hull hull = Hull.FindHull(displayPosition);
foreach (Item item in Item.ItemList)
{
if (item.body == null || item.CurrentHull != hull) continue;
Vector2 dir = (item.SimPosition == simPosition) ? Rand.Vector(1.0f) : Vector2.Normalize(item.SimPosition - simPosition);
float distFactor = 1.0f - Vector2.Distance(item.SimPosition, simPosition) / attack.Range;
item.body.ApplyLinearImpulse(dir * distFactor * force);
}
foreach (Character c in Character.CharacterList)
{
float dist = Vector2.Distance(c.SimPosition, simPosition);
@@ -89,6 +101,7 @@ namespace Barotrauma
foreach (Limb limb in c.AnimController.Limbs)
{
if (limb.SimPosition == simPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range;
c.AddDamage(limb.SimPosition, DamageType.None,

View File

@@ -9,9 +9,13 @@ namespace Barotrauma
{
class FireSource
{
const float OxygenConsumption = 10.0f;
static Sound fireSoundBasic, fireSoundLarge;
const float OxygenConsumption = 50.0f;
const float GrowSpeed = 5.0f;
private int basicSoundIndex, largeSoundIndex;
Hull hull;
LightSource lightSource;
@@ -29,13 +33,19 @@ namespace Barotrauma
hull = Hull.FindHull(position);
if (hull == null) return;
if (fireSoundBasic==null)
{
fireSoundBasic = Sound.Load("Content/Sounds/fire.ogg");
fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg");
}
lightSource = new LightSource(position, 50.0f, new Color(1.0f, 0.9f, 0.6f));
hull.AddFireSource(this);
this.position = position - new Vector2(-5.0f, 5.0f);
this.position.Y = hull.Rect.Y - hull.Rect.Height;
//this.position.Y = hull.Rect.Y - hull.Rect.Height;
size = new Vector2(10.0f, 10.0f);
}
@@ -61,12 +71,15 @@ namespace Barotrauma
{
for (int j = i-1; j>=0 ; j--)
{
i = Math.Min(i, fireSources.Count - 1);
j = Math.Min(j, i - 1);
if (!fireSources[i].CheckOverLap(fireSources[j])) continue;
fireSources[j].position.X = Math.Min(fireSources[i].position.X, fireSources[j].position.X);
fireSources[j].size.X =
Math.Max(fireSources[i].position.X + fireSources[i].size.X, fireSources[j].position.X + fireSources[j].size.X)
fireSources[j].size.X =
Math.Max(fireSources[i].position.X + fireSources[i].size.X, fireSources[j].position.X + fireSources[j].size.X)
- fireSources[j].position.X;
fireSources[i].Remove();
@@ -85,7 +98,15 @@ namespace Barotrauma
public void Update(float deltaTime)
{
float count = Rand.Range(0.0f, (float)Math.Sqrt(size.X)/2.0f);
basicSoundIndex = fireSoundBasic.Loop(basicSoundIndex, Math.Min(size.X/100.0f,1.0f), position+size/2.0f, 2000.0f);
largeSoundIndex = fireSoundLarge.Loop(largeSoundIndex, MathHelper.Clamp((size.X-200.0f) / 100.0f, 0.0f, 1.0f), position + size / 2.0f, 2000.0f);
if (size.X>50.0f)
{
this.position.Y = MathHelper.Lerp(this.position.Y, hull.Rect.Y - hull.Rect.Height, deltaTime);
}
for (int i = 0; i < count; i++ )
{
float normalizedPos = 0.5f-(i / count);
@@ -106,6 +127,7 @@ namespace Barotrauma
}
DamageCharacters(deltaTime);
DamageItems(deltaTime);
if (hull.Volume > 0.0f) Extinquish(deltaTime);
@@ -114,7 +136,7 @@ namespace Barotrauma
hull.Oxygen -= size.X*deltaTime*OxygenConsumption;
float growModifier = hull.OxygenPercentage < 20.0f ? hull.OxygenPercentage/20.0f : 1.0f;
float growModifier = hull.OxygenPercentage < 20.0f ? (hull.OxygenPercentage/10.0f)-1.0f : 1.0f;
position.X -= GrowSpeed * growModifier * 0.5f * deltaTime;
//position.Y += GrowSpeed*0.5f * deltaTime;
@@ -136,6 +158,8 @@ namespace Barotrauma
private void DamageCharacters(float deltaTime)
{
if (size.X <= 0.0f) return;
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.CurrentHull == null) continue;
@@ -143,11 +167,29 @@ namespace Barotrauma
float range = (float)Math.Sqrt(size.X) * 10.0f;
if (c.Position.X < position.X - range || c.Position.X > position.X + size.X + range) continue;
if (c.Position.Y < position.Y - size.Y || c.Position.Y > hull.Rect.Y) continue;
c.Health -= (float)Math.Sqrt(size.X) * deltaTime;
}
}
private void DamageItems(float deltaTime)
{
if (size.X <= 0.0f) return;
foreach (Item item in Item.ItemList)
{
if (item.CurrentHull != hull || item.FireProof || item.Condition <= 0.0f) continue;
float range = (float)Math.Sqrt(size.X) * 10.0f;
if (item.Position.X < position.X - range || item.Position.X > position.X + size.X + range) continue;
if (item.Position.Y < position.Y - size.Y || item.Position.Y > hull.Rect.Y) continue;
item.Condition -= (float)Math.Sqrt(size.X) * deltaTime;
item.ApplyStatusEffects(ActionType.OnFire, deltaTime);
}
}
private void Extinquish(float deltaTime)
{
float extinquishAmount = Math.Min(hull.Volume / 100.0f, size.X);
@@ -180,6 +222,9 @@ namespace Barotrauma
{
lightSource.Remove();
if (basicSoundIndex > -1) Sounds.SoundManager.Stop(basicSoundIndex);
if (largeSoundIndex > -1) Sounds.SoundManager.Stop(largeSoundIndex);
hull.RemoveFire(this);
}
}

View File

@@ -201,6 +201,12 @@ namespace Barotrauma
Item.UpdateHulls();
Gap.UpdateHulls();
List<FireSource> fireSourcesToRemove = new List<FireSource>(fireSources);
foreach (FireSource fireSource in fireSourcesToRemove)
{
fireSource.Remove();
}
//renderer.Dispose();
hullList.Remove(this);

View File

@@ -20,6 +20,11 @@ namespace Barotrauma
private Texture2D waterTexture;
public Texture2D WaterTexture
{
get { return waterTexture; }
}
public WaterRenderer(GraphicsDevice graphicsDevice)
{
#if WINDOWS