
Asteroid Q: Strategic 2D Asteroid Hunter Game
Building a Flutter Web Game with Amazon Q Developer
Published Jan 13, 2025
Intrigued by the possibilities of Amazon Q Developer, we challenged ourselves to build a fully interactive game using only Flutter, without any game engines.
Creating a visually engaging experience without relying on sprites presented a unique opportunity.
Inspired by the classic arcade shooter 1942, we decided to develop a board game that captures the essence of aerial combat in a fresh and innovative way.
Asteroid Q is a 2D asteroid hunting board game inspired by the classic arcade shooter, 1942.
The game's universe is represented by a Cartesian plane, where each coordinate denotes a distinct galaxy within a vast, procedurally generated universe.
The objective is to destroy 100 asteroids using a jet fighter as efficiently as possible.
Play the Game: https://asteroid.hasto.dev
You will start your journey with 50 fuel units and 3 lives in a randomly selected galaxy.
Each galaxy is populated with asteroids to destroy and fuel pods to replenish your jet.
The number of these objects varies depending on the galaxy's size.
The number of these objects varies depending on the galaxy's size.
There are 3 galaxy size based on your device in this game :
- Itokawa (Mobile): 1 fuel pod, 3 asteroids
- Hygiea (Tablet): 1 fuel pod, 5 asteroids
- Chiron (Desktop): 2 fuel pods, 7 asteroids
Maneuvering your jet fighter consumes fuel, and the amount of fuel consumption is different for each activity :
- Movement: 2 fuel units per space unit traveled
- Rotation: 1 fuel unit per turn
- Missile Launch: 5 fuel units per launch (regardless of impact)
- Refueling: Free
Here's what makes Asteroid Q a thrilling challenge:
- Deadly Asteroids: Fly carefully! Colliding with an asteroid will cost you a life. You have three lives to protect the universe.
- Limited Missile Range: Your missiles have a range of 3 spaces. Destroy asteroids within this range to score points.
- Strategic Refueling: Run low on fuel? Land on a fuel pod to replenish your reserves by 100 units.
Destroying 100 Asteroids will put your name into the Leaderboard.
Leaderboard rankings are based on efficiency: less space travel, fewer rotations, minimal refueling, and exploring the fewest galaxies possible.
For fair competition, each galaxy size (Itokawa, Hygiea, and Chiron) has its own leaderboard, ensuring players aren't unfairly disadvantaged by screen size.
Keyboard:
- Select a Tile: Use WASD or the arrow keys to highlight the tile you want to move to.
- Move: Press Enter to move your jet to the selected tile.
- Launch Missile: Press Spacebar to fire a missile.
- Refuel: Press R to refuel when over a fuel pod.
Mouse:
- Select Tile & Move: Left-click on a tile to move your jet there.
- Launch Missile: Right-click to fire a missile.
- Refuel: Middle-click to refuel when over a fuel pod.
Touchscreen (Tablet & Mobile):
- Move: Tap a tile to move your jet to that location.
- Virtual Controls: Use the on-screen buttons for movement, firing missiles, and refueling.
We'd always been curious about AI coding assistants, but the sheer number of options available was overwhelming. We weren't sure where to start or which tool would best fit our workflow.
The AWS Game Builder Challenge provided the perfect opportunity to finally explore this exciting technology.
We chose Amazon Q Developer and set ourselves a challenge: Q would be responsible for generating all the code for our game. Our role would be simply to assemble the pieces, like building with LEGO.
We were blown away by Amazon Q's capabilities. With detailed prompts, it generated incredible results, transforming our approach to programming.
Q's boilerplate code generation, both through inline suggestions and direct prompts, significantly accelerated development.
Q handled everything from routing and navigation to the initial UI, grid management, object placement, data structures, collision detection, jet movement, fuel management, and input handling.
Here are a few examples of the prompts we used to generate specific game elements:
- Routing and Navigation
- Responsive Game Board Grid
- Movement Algorithm
- Object Collision Algorithm
- Blinking Animation
The leaderboard in Asteroid Q is reserved for those who achieve the ultimate goal: destroying 100 asteroids.
Upon reaching this milestone, your score is automatically saved to the correct leaderboard based on your device (desktop, tablet, or mobile).
We understand that life can interrupt even the most intense asteroid-blasting sessions. That's why Asteroid Q features secure local storage.
Your current progress is saved locally and encrypted to ensure data integrity. You can seamlessly pick up where you left off on the same device, provided you remain logged in.
The AWS Game Builder Challenge marked our first foray into the world of AWS services. While initially daunting, the abundance of online tutorials proved invaluable in guiding our first steps.
We integrated several AWS services into our game:
1. AWS Cognito: Securing Our Leaderboard
Our initial plan was to save leaderboard entries directly to DynamoDB using the aws_dynamodb_api package.
However, during testing, we discovered a critical security flaw:
our access and secret keys were exposed in the main.dart.js file, despite using environment variables. This posed a significant risk to our AWS account.
Following AWS best practices, we implemented AWS Cognito for secure authentication and authorization. This ensured that only authenticated users could access and modify leaderboard data.
We followed the excellent Authentication guide for Flutter on Amplify Docs to seamlessly integrate Cognito into our game.
2. AWS Amplify REST API: Connecting to DynamoDB
With Cognito in place, we needed a secure way to interact with our DynamoDB database. AWS Amplify's REST API provided the perfect solution.
Using the Amplify CLI and the REST API CRUD template, we effortlessly created an API to save leaderboard entries. This streamlined the process significantly, allowing us to focus on gameplay rather than backend infrastructure.
We followed the API (REST) guide for Flutter on Amplify Docs for this integration.
We're just getting started with Asteroid Q! We have a galaxy of exciting features planned to make the game even more addictive. Get ready for:
- Multiple Difficulty Levels: From casual asteroid cruising to intense cosmic battles, we'll be adding difficulty levels to challenge players of all skill levels.
- Thrilling Multiplayer Modes: Imagine teaming up with friends to take down colossal asteroids or battling head-to-head for galactic supremacy. Multiplayer is definitely on our radar!
- Hidden Easter Eggs: We love surprises! We'll be hiding secrets and Easter eggs throughout the game for players to discover. Keep your eyes peeled!
- Upgrade Paths: Want to supercharge your jet fighter with powerful lasers or equip it with devastating missiles? We're planning upgrade paths that will let you customize your ship and unlock new abilities.
- Native Mobile and Desktop Experiences: We want Asteroid Q to be accessible to everyone, everywhere! We're working on bringing the game to native mobile and desktop platforms for a smoother, more optimized experience.


