4d225c65f2
- Barotrauma's projects are in the Barotrauma directory - All libraries are in the Libraries directory - MonoGame is now managed by NuGet, rather than referenced from the installed files (TODO: consider using PCL for easier cross-platform development?) - NuGet libraries are not included in the repo, as getting the latest versions automatically should be preferred - Removed Content/effects.mgfx as it didn't seem to be used anywhere - Removed some references to Subsurface directory - Renamed Launcher2 to Launcher
92 lines
2.4 KiB
C#
92 lines
2.4 KiB
C#
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
class MotionSensor : ItemComponent
|
|
{
|
|
private const float UpdateInterval = 0.1f;
|
|
|
|
private string output, falseOutput;
|
|
|
|
private bool motionDetected;
|
|
|
|
private float range;
|
|
|
|
private float updateTimer;
|
|
|
|
[InGameEditable, HasDefaultValue(0.0f, true)]
|
|
public float Range
|
|
{
|
|
get { return range; }
|
|
set
|
|
{
|
|
range = MathHelper.Clamp(value, 0.0f, 500.0f);
|
|
}
|
|
}
|
|
|
|
[InGameEditable, HasDefaultValue("1", true)]
|
|
public string Output
|
|
{
|
|
get { return output; }
|
|
set { output = value; }
|
|
}
|
|
|
|
[InGameEditable, HasDefaultValue("", true)]
|
|
public string FalseOutput
|
|
{
|
|
get { return falseOutput; }
|
|
set { falseOutput = value; }
|
|
}
|
|
|
|
public MotionSensor(Item item, XElement element)
|
|
: base (item, element)
|
|
{
|
|
IsActive = true;
|
|
}
|
|
|
|
public override void Update(float deltaTime, Camera cam)
|
|
{
|
|
if (motionDetected)
|
|
{
|
|
item.SendSignal(1, output, "state_out", null);
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(falseOutput))
|
|
{
|
|
item.SendSignal(1, falseOutput, "state_out", null);
|
|
}
|
|
|
|
updateTimer -= deltaTime;
|
|
if (updateTimer > 0.0f) return;
|
|
|
|
motionDetected = false;
|
|
updateTimer = UpdateInterval;
|
|
|
|
if (item.body != null && item.body.Enabled)
|
|
{
|
|
if (Math.Abs(item.body.LinearVelocity.X) > 0.01f || Math.Abs(item.body.LinearVelocity.Y) > 0.1f)
|
|
{
|
|
motionDetected = true;
|
|
}
|
|
}
|
|
|
|
foreach (Character c in Character.CharacterList)
|
|
{
|
|
if (Math.Abs(c.WorldPosition.X - item.WorldPosition.X) < range &&
|
|
Math.Abs(c.WorldPosition.Y - item.WorldPosition.Y) < range)
|
|
{
|
|
if (!c.AnimController.Limbs.Any(l => l.body.FarseerBody.Awake)) continue;
|
|
|
|
motionDetected = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|