virtual protected void SendInputDown(Vector2 velocity, CommandRegion region) { primaryClient.SendMessage("OnInputDown", new DirectionalAnalogEvent() { Velocity = velocity, Region = region }, SendMessageOptions.DontRequireReceiver); }
public void Flush() { commandString = new char[] { 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n' }; commandSize = 0; commandDirection = 0; lastDirectionalRegion = CommandRegion.None; LastInput = DirectionalAnalogEvent.Empty(); }
public static bool LineCast(CommandRegion start, CommandRegion middle, CommandRegion end) { if (middle != CommandRegion.Center) { return(false); } else { return(ClockwiseCast(start, end, 4)); } }
virtual protected bool GetInput(out Vector2 vel, out CommandRegion reg) { bool state = GetInput(out vel); if (state) { reg = GetRegion(vel); } else { reg = CommandRegion.None; } return(state); }
private void InterpretStep(CommandRegion reg) { if (commandSize > 9) { Flush(); } if (reg == CommandRegion.Center) { commandString [commandSize] = 'c'; } else if (reg == CommandRegion.None) { commandString [commandSize] = 'n'; } else if (lastDirectionalRegion == CommandRegion.None) { commandString [commandSize] = 'd'; lastDirectionalRegion = reg; } else if (commandDirection == 0) { int delta = (int)reg - (int)lastDirectionalRegion; //commandDirection = delta > 0 || delta == -7 ? 1 : -1; //delta = delta == commandDirection * -7 ? 1 : delta; //commandString [commandSize] = Math.Abs (delta).ToString () [0]; //lastDirectionalRegion = reg; lastDirectionalRegion = reg; } else { int delta = commandDirection * ((int)reg - (int)lastDirectionalRegion); //delta = delta < 0 ? delta + 8 : delta; if (delta == commandDirection * -7) { delta = 1; } else if (delta < 0) { delta += 8; } commandString [commandSize] = Math.Abs(delta).ToString() [0]; lastDirectionalRegion = reg; } commandSize++; }
public static bool ClockwiseCast(CommandRegion start, CommandRegion end, int count) { int dif = (int)end - (int)start; return(IsDirectionCommand(start) && IsDirectionCommand(end) && (Math.Abs(dif) == count || Math.Abs(dif) == 8 - count)); }
//Chek if the regions are a counter-clockwise sequence public static bool CounterClockwiseSequence(CommandRegion start, CommandRegion end) { int dif = (int)end - (int)start; return(IsDirectionCommand(start) && IsDirectionCommand(end) && (dif == -1 || dif == 7)); }
public static bool IsDirectionCommand(CommandRegion reg) { return(reg != CommandRegion.Center && reg != CommandRegion.None); }
public static bool IsCenterCommand(CommandRegion reg) { return(reg == CommandRegion.Center); }