public Keypress[] translateInput(GameStateMatch game, KeyboardDevice keyboard) { Keypress[] cmds = new Keypress[keys.Length]; int i = 0; // length/first_free index in cmds array for (int k = 0; k < keys.Length; k++) { if (keyboard[keys[k]]) { if (kxpressed[k]) { cmds[i++] = new Keypress(commands[k], Keypress.KeypressState.HOLD); } else { kxpressed[k] = true; cmds[i++] = new Keypress(commands[k], Keypress.KeypressState.PRESS); } } else { if (kxpressed[k]) { kxpressed[k] = false; cmds[i++] = new Keypress(commands[k], Keypress.KeypressState.RELEASE); } } } if (i == 0) { return(null); } Keypress[] cmds2 = new Keypress[i]; int p = 0; for (int k = 0; k < keys.Length; k++) { if (cmds[k] != null) { cmds2[p++] = cmds[k]; } } return(cmds2); }
/* * public bool CommandAtIs(int time, Keypress c) * { * for (int i=0; i<times.Count; i++) * if (times.ElementAt(i) == time) * if (keypress.ElementAt(i).Type == c.Type && (keypress.ElementAt(i).State == Keypress.KeypressState.PRESS || keypress.ElementAt(i).State == Keypress.KeypressState.HOLD)) * return true; * * return false; * }*/ public Keypress[] CurrentMoveList() { LinkedList <Keypress> valid = new LinkedList <Keypress>(); for (int i = 0; i < keypress.Count; i++) { Keypress c = keypress.ElementAt(i); if (c.State == Keypress.KeypressState.PRESS) { valid.AddFirst(c); } // else if (c.State == Command.CommandState.HOLD) // valid.AddLast(c); // else if (c.State == Command.CommandState.RELEASE) // valid.AddLast(c); } return(valid.ToArray <Keypress>()); }
public Keypress(Keypress cmd, KeypressState state) { keypresstype = cmd.Type; commandstate = state; }
public virtual Keypress[] getKeySequence() { Keypress[] kp = new Keypress[1]; kp[0] = Keypress.KeyNULL; return(kp); }
public void addKeypress(Keypress c, int time) { keypress.AddFirst(c); times.AddFirst(time); }