Skip to content

Instantly share code, notes, and snippets.

@alexmaryin
Created May 6, 2022 08:40
Show Gist options
  • Save alexmaryin/e552473c8299fbe8ae69b6de66b37870 to your computer and use it in GitHub Desktop.
Save alexmaryin/e552473c8299fbe8ae69b6de66b37870 to your computer and use it in GitHub Desktop.
Starfield Kotlin main
fun main() {
SDLEngine(Consts.WIDTH, Consts.HEIGHT) {
val fpsCounter = FPSCounter(window)
val stars = List(Consts.STARS_COUNT) { Star() }
addEventListener("starfield") { event ->
if (event.type == SDL_QUIT) stopLoop()
}
startInfiniteLoop {
onEachFrame {
fpsCounter.checkFPS()
stars.forEach { star ->
star.process()
val color = star.brightness.toUInt().toUByte()
SDL_SetRenderDrawColor(this, color, color, color, 255)
val x = star.viewX + Consts.WIDTH / 2
val y = star.viewY + Consts.HEIGHT / 2
SDL_RenderFillCircle(this, x, y, star.radius.toInt())
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment