{"id":6955,"date":"2025-08-31T18:10:17","date_gmt":"2025-08-31T09:10:17","guid":{"rendered":"https:\/\/the-world-star.com\/?p=6955"},"modified":"2026-11-28T14:14:37","modified_gmt":"2026-11-28T05:14:37","slug":"ai-programming-building-a-game-part-2","status":"publish","type":"post","link":"https:\/\/the-world-star.com\/en\/games\/ai-programming-building-a-game-part-2-6955\/","title":{"rendered":"AI Programming: Building a Game Part 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Today, I'm working on Ubuntu\/Linux. While both Copilot and Gemini have dedicated apps, you can easily use them right in your web browser by searching and logging in.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"786\" src=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164646\/image-12-1024x786.png\" alt=\"\" class=\"wp-image-5768\" srcset=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164646\/image-12-1024x786.png 1024w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164646\/image-12-300x230.png 300w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164646\/image-12-768x590.png 768w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164646\/image-12.png 1082w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After raising the complexity level a bit and explaining what I wanted to build, it suggested making a Breakout-style game.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Trying it out\u2014Python is awesome!<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"690\" src=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164322\/image-10.png\" alt=\"\" class=\"wp-image-5766\" srcset=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164322\/image-10.png 812w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164322\/image-10-300x255.png 300w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31164322\/image-10-768x653.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It wrote the whole thing on the first try: rendering the blocks, a moving ball, a paddle controlled by the cursor to bounce the ball, and breakable bricks.<br>All that's left now is adding a score system, a game-clear condition, and a restart option after a game over.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It mentioned this was for learning purposes, but when you can get something like this working on the first try, you honestly lose all motivation to understand the underlying code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Next Prompt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\"Please allow up to 3 misses. Also, instead of quitting the program on game over, let the player restart by pressing the spacebar.\"<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"626\" src=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31165710\/image-13.png\" alt=\"\" class=\"wp-image-5769\" srcset=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31165710\/image-13.png 800w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31165710\/image-13-300x235.png 300w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31165710\/image-13-768x601.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Absolute perfection.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Next Prompt: Refactoring 1 - OOD<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The code is getting longer. Since we have distinct objects like blocks, the ball, and the paddle, please refactor the code using Object-Oriented Design.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Next Prompt: Refactoring 2 - Detailed Instructions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The run function seems to be the main routine, so please put it at the very bottom and add comments to the logic inside it. Also, the update function is doing way too much, so please break it down into separate functions based on the commented blocks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Copilot's Suggestion and the Next Prompt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">[Copilot]<br>\"With this structure, adding things like<strong>enemy characters<\/strong>or<strong>special blocks<\/strong>will be as simple as adding a new function. Next, we can add<strong>sound effects and BGM<\/strong>to this OOP version to give it a more authentic arcade feel. Shall we do that?\"<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[Prompt]<br>&gt; Make the blocks containing power-ups a different color. Create a block that spawns two balls when destroyed. Go ahead and add some fitting sound effects and BGM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&gt; The code got cut off, so please output the entire thing again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&gt; It keeps cutting off. Is there a character limit per response? Please show the code starting from run().<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apparently there's a character limit per message = a code length limit.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A new fact discovered. Is this because I'm using the free version?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Is around 200 lines (including comments) the absolute limit?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I guess I need to plan carefully and keep individual files compact. That sounds better, though. How do I split classes into separate files? Since I don't know Python, I'll have to start from there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">As soon as I set it up to add more balls... breaking a single block started spawning an infinite number of them.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Things are getting chaotic.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"626\" src=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31172504\/image-14.png\" alt=\"\" class=\"wp-image-5770\" srcset=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31172504\/image-14.png 800w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31172504\/image-14-300x235.png 300w, https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31172504\/image-14-768x601.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Next Prompt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">[Prompt]<br>There's a bug where balls multiply way more than expected under the multi-ball condition. If I let it run, the number of balls increases infinitely. Please cap the maximum number of balls on screen at 10.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[Copilot]<br>Understood. The runaway duplication is mainly caused by \"unlimited multi-ball spawning,\" so I'll set a limit on the number of balls on screen. The implementation is simple: we'll only add new balls up to the remaining slot limit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary of Changes<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Capped the maximum number of balls at 10 (MAX_BALLS).<\/li>\n\n\n\n<li>Added safeguards to prevent exceeding the limit during multi-ball generation.<\/li>\n\n\n\n<li>Slightly varied the initial velocity vectors of the two spawned balls to reduce overlapping.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, ball splitting stopped working entirely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Turns out the infinite ball duplication was caused by an indentation error during copy-pasting. Apparently, Python uses exact indentation positions to define blocks of code. Tricky! That's bound to cause bugs.<br>And sometimes things still break while running. It's probably due to poor collision detection, causing balls to hit blocks repeatedly. Maybe the blocks take too long to disappear? To fix this easily... I just lowered the ball limit to 3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And we're done. Took about 1 to 2 hours. AI programming is incredible.<br>I'll share the source code on a separate page. Right here \u2193<\/p>\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\t\t\t<div class=\"blog-card\">\n\t\t\t\t<div class=\"blog-card-body-outer\">\n\t\t\t\t\t<div class=\"blog-card-body\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<h5 class=\"blog-card-title\">\n\t\t\t\t\t\t\t\t<a href=\"https:\/\/the-world-star.com\/en\/games\/writing-game-code-with-ai-part-2-6950\/\">Writing Game Code with AI: Part 2<\/a>\n\t\t\t\t\t\t\t<\/h5>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"blog-card-text\">\n\t\t\t\t\t\t\t\tThis is based on the original article. The code from the very end of that article is posted here. You can save this code into a text file as a &quot;.py&quot; file, inst\u2026\t\t\t\t\t\t\t<\/p>\n\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"blog-card-site-title\">\n\t\t\t\t\t\t\t<a href=\"http:\/\/the-world-star.com\/en\/\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tThe\u2606World Star\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"blog-card-image-outer\">\n\t\t\t\t\t\t<a href=\"https:\/\/the-world-star.com\/en\/games\/writing-game-code-with-ai-part-2-6950\/\" class=\"blog-card-image-frame\">\n\t\t\t\t\t\t\t<img decoding=\"async\" class=\"blog-card-image-src\" src=\"https:\/\/static.the-world-star.com\/wp-content\/uploads\/2025\/08\/31165710\/image-13.png\" alt=\"\">\n\t\t\t\t\t\t<\/a>\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\n\t\t\t<\/div><\/figure>","protected":false},"excerpt":{"rendered":"<p>Today, I'm working on Ubuntu\/Linux. While both Copilot and Gemini have dedicated apps, you can easily use them right in your web browser by searching and logging in. After raising the complexity level a bit and explaining what I wanted to build, it suggested making a Breakout-style game. Trying it out\u2014Python is awesome! It wrote [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5769,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/175.41.248.22\/?p=5765","_lightning_design_setting":{"layout":"default"},"footnotes":""},"categories":[371],"tags":[1366,1367,1368,1369,860],"class_list":["post-6955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-games","tag-ai-programming","tag-no-coder","tag-beginner-friendly","tag-coding-for-non-engineers","tag-games","en-US"],"_links":{"self":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts\/6955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/comments?post=6955"}],"version-history":[{"count":2,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts\/6955\/revisions"}],"predecessor-version":[{"id":6957,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts\/6955\/revisions\/6957"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/media\/5769"}],"wp:attachment":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/media?parent=6955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/categories?post=6955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/tags?post=6955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}