low pass filter to sounds playing at distance, "armored" limbs, moved playing damagesounds from attack to IDamageable

This commit is contained in:
Regalis
2015-06-01 22:20:17 +03:00
parent 95c0d41023
commit 1f42e4a4db
32 changed files with 331 additions and 175 deletions

View File

@@ -110,7 +110,7 @@ namespace Subsurface.Items.Components
if (contained.body!=null) contained.body.Enabled = false;
RelatedItem ri = containableItems.Find(x => x.MatchesItem(item));
RelatedItem ri = containableItems.Find(x => x.MatchesItem(contained));
if (ri == null) continue;
foreach (StatusEffect effect in ri.statusEffects)

View File

@@ -9,19 +9,20 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking;
using Subsurface.Items.Components;
using System.IO;
namespace Subsurface
{
struct ItemSound
class ItemSound
{
public readonly byte index;
public readonly Sound sound;
public readonly ActionType type;
public readonly float range;
public ItemSound(int index, ActionType type, float range)
public ItemSound(Sound sound, ActionType type, float range)
{
this.index = (byte)index;
this.sound = sound;
this.type = type;
this.range = range;
}
@@ -150,10 +151,12 @@ namespace Subsurface
statusEffects.Add(StatusEffect.Load(subElement));
break;
case "sound":
string filePath = ToolBox.GetAttributeString(subElement, "path", "");
string filePath = ToolBox.GetAttributeString(subElement, "file", "");
if (filePath=="") continue;
if (!filePath.Contains("\\")) filePath = Path.GetDirectoryName(item.Prefab.ConfigFile)+"\\"+filePath;
//int index = item.Prefab.sounds.FindIndex(x => x.FilePath == filePath);
int index = item.Prefab.sounds.FindIndex(x => x.FilePath == filePath);
ActionType type;
@@ -167,34 +170,41 @@ namespace Subsurface
break;
}
Sound sound = Sound.Load(filePath);
float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f);
sounds.Add(new ItemSound(index, type, range));
sounds.Add(new ItemSound(sound, type, range));
break;
}
}
}
private ItemSound loopingSound;
private int loopingSoundIndex;
public void PlaySound(ActionType type, float volume, Vector2 position, bool loop=false)
{
if (loop && Sounds.SoundManager.IsPlaying(loopingSoundIndex)) return;
ItemSound itemSound = null;
if (!loop || !Sounds.SoundManager.IsPlaying(loopingSoundIndex))
{
List<ItemSound> matchingSounds = sounds.FindAll(x => x.type == type);
if (matchingSounds.Count == 0) return;
int index = Game1.localRandom.Next(matchingSounds.Count);
itemSound = sounds[index];
if (loop) loopingSound = itemSound;
}
List<ItemSound> matchingSounds = sounds.FindAll(x => x.type == type);
if (matchingSounds.Count == 0 || item.Prefab.sounds.Count == 0) return;
int index = Game1.localRandom.Next(Math.Min(matchingSounds.Count, item.Prefab.sounds.Count));
Sound sound = item.Prefab.sounds[matchingSounds[index].index];
if (loop)
{
loopingSoundIndex = sound.Loop(loopingSoundIndex, volume, position, matchingSounds[index].range);
loopingSoundIndex = loopingSound.sound.Loop(loopingSoundIndex, volume, position, loopingSound.range);
}
else
{
sound.Play(volume, matchingSounds[index].range, position);
itemSound.sound.Play(volume, itemSound.range, position);
}
}

View File

@@ -91,6 +91,8 @@ namespace Subsurface.Items.Components
public float ExtraCooling { get; set; }
public float AvailableFuel { get; set; }
public Reactor(Item item, XElement element)
: base(item, element)
{
@@ -109,6 +111,8 @@ namespace Subsurface.Items.Components
{
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
fissionRate = Math.Min(fissionRate, AvailableFuel);
float heat = 100 * fissionRate;
float heatDissipation = 50 * coolingRate + ExtraCooling;
@@ -157,6 +161,7 @@ namespace Subsurface.Items.Components
//fission rate can't be lowered below a certain amount if the core is too hot
FissionRate = Math.Max(fissionRate, heat / 200.0f);
//the power generated by the reactor is equal to the temperature
currPowerConsumption = -temperature*powerPerTemp;
@@ -169,6 +174,7 @@ namespace Subsurface.Items.Components
UpdateGraph(deltaTime);
ExtraCooling = 0.0f;
AvailableFuel = 0.0f;
}
public override void UpdateBroken(float deltaTime, Camera cam)

View File

@@ -334,16 +334,8 @@ namespace Subsurface.Items.Components
if (!mouseIn) return;
end = PlayerInput.MousePosition;
}
else if (draggingConnected == null)
{
if (Vector2.Distance(end, PlayerInput.MousePosition)<20.0f)
{
item.IsHighlighted = true;
//start dragging the wire
if (PlayerInput.LeftButtonDown()) draggingConnected = wireItem;
}
}
bool mouseOn = false;
int textX = (int)start.X;
float connLength = 10.0f;
@@ -358,9 +350,12 @@ namespace Subsurface.Items.Components
}
else
{
wireVertical.DrawTiled(spriteBatch,
new Vector2(start.X, end.Y + wireCorner.size.Y) - wireVertical.size / 2,
new Vector2(wireVertical.size.X, (float)Math.Abs((end.Y + wireCorner.size.Y) - start.Y)), Color.White);
Vector2 pos = new Vector2(start.X, end.Y + wireCorner.size.Y) - wireVertical.size / 2;
Vector2 size = new Vector2(wireVertical.size.X, (float)Math.Abs((end.Y + wireCorner.size.Y) - start.Y));
wireVertical.DrawTiled(spriteBatch, pos, size, Color.White);
Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
if (rect.Contains(PlayerInput.MousePosition)) mouseOn = true;
float dir = (end.X > start.X) ? -1.0f : 1.0f;
@@ -371,16 +366,29 @@ namespace Subsurface.Items.Components
float wireStartX = start.X - wireCorner.size.X / 2 * dir;
float wireEndX = end.X + connLength * dir;
wireHorizontal.DrawTiled(spriteBatch, new Vector2(Math.Min(wireStartX,wireEndX), end.Y - wireVertical.size.Y / 2),
new Vector2(Math.Abs(wireStartX - wireEndX), wireHorizontal.size.Y), Color.White);
pos = new Vector2(Math.Min(wireStartX,wireEndX), end.Y - wireVertical.size.Y / 2);
size = new Vector2(Math.Abs(wireStartX - wireEndX), wireHorizontal.size.Y);
wireHorizontal.DrawTiled(spriteBatch, pos, size, Color.White);
rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
if (rect.Contains(PlayerInput.MousePosition)) mouseOn = true;
connector.Draw(spriteBatch, end, -MathHelper.PiOver2*dir);
}
if (draggingConnected == null)
{
if (mouseOn || Vector2.Distance(end, PlayerInput.MousePosition)<20.0f)
{
item.IsHighlighted = true;
//start dragging the wire
if (PlayerInput.LeftButtonDown()) draggingConnected = wireItem;
}
}
spriteBatch.DrawString(GUI.font, item.Name,
new Vector2(textX, start.Y-30),
Color.White,
mouseOn ? Color.Gold : Color.White,
MathHelper.PiOver2,
GUI.font.MeasureString(item.Name)*0.5f,
1.0f, SpriteEffects.None, 0.0f);

View File

@@ -17,8 +17,9 @@ namespace Subsurface.Items.Components
bool throwing;
[HasDefaultValue(1.0f, false)]
private float ThrowForce
public float ThrowForce
{
get { return throwForce; }
set { throwForce = value; }
}