CleanCut / invaders

Open source terminal arcade game with audio - based off of the classic "Space Invaders"
206 stars 107 forks source link

can't move and shoot at the same time #13

Closed qiaopeng55 closed 1 year ago

qiaopeng55 commented 1 year ago

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

CleanCut commented 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.