Created
May 6, 2022 08:40
-
-
Save alexmaryin/e552473c8299fbe8ae69b6de66b37870 to your computer and use it in GitHub Desktop.
Starfield Kotlin main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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