How I Simplify Coding 100 Enemies in 1 Minute for My Game
Elegantly skip Ctrl+C -> Ctrl+V and hours of adjusting monsters' stats one by one
Published Nov 4, 2024
Designing elements in game development can indeed be a double-edged sword. On one hand, it's a creative playground where you can bring your wildest ideas to life. Crafting unique characters, intricate worlds, and engaging storylines can be incredibly rewarding and fun. It's a chance to let your imagination run wild and see your visions come to life in a tangible form.
However, the flip side is that it can also become a tedious and time-consuming task. The repetitive nature of certain design elements, like creating multiple variations of the same asset or fine-tuning details to perfection, can feel like a chore.
Balancing the fun and the grind is key. Using tools like procedural generation and AI, like ChatGPT and AmazonQ, can help automate some of the more monotonous tasks, allowing you to focus more on the creative aspects.
Here's some tips that I did to simplify that chore:
Compose your interfaces and type definitions with comments like this and put it into chatbot. You can add instructions to the bot with something like "Create a const variable Record<string, EnemyState> with <type> animals" along with it.
Running it into chatbot would give me something like:
Once the chatbot generates the initial code, my role shifts to that of a reviewer and editor. This involves meticulously going through the code to ensure it aligns with the game's requirements and making any necessary adjustments. For instance, if the chatbot creates a bear character with default attributes, I might decide to enhance its armor for better defense while simultaneously reducing its speed to balance the gameplay. This step is crucial as it allows me to fine-tune the characters and ensure they fit seamlessly into the game's mechanics and narrative. By leveraging the chatbot's capabilities, I can streamline the coding process, saving time and effort while still maintaining creative control over the final product.
Repeat this multiple times and profit!
However, I still need to be careful with the code generated above, so I need to write some tests for it. This step is crucial to ensure that the code functions as expected and integrates seamlessly with the rest of the game.
In my case, the chatbot just generating a path for sprite for the enemies, not the actual file itself. I need to ensure that I don't ship an enemy that doesn't have existing sprite file to production. The test itself is pretty simple, I just install Vitest and create a file with name `enemy.test.ts` in the same folder as the code that I generated:
Running
bun test
would give me:Alternatively, you can write a vite plugin that will fail the build but do the same thing if you want. In any case, you would need to make sure you have some sort of safety belt for your generative code so that you can address the issues that might appear in the future. For me, from the code above I just need to generate sprites using Stable Diffusion later on and fill my assets until my test don't fail with `Sprite 404` code.