DEV Community

Cover image for Building “Traffic Driving” Game Using Amazon Q CLI
Jhai M
Jhai M

Posted on

Building “Traffic Driving” Game Using Amazon Q CLI

Cover image source:AWS EVENT

My First Time with Amazon Q CLI

I had never used Amazon Q CLI before this. When I saw the "Build Games with Amazon Q CLI" campaign, I was curious. It mentioned that you could create a game just by describing it in a prompt, which sounded surprisingly convenient.

So I decided to give it a try. I approached it with no expectations, and I was genuinely impressed by how capable and easy the experience was, especially for a command-line tool.

Installation and Setup (on Windows + WSL Ubuntu)

I followed this essential guide to install everything:
The Essential Guide to Installing Amazon Q Developer CLI on Windows
Once installed, I entered:

q doctor
Enter fullscreen mode Exit fullscreen mode

then:

q chat
Enter fullscreen mode Exit fullscreen mode

And inside the chat, I simply asked it to install Pygame as the game library. Amazon Q CLI did it by itself. That was a surprise and a huge time-saver.

The Prompt That Did It All

Within the Q CLI terminal, I provided a single prompt. Here’s the exact prompt I gave:

Create a 2D top-down racing game using Python and Pygame, styled with pixelated retro graphics like early 2000s mobile games, and set in a neon-lit Tokyo city at night. The player controls a pixel-style racing car driving through Tokyo streets with glowing signs, passing buildings, and ambient traffic lights. The road should scroll vertically to simulate movement, with lane-based controls to move left and right. Add obstacles like other pixel cars, cones, or barriers that the player must avoid. Include collision detection, a game over screen, and a simple scoring system that increases over time. Display a retro-style pixel HUD showing the player's score and speed. Use basic shapes or pixel-style patterns for graphics, and include optional chiptune-style background music and simple 8-bit sound effects. Keep the code in one Python file, organised with classes for the car, road, and obstacles.

That’s all. I didn’t write any code manually.
In just a few minutes, Q CLI generated the code. Then it paused for a moment, thought, and returned with the modified code. After another brief processing period, it corrected the error again and provided me with the final working version. It even saved the Python file on its own. I told it to run the game, and it ran!

EXAMPLE Errors (And How Q Fixed Them)

While generating the game, Amazon Q CLI encountered a couple of minor issues. What really impressed me was how it managed them completely on its own, without any input from me.
Error 1: Missing Color Definition
Q CLI paused briefly, identified the root cause, and added the correct color definition automatically:

NEON_RED = (255, 0, 60)
Enter fullscreen mode Exit fullscreen mode

Error 2: Inconsistent Variable Name
Another issue arose with an undefined variable YELLOW that showed up in a sprite generation function. The code referenced YELLOW, but only NEON_YELLOW was defined.

Q CLI noticed the mismatch, replaced YELLOW with NEON_YELLOW wherever necessary, and regenerated the code. It did all this without me entering any extra prompts.

It kept working through the problem, fixed the error, and re-ran the code. Just like that, the game was up and running. Watching it debug and correct its own output was truly impressive!

Renaming the Game

Initially, the game was named "Tokyo Drift", but I wanted something more generic. I simply told Q CLI:

Change the name to ‘Traffic Driving’ and rename the Python file.

It did both:

  • Renamed the file
  • Updated in-game titles and README accordingly

About the Game - “Traffic Driving”

Traffic Driving is a straightforward 2D top-down racing game with retro pixel graphics and a nighttime atmosphere. You control a pixelated car as it weaves through city traffic at night. You aim to avoid crashes with other vehicles and obstacles.
I’ve always liked pixel-style retro games, especially classic mobile racing games, so I thought it would be a fun idea to bring that to life using Q CLI.

Gameplay Features:

  • Three-lane movement using arrow keys
  • Obstacles: cones, pixel cars, and road barriers
  • Collision detection with game-over screen
  • Scoring system that increases over time
  • Restart (R key) and Quit (ESC) functionality
  • Pixel HUD showing current score and speed

What Impressed Me Most

  • No boilerplate: The code structure was clean, logical, and ready to run.
  • Auto error fixing: Q CLI caught and fixed syntax issues when prompted.
  • Prompt-to-code: Writing the game logic took one prompt. It provided a decent game.
  • Terminal-native: Everything happened inside the command line, with no need to switch tools or editors. For someone who hadn't used Q CLI before, this was a surprisingly efficient and creative workflow.

Conclusion

This was my first time building a game entirely with AI support in the terminal, and honestly, I didn’t expect it to go this smoothly.

Amazon Q CLI managed everything from creating files to fixing bugs, and all I had to do was explain what I wanted. For prototyping, learning, or exploring creative coding ideas, this tool makes the process very easy.

If you haven’t tried it yet, give it a shot, especially if you’re into game development or Python. You might be surprised by how much it can do!

Screenshots

C1

C2

PIC1

PIC2

PIC3

Top comments (0)