Closed qiaopeng55 closed 1 year ago
I don't believe that's possible using the crossterm
library.
As far as I am aware, crossterm only reports the key events sent by the OS as if you were in a text editor. If you place your cursor on a line of text and hold the arrow key down you'll see your cursor move continuously (after a short initial pause), but if you press the space bar while that is going on you will see that you get a space character, and the arrow key is now ignored.
If crossterm provided access to the keyboard state (what keys are pressed right now), then we could use that instead. If crossterm provided key press/release events, then would could keep track of the state inside of invaders. Unfortunately, we only get the events as if you are in a text editor.
The only "real" solution here would be to find a different (or additional) library that would provide the information we need... 🤔 ...which is possible to do, if you'd like to look into it. 😉
For now, though, I'll consider this question as "answered". Please feel free to continue to discuss this here if you like despite the "closed" status.
in the current game, we can hold left/right to move the spaceship. However, once we pressed the shoot button, the spaceship stopped despite of us still holding the left/right key.
How can we modify the match key_event.code logic to make it support the move and shoot simultaneously? @CleanCut