I’m fairly new to scripting and I have a high-level question of how to do something.
I want to design a simple game similar to space invaders, with these two main features for now:
- Bullets drop down from the top of the screen every second.
- The user can move the home ship around at the bottom line of the screen and dodge the bullets.
The issue is that I can't find a way to constantly move the bullets down while still getting input.
Most of the code from the main loop:
while true #gets user input and updates screen.
read -r -sn1 -t 1 USERIN
case $USERIN in
D) moveleft ;;
C) moveright ;;
updatescreen #(my code makes sure that at least a second has passed since the last "updatescreen" execution before running this)
I want the screen to update every second, independently of the user input. Right now, the program is choppy when it updates because sometimes it has to wait longer for the input to timeout. It would be nice to have a lower read timeout but if I lower it I get an error: "invalid timeout specification."
Is there a way around this or maybe a whole different program organization?