# How I built an "Asteroids" game using Jetpack Compose for Desktop

DevFeed: [How I built an "Asteroids" game using Jetpack Compose for Desktop](<https://devfeed.tech/articles/how-i-built-an-asteroids-game-using-jetpack-compose-for-desktop-22981.md>)

Original publisher: [Read original article](<https://dev.to/kotlin/how-i-built-an-asteroids-game-using-jetpack-compose-for-desktop-309l>)

Author: Sebastian Aigner

Published: 2021-05-06T13:03:23Z

Content type: tutorial

Language: en

Sources: [Kotlin](<https://devfeed.tech/sources/kotlin-2.md>)

Topics: [compose-for-desktop](<https://devfeed.tech/topics/compose-for-desktop.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Code](<https://devfeed.tech/topics/code.md>), [arcade](<https://devfeed.tech/topics/arcade.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [code](<https://devfeed.tech/tags/code.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [compose-for-desktop](<https://devfeed.tech/tags/compose-for-desktop.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [gamedev](<https://devfeed.tech/tags/gamedev.md>), [games](<https://devfeed.tech/tags/games.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [jetpackcompose](<https://devfeed.tech/tags/jetpackcompose.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [software](<https://devfeed.tech/tags/software.md>), [state-management](<https://devfeed.tech/tags/state-management.md>)

## AI overview

A tutorial explaining how to build a basic Asteroids-style game with Jetpack Compose for Desktop. It discusses the game's structure, including the game loop, state management, rendering, and the differences between declarative UI and repeatedly updating game logic.

## Source excerpt

A while ago, I tweeted about a small game I had created on top of Jetpack Compose for Desktop: A small clone of the classic arcade game Asteroids, in which you control a space ship with your mouse, and navigate the vastness of space, avoiding and breaking asteroids in the process. // Detect dark theme var iframe = document.getElementById('tweet-1382668779377762305-462'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1382668779377762305&theme=dark" } Today, it's time to take a look under the hood and understand how I built a basic version of this game, and how Compose for Desktop helped me achieve it in just one evening! We will take a look at parts and structures in the code that I find the most interesting. To see how it all fits together, I suggest exploring the whole code on GitHub. The whole implementation is only 300 lines of code, which I hope makes studying and understanding it easy. The Game If you're not caught up on your 80s arcade trivia, Asteroids was a popular arcade game where you try to steer your space ship through space, avoiding and destroying asteroids with your ship. Because of the limitations of the hardware at the time, the game is quite simplistic in appearance: a triangular spaceship moves across a plain background and avoids simple displays of asteroids on a 2D surface. What makes this a challenge is the interia: Just like a real space ship, your spaceship moves along its course in a straight line at constant speed, and you need to make corrective maneuvers by turning your ship and directing your thrust. Asteroids has achieved cult status in the arcade game scene. Because of that, I wanted to see what it would take to recreate this experience using Jetpack Compose for Desktop! The Building Blocks I have roughly divided the project into a few building blocks that make up the project, and that we will talk about. Namely, those are: The Game Loop Game State Management Render