public override void Loop(MovingObject pShip) { InputStates.Clear(); if ((TargetShip.Position - pShip.Position).Length > 16) // chase the player ship if it gets too far { Targets.Clear(); Targets.Add(TargetShip.Position); } else if (Targets.Count == 0) // face the same way as the player ship once you reach it { InputStates.Left = Methods.AngleDifference(pShip.Angle, TargetShip.Angle) < -15; InputStates.Right = Methods.AngleDifference(pShip.Angle, TargetShip.Angle) > 15; } InputStates.Add(MoveToNextTarget(pShip)); InputStates.DetectPresses(); }
/// <summary> /// Initialize this module. /// </summary> public override void Initialize() { base.Initialize(); HardwareInput = Host.Platform.GetInput(Host.Window); HardwareInput.Initialize(); HardwareInput.JoypadConnection += (obj, e) => { if (!InputStates.ContainsKey(e.Joypad)) { InputStates.Add(e.Joypad, new InputState()); } if (e.Connected) { Joypads.Add(new VirtualJoypad(InputStates?[e.Joypad], e.Joypad.Index, e.Joypad.Name)); } else { Joypads.RemoveAt(Joypads.FindIndex(x => x.Index == e.Joypad.Index)); } JoypadConnection?.Invoke(obj, e); }; InputStates.Add(HardwareKeyboard, new InputState()); InputStates.Add(HardwareMouse, new InputState()); HardwareKeyboard.OnTypeWithMods += HardwareKeyboard_OnTypeWithMods; HardwareKeyboard.OnKeyEvent += HardwareKeyboard_OnKeyEvent; HardwareKeyboard.OnType += HardwareKeyboard_OnType; HardwareMouse.OnButtonEvent += HardwareMouse_OnButtonEvent; HardwareMouse.OnScroll += HardwareMouse_OnScroll; HardwareMouse.OnMove += HardwareMouse_OnMove; foreach (var j in HardwareJoypads) { Joypads.Add(new VirtualJoypad(null, j.Index, j.Name)); } }