by nickelpro · 6y ago · 0 comments
They've worked through the bog standard Python tutorials using input() to capture from stdin, so it should be trivial to design a simple game that uses the arrow keys right? And suddenly this gulf of complexity opens up of event polling, keycodes, integrating third party modules, and they're left wondering why moving one key over on the keyboard is so hard.
If it's a command-line application, they might use curses.
edit Apparently curses isn't available by default in Python3 for Windows. Is there a nice way to do this?
You're saying this like most beginners even have an idea what a tty is.
An anecdote: When I wrote my first C++ program that reads an input (using `cin`, hello-world style), I immediately wondered how to read single keys including arrow keys. The book I was following had nothing about this. I don't remember the exact details but a bit of Internet search got me to `conio.h` (I was using Dev-C++ on Windows) which did work. But getting it to work was so confusing to me at the time. And I didn't even get to understand what it's actually doing under the hood.
I imagine it would be a bit easier in Python given the right libraries, but the dependency management probably adds to the complexity for a beginner.
What’s the keystroke for right-arrow, spacebar, left-shift, and W all being held down?
(Think of an Asteroids arcade game where w is thrust, spacebar is fire, left-shift is shields, and right arrow is rotate. Those are up/down, not strokes, that the player is giving you.)