跳到主要內容

實戰 Vibe Coding:利用 Amazon Q Developer CLI 打造經典平台跳躍遊戲

本篇文章將介紹如何透過 Amazon Q Developer CLI 建構一款完整的 2D 平台跳躍遊戲,從初始生成、功能增強,到最終打造出具備多關卡、多樣互動元素的遊戲體驗。特別的是,過程中開發者並未撰寫任何一行程式碼,僅透過自然語言指令與 CLI 對話完成所有工作,實踐「Vibe Coding」( 氛圍編碼 )。

image

本文作者為 Haowen Huang, AWS Senior Developer Advocate. 擁有 20 年以上電信、互聯網以及雲端運算等行業架構設計、技術及創業管理等豐富經驗,曾任職於 Microsoft、Sun Microsystems 等企業,專注為遊戲、電商、媒體和廣告等企業客戶提供 AI/ML、數據分析和企業數字化轉型等解決方案諮詢服務。

引言

本篇文章 (English Version) 將介紹如何使用 Amazon Q Developer CLI,以無需撰寫任何程式碼的方式,打造一款經典的 2D 平台跳躍遊戲。透過「Vibe Coding」( 氛圍編碼 ) 的開發流程,開發者可以藉由簡單的語言提示詞 (prompt),逐步完成從遊戲雛型、功能擴充到完整關卡設計的開發流程。

整體開發流程將分為三個步驟:

1. 生成遊戲雛型
2. 功能擴充強化與畫面調整
3. 導入參考架構建立完整遊戲

環境建置

使用者需先安裝並設定 Amazon Q Developer CLI。對於 macOS 使用者,可透過下列步驟完成安裝:

  1. 下載並安裝 Amazon Q Developer CLI
  2. 登入 Builder ID 完成認證
  3. 開啟終端機控制與無障礙設定
  4. 執行 q doctor 指令檢查 Amazon Q Developer CLI 是否安裝成功:
  5. 遊戲開發方面,建議使用 Python 語言與 Pygame 套件,可透過下列指令完成安裝;Pygame 提供以下功能支援:
  • 畫面與動畫渲染
  • 音效播放
  • 鍵盤與搖桿輸入控制
  • 物理模擬與碰撞偵測
  • 多種媒體格式支援(圖片與音效)
$ q doctor

image

$ pip install pygame

第一步驟:初步生成遊戲雛型

透過簡單的一句 prompt,Amazon Q Developer CLI 結合 Pygame 套件可快速生成具備基本跳躍與平台邏輯的遊戲原型。CLI 自動產生完整的 Python 程式碼,使用者無需編寫任何程式碼即可執行並測試遊戲功能。👉 檢視 GitHub 原始碼(v1)

$ q chat
> Create a classic platform game using the Pygame library, replacing traditional coins with stars and standard walls with post-industrial cyberpunk style

遊戲雛型包括:

  • 主角角色控制
  • 基本平台邏輯
  • 重力與跳躍效果

image

啟動遊戲的指令如下:

source venv/bin/activate && python main.py

在第一步驟的嘗試中,Q CLI 能在輸入第一個 prompt 後,能立即完成整個遊戲的程式設計,展現了非常強大的生成能力。不過,儘管遊戲邏輯完整、可執行,整體 UI(使用者介面)仍偏向基礎與簡單。因此,建議進行第二步驟,持續與 Q CLI 對話,透過更多指令逐步強化遊戲的視覺效果與互動性。

第二步驟:功能擴充強化與畫面調整

進入第二個步驟後,開發者可透過進一步提示,引導 Q CLI 強化遊戲內容,包括:

  • 加入角色動畫與精靈圖(sprites)
  • 整合音效與背景音樂
  • 實作畫面滾動(camera scrolling)
  • 加入分數計算與顯示機制
> /quit

$ q chat 
>  Please examine the code directory located at /Users/AMAZON/DA-Stage/DA-Role/2025/CLI-Q/my-blogs/platform-game/v1, which contains the platform game code (version 1) that you previously wrote. I need you to create a new directory at /Users/AMAZON/DA-Stage/DA-Role/2025/CLI-Q/my-blogs/platform-game/v2 and copy all the version 1 code files to this new directory.

image

如上所示,Q CLI 成功建立了一個新的 v2 子資料夾,並將 v1 版本的所有程式碼完整地複製到了這個新位置。接著指示 Q CLI 將後續的開發工作切換到這個新的資料夾中:

>  You should work on the directory: /Users/AMAZON/DA-Stage/DA-Role/2025/CLI-Q/my-blogs/platform-game/v2

加入精靈圖與音效

Enhance this game by implementing the following extension features: 1) Improving the 3D visual effects of the gameplay graphics; 2) Add appropriate sound effects; 3) Creating a scrolling camera system

實作畫面滾動與更多遊戲元素

> Continue to enhance this platform game by: 1) Improving the 3D visual effects of the sprites; 2) Adding more levels; 3) Implementing power-ups; 4) Creating a scrolling camera; 5) Including more enemy types

透過這些強化功能,遊戲的視覺效果與互動性獲得明顯提升,如此將使遊戲更具吸引力。👉 檢視 GitHub 原始碼(v2)

image

第三步驟:導入參考架構建立完整遊戲

在初步嘗試中,開發者藉由逐步輸入 prompt 的方式與 Q CLI 互動,讓模型依據需求逐步增強遊戲功能。然而,這種逐步式開發對於開發一款結構完善、關卡漸進的遊戲而言仍不夠完整。因此我們可以思考:若能將現有的開源遊戲專案作為參考,是否能讓 Q CLI 學習其結構與邏輯,進而產出完整的遊戲設計?

而為了打造完整的遊戲體驗,開發者可以讓 Amazon Q Developer CLI 對開源專案進行分析,並根據分析結果生成新遊戲架構。本案例中,筆者選擇 GitHub 上的 PirateMaker 作為參考專案;該專案為「公有領域(Public Domain)」,授權釋出,可自由修改與應用,包含商業用途,無需取得額外授權,適合作為生成模型的參考資料。

透過 Q CLI 學習外部專案並生成新遊戲

$ q doctor
$ q chat
> Referring to the approach and implementation of the code in the project https://github.com/clear-code-projects/PirateMaker, design a complete platform game in Python.

Q CLI 在獲得使用者授權後,自動下載並分析專案架構,並生成一份全新平台遊戲的系統設計。

I'll help you design a platform game in Python using the PirateMaker project as a reference. Let's first examine the PirateMaker project structure to understand its implementation approach.

I will run the following shell command:
git clone https://github.com/clear-code-projects/PirateMaker /tmp/PirateMaker && ls -la /tmp/PirateMaker

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> t

Q CLI 所生成的整體遊戲架構

透過分析 PirateMaker 專案,Q CLI 建構出了一套模組化遊戲架構,內容包括:

模組名稱 說明
main.py 控制主遊戲迴圈與狀態轉換(主選單、關卡、編輯器)
settings.py 管理遊戲參數與設定常數(螢幕尺寸、物理引擎參數等)
level.py 處理 CSV 關卡資料載入、碰撞機制、物件互動
player.py 定義主角行為與動畫邏輯,支援各種強化狀態(如火球、星星)
enemies.py 管理敵人類型(如 Goomba、Koopa)的 AI 行為與碰撞邏輯
tiles.py 建構地圖區塊與互動物件(如問號磚塊、可破壞牆)
ui.py 管理 UI 元素,如分數、時間、主選單與按鈕互動
editor.py 提供關卡編輯器功能,支援多層編輯與存檔
particles.py 負責產生各種視覺特效(如爆炸、閃爍、得分)
support.py 資源載入與輔助工具函式庫

小結而言,Amazon Q Developer CLI 對其執行下列操作:

  • 複製開源專案並解析架構
  • 擷取遊戲功能模組與邏輯
  • 根據參考設計,生成包含難度調整、敵人互動、完整關卡等功能的新遊戲 (如下所示)

platform-game/
├── main.py # 遊戲主迴圈
├── settings.py # 遊戲設定
├── level.py # 關卡控制
├── player.py # 玩家角色邏輯
├── enemies.py # 敵人系統
├── tiles.py # 遊戲場景與方塊
├── ui.py # 使用者介面
├── support.py # 輔助工具
├── editor.py # 關卡編輯器
├── particles.py # 視覺特效系統
├── assets/ # 遊戲素材資源
└── levels/ # 關卡資料儲存

補充:除錯與功能微調可透過自然語言持續優化

由於生成程式碼可能初期包含錯誤,開發者可透過 Q CLI 提供錯誤說明與除錯請求,例如:

> You previously referenced https://github.com/clear-code-projects/PirateMaker and generated some platform game code in this directory, but the game cannot run correctly now. Please modify these codes so that the game can run properly
> Could you fix the trouble "failed to print tool: stream did not contain valid UTF-8"?
> I need a 'Replay' feature
> When the red block and blue block collide with each other, the screen freezes, and you can only press 'R' to restart or press 'ESC' to exit.
> The Arrow keys used for moving left and right are not working
> How can I proceed to the next level?

開發流程總結

步驟 內容 成果
1 初始生成 平台邏輯 + 跳躍控制
2 功能增強 精靈圖、音效、滾動畫面
3 完整遊戲 難度設計、多關卡、敵人互動

最終成果展示

透過 Amazon Q Developer CLI,筆者成功打造出具備三種難度模式、支援多關卡、敵人互動、視覺特效與編輯器的經典平台跳躍遊戲。全程透過自然語言溝通與命令列操作完成,實踐真正的「Vibe Coding」( 氛圍編碼 ) 體驗。

若想進一步了解完整示範過程,筆者亦製作了相關展示影片並上傳至 YouTube

雖然目前版本的美術細節仍有進一步優化的空間,例如尚未指示 Q CLI 產生寫實的牆面材質,但整體程式碼架構已具備高度完整性。只需再投入一些時間,持續與 Q CLI 對話,就能建構出更具視覺深度與互動性的遊戲體驗。若讀者有興趣深入了解技術細節,可前往以下 GitHub 查看完整程式碼 👉 檢視 GitHub 原始碼(v3)

在本機 macOS 執行遊戲的指令如下:

source venv/bin/activate 
python fixed_game_v1.py

專案總結:全程無需撰寫程式碼,打造完整跳躍遊戲

透過 Amazon Q Developer CLI,本專案實現了無需手動撰寫任何程式碼,即完成一款具備完整邏輯、音效與視覺效果的經典平台跳躍遊戲。整體開發歷程可分為三大步驟:

  1. 初步生成遊戲雛型:以一行 Prompt 建構出可執行的基本平台遊戲雛型。
  2. 功能擴充強化與畫面調整:透過逐步輸入需求,加入精靈圖、音效與捲動畫面等互動效果。
  3. 完整遊戲架構建構:引用開源專案 PirateMaker,指示 Q CLI 分析並生成一套結構化的遊戲系統,涵蓋關卡管理、物理機制與敵人行為等要素。

在開發過程中,若遇技術性錯誤,皆可透過自然語言提示修復。最終成果包含自訂角色動畫、三種難度關卡與完整 UI 系統,充分體現大型語言模型在軟體創作上的潛力。

給開發者的建議:創作門檻再降低,創意邊界再拓寬

本次遊戲開發歷程驗證了 Amazon Q Developer CLI 作為程式開發助手的可行性與靈活性。它不僅適用於原型 (Prototype) 快速開發,更具備學習與模仿開源架構的能力,能協助開發者快速構築成熟產品;隨著「Vibe Coding」(氛圍編碼) 模式日益普及,開發門檻正快速降低,而創意實現的速度也正被大幅提升。

對於想要進入遊戲開發、工具創作或教育應用領域的開發者,Amazon Q Developer CLI 著實提供了一個值得探索的全新可能性!

🎮 現在就啟動你的 CLI,讓創意與 Q Developer 一起展開旅程。Happy Vibe Coding!

留言

這個網誌中的熱門文章

Early Guide to Joining COSCUP 2025 

(Updated: Feb 13) Many people in the community are excited to find out how to participate in COSCUP 2025. We’ll share more updates soon, but here’s what we can share so far! You can join as a speaker, host a booth, organize a track, or become a sponsor. If you’re new to COSCUP, take a look at the article " COSCUP Unveiled " to learn more. Date and Location The event will take place at NTUST in Taipei, Taiwan, on a weekend in late July to early August, as usual. The planned dates for this year are August 9-10. Be a Speaker Our early bird Call for Proposals (CfP) is now opened!  If you have a presentation about open culture or open-source technology, we want to hear from you. Submitting early means you’ll hear back sooner about your proposal. Host a Booth Open-source communities can set up booths to display their work and interact with attendees. This is a great way to share your community’s projects and connect with others. Businesses that support open-source can also host a ...

COSCUP 2025 Call for Proposals / 徵稿辦法

COSCUP 常規徵稿已於 2025-05-10 截止,接下來進入加碼徵稿階段。加碼徵稿是為了提升大會的稿件品質,依據投稿狀況(數量、品質)部分徵稿主題可能提前喊停。最遲請於 05 月 24 日(AoE) 前投稿,徵稿主題可參考下方列表。 The regular call for proposals (CFP) for COSCUP closed on May 10, 2025. We are now entering the bonus CFP phase to improve the quality of submissions. Some topics may close earlier than expected, depending on the current status of submissions (in terms of quantity and quality). Please submit by May 24 (AoE) at the latest. You may refer to the topic list below for inspiration. 開始投稿 Submit Your Proposal 提案須知 Things you may need to know 演講形式:預設為現場30分鐘演講包含QA,若有其他需求可於提案系統註明,由各主題主辦單位決定如何安排。 Talk Format : The default format is a 30-minute on-site talk, including Q&A. If you have other requirements, please indicate them while submitting your proposal. The final arrangement will be decided independently by the organizers of each topic. 語言:COSCUP 受眾包含海內外與會者,大會不限制發表語言但鼓勵以英語發表。大會將公布雙語議程表,請提供中英文版議程介紹。 L...

COSCUP 2025 Call for Participation, 議程軌與攤位即日起開放申請

Jump to English   COSCUP 2025的社群議程/攤位即日起開始接受申請,社群議程於3月22日截止申請,社群攤位於6月10號截止。請有興趣在今年與我們共襄盛舉的社群把握機會! 👉  申請加入 以下介紹如何在 COSCUP 籌辦議程軌或攤位的流程及注意事項。