I've just started with Haskell and want to make a simple real-time game without installing additional libraries. I need to write a loop that scans for keyboard input but the game also has to run if there is no input. How do I do this?
How can I write a simple real-time game loop in pure Haskell?
879 views Asked by Miloslav Číž At
1
this answer is being updated as I find new solutions
After hours of studying I came up with the following code:
A few notes:
inputTimeout
microseconds, but not exactly. Very fast input could theoretically lower this, computation delays will increase this.updated code
In previous code, if the game
nextGameState
function took a significant time to compute, the input characters would pile up in stdin and the reaction of the program would be delayed. The following code solves this by always reading all characters from input and taking only the last one.