Original Post — Direct link

There is a pretty confusing logic, when multiple arrow keys are pressed. Pressing left and right simaltaneously evaluates to walking right. So right gets priority before left. If you then add up or down, you keep walking right plus the third direction.

Pressing up and down moves the character up. Adding the right arrow key, adds movement to the right. Adding the left arrow key does add movement to the left, but also changes vertical movement to down. Somehow pressing left overrides the "up before down" priority. This is strange!

Pressed arrows in red. Direction in yellow.

Also pressing all 4 arrow keys evaluates to walking up right. So the priorities we see from pressing two opposite directions are back in order. The "Up, Left, Down" case is very peculiar!

Any ideas how the underlying code could look like, so that such a behaviour could emerge?

External link →
14 days ago - /u/Klonan - Direct link
if (moveRightActive && moveUpActive)
  return Direction::NorthEast;
if (moveRightActive && moveDownActive)
  return Direction::SouthEast;
if (moveLeftActive && moveDownActive)
  return Direction::SouthWest;
if (moveLeftActive && moveUpActive)
  return Direction::NorthWest;
if (moveUpActive)
  return Direction::North;
if (moveRightActive)
  return Direction::East;
if (moveDownActive)
  return Direction::South;
if (moveLeftActive)
  return Direction::West;
return Direction::None;