Game Loop
A game loop is the backbone of your game. It loops around, and every frame re-draws the screen.
But first we need to initialise the window:
fun main() {
w = Window(20, 20)
}
This creates the window, with a width and height of 20. It'll just be blank at the moment though.
Next, every frame, the game loop needs to do 3 things:
clear the screen
re-draw the scene
and then update the screen (or, terminal)
Finally, wait for a bit.
Here is some code to do this:
fun main() {
w = Window(20, 20)
while(true) {
w.clear()
// Code to draw stuff
w.printScreen()
Thread.sleep(100)
}
}
In this snippet, the while(true)
repeats indefinitely, w.clear()
clears the screen, and w.printScreen()
updates the terminal.
If there was any code to draw something in // Code to draw stuff
, then there would be something on the screen.
Now, lets do some interesting stuff.
Last modified: 12 December 2023