Hacker News new | ask | show | jobs
by cactusface 4007 days ago
It's actually reasonable. Step 1, translate key push. Step 2, broadcast key message. What you're missing is that there's an alternate Step 1, translate joystick hat push (or mouse drag, or whatever). So Step 2 should be broadcast generic up/down/left/right input message. Step 3, translate message into movement. But what you're missing is that dependent on context, there's going to be other things besides movement that those keys do. Step 4, pan the map with N/S/E/W. Again here, you have the flexibility to work with a rotated map. Your code was probably overdesigned for the use case, but I've seen your solution many times, in books and in real life.

However, I've also solved this problem by passing around polar coordinates, it's elegant and very flexible but you have to munge some data at the beginning. You can also pass around a simple vector [{-1, 0, 1}, {-1, 0, 1}], which is basically what you describe.