experiments-monogame/Inky/Inky/DemoControls.cs

48 lines
1.7 KiB
C#

using Microsoft.Xna.Framework.Input;
using Nez;
namespace Inky
{
public class DemoControls : SceneComponent, IUpdatable
{
private VirtualButton _left;
private VirtualButton _right;
private float _eyeDirection = 1;
public DemoControls()
{
_left = new VirtualButton();
_left.Nodes.Add(new VirtualButton.KeyboardKey(Keys.Left));
_right = new VirtualButton();
_right.Nodes.Add(new VirtualButton.KeyboardKey(Keys.Right));
}
public override void Update()
{
var lanky = Scene.Entities.FindEntity("inky").GetComponent<Lanky>();
if (_left.IsDown)
{
lanky.LegAlignment = Alignment.Left;
lanky.ArmAlignment = Alignment.Left;
lanky.HeadShift -= 1f * Time.DeltaTime;
}
else if (_right.IsDown)
{
lanky.LegAlignment = Alignment.Right;
lanky.ArmAlignment = Alignment.Right;
lanky.HeadShift += 1f * Time.DeltaTime;
}
else
{
lanky.EyeShift += _eyeDirection * Time.DeltaTime;
if (lanky.EyeShift < -0.99) _eyeDirection = 1;
else if (lanky.EyeShift > 0.99) _eyeDirection = -1;
lanky.MouthShift += _eyeDirection * Time.DeltaTime;
lanky.LegWobble += _eyeDirection * Time.DeltaTime;
lanky.LegAlignment = Alignment.Center;
lanky.ArmAlignment = Alignment.Center;
}
}
}
}