# Building A Plasma Sword Fighter Game with Amazon Q CLI

> As a DevSecOps engineer, my daily grind usually involves CI/CD pipelines, security audits, and...

- Author: Gabriel Koo (AWS Community Builder)
- Published: 2025-06-18
- Topics: aws, awschallenge, genai
- HTML: https://gabrielkoo.com/blog/building-a-plasma-sword-fighter-game-with-amazon-q-cli-279g/
- Original canonical URL: https://dev.to/aws-builders/building-a-plasma-sword-fighter-game-with-amazon-q-cli-279g

As a **DevSecOps engineer**, my daily grind usually involves **CI/CD pipelines**, **security audits**, and **infrastructure as code**. So, when the "Build Games with Amazon Q CLI" campaign popped up, it was a refreshing detour from the usual. The idea of conjuring a game with just **conversational prompts**, powered by **Amazon Q CLI's Claude 4 large language model**, was too intriguing to pass up. This isn't the usual realm of an "enthusiast" for me, but more of an exploration into how **AI can augment a developer's toolkit**, even outside their primary domain.

## The Game: A "Space Trilogy" Inspired Plasma Sword Fighter ✨

My concept for the game was heavily inspired by the classic **"Space Trilogy" narratives** (you know the ones 😉), where the good guys wield **blue "light swords"** and the antagonists opt for menacing **red ones**. I wanted to capture that classic duel vibe, with players having **supernatural "force push" abilities** to add another layer to the combat. The result is a **"Plasma Sword Fighter" game** – a **two-player combat experience** featuring **real-time sword mechanics** and **tactical force pushes**. It's designed to be **intuitive, visually engaging**, and, importantly, **free from copyright entanglements** by using generic names.

## Effective Prompting: Speaking the AI's Language 🗣️

My interaction with Amazon Q CLI was a rapid learning curve in **effective prompting**. Here’s what I found worked best:

**Context is King**: I started by setting the scene: "write a pygame on a streetfight style of star war light sword game, but don't use real names to avoid copyright." This broad stroke gave the AI its initial direction.

![Initial Prompt](/assets/img/216c1c4fdc95.png)

**Feature by Feature**: Instead of overwhelming the AI with a massive request, I let the AI to design an initial version first, followed by my later bug requests as well as feature enhancements, this allowed the AI to build the game incrementally.

![Initial Features](/assets/img/ad701b2b31d9.png)

**Leveraging Error Messages**: When things inevitably went sideways (as they do in development 🐛), I found Amazon Q CLI doing a good job on **auto-identifying the errors** from the command outputs in its initial runs, and it was able to **resolve the errors by itself** without my intervention.

![Auto resolved package error](/assets/img/b08925e79cdd.png)

**Refining Game Logic**: One of the more nuanced challenges was ensuring **continuous damage** when an opponent remained in the sword's active area. My prompt, `"now there's a problem, the opponent's HP doesn't decrease for a 2nd time if the opponent stayed in the attack area of the plasma sword.` resulted in `You're right! The issue is that the combat detection only triggers once per attack due to the last_hit_time check. When a player holds down the attack button and the opponent stays in range, it should continue dealing damage. Let me fix this:"`, guided Amazon Q CLI to implement a **time-based hit detection**, allowing for sustained damage while preventing hit-spamming with **invulnerability frames**.

![Fixing the "double hit" issue](/assets/img/bc7e4b73582a.png)

## AI as a Development Accelerator / Quick Prototype Generator ⚡

**Amazon Q CLI**, recently powered by **Claude 4**, proved to be an **invaluable development partner**. It automated much of the heavy lifting, significantly reducing my **development time**:

- **Boilerplate Generation**: The initial `pygame` setup, including window creation, basic event loops, and constant definitions, was generated almost instantly. This freed me from the mundane setup tasks.
- **Core Game Mechanics**: From player movement and sword activation to force push mechanics and health management, the AI took my **high-level descriptions** and translated them into **functional code**.
- **Smart Debugging**: The AI's ability to not only identify errors but also **suggest and implement fixes**, like installing missing libraries or correcting logical flaws in combat detection, was a **major time-saver**.
- **Iterative Refinement**: The **back-and-forth process of prompting, testing, and refining** allowed for quick iterations and continuous improvement of the game's mechanics.

## About the Code 💻

The Python code for the "Plasma Sword Fighter" game is straightforward and relies solely on the **`pygame` library**. While some of the combat and AI logic might appear "raw" to a seasoned game developer, offering room for more sophisticated refactoring (e.g., using state machines for AI), the current structure is **remarkably readable**. This clarity is a testament to the AI's ability to produce **understandable code**, even when generating complex interactions.

The full code is be hosted on GitHub here: <https://github.com/gabrielkoo/amazonq-plasma-sword-fighter-game/>

## Screenshots and Gameplay 🎮

![Image description](/assets/img/f2d63e851321.png)

![Image description](/assets/img/ad28a54008f8.png)

![Image description](/assets/img/e1e9045e84e7.png)

![Image description](/assets/img/2d0d2cbd6f3e.png)

Here are some snapshots from the "Plasma Sword Fighter" battles:

- **Ready for Battle**: The game's initial screen, featuring two fighters against a cosmic backdrop, their health bars poised for action.
- **Mid-Combat**: A dynamic shot showing the glowing plasma swords in action, with players engaged in a fierce duel.

### Game Features:

- **Two-player combat** with **glowing plasma swords** (avoiding copyright)
- **Real-time combat system** with sword swinging and blocking
- **Supernatural "force push" ability** with cooldown mechanics
- **Health system** with visual health bars
- **Invulnerability frames** after taking damage
- **Visual effects** including sword glow and hit flashes
- **Starfield background** for an immersive space combat feel
- **AI opponent** with adjustable difficulty (Easy, Medium, Hard)

### How to Play:

- **Player 1 (Blue)**: WASD to move, SPACE to activate sword, SHIFT to attack, Q for force push, T to toggle targeting mode (mouse vs. auto-target).
- **Player 2 (Red)**: Arrow keys to move, Right CTRL to activate sword, Right SHIFT to attack, ENTER for force push, P to toggle targeting mode (mouse vs. auto-target).
- **AI Difficulty**: Press 1 for Easy, 2 for Medium, 3 for Hard.

### Combat Mechanics:

- Activate your plasma sword and maneuver close to your opponent.
- Swing your sword to deal damage (**10 HP per hit**).
- Utilize **force push** to knock back enemies and inflict minor damage (**5 HP + knockback**).
- Each player starts with **100 HP**; the first to reach 0 loses.
- Brief invulnerability periods after taking damage prevent spam attacks.

### Game Controls:

- Press **R to restart** after a game over.
- Press **ESC to quit** anytime.

The "Plasma Sword Fighter" game captures the essence of classic space duels without infringing on any existing intellectual property. The visual effects create that iconic glowing sword aesthetic, offering a fun and engaging combat experience.

## Final Thoughts 💡

This experience with Amazon Q CLI wasn't just about building a game; it was about understanding the practical applications of **GenAI in accelerating software development**. **Amazon Q CLI**, recently leveraging **Claude 4**, is a **powerful tool** that can significantly enhance productivity, even for those working outside traditional software development domains. It's a clear example of how **GenAI can democratize development**, allowing anyone with an idea to bring it to life with guided assistance. I'm genuinely impressed and encourage others to experiment with Amazon Q CLI to discover its potential firsthand.
