Using ChatGPT for Uzebox development

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
Post Reply
User avatar
danboid
Posts: 1932
Joined: Sun Jun 14, 2020 12:14 am

Using ChatGPT for Uzebox development

Post by danboid »

I've already posted this deep in the IKD thread but I thought it was important enough to create its own thread for.

This is a log of my first ChatGPT session. I wanted it to suggest a way to implement a new feature in my Uzebox game, IKD.

At first I tried to paste the entire main C source code file of my game followed by my question but it was too big to be accepted by ChatGPT at ~950 lines of code so I removed the bloated tank/wall collision code and that made it short enough to be accepted by ChatGPT at ~450 lines. I pasted most of IKD.c, everything except/ up to the tank/wall collision function, into ChatGPT and this is how it went:

-----------------------------------------------------------------

Me: Add a new menu option to this C code to make the bullets bounce off the walls

GPT3: This appears to be a code file written in the C programming language for a game called IKD (presumably an acronym for something). The code appears to define several constants and variables, as well as several functions that are used to initialize and control the game. It looks like the game involves two tanks that can move around and shoot at each other, and the code defines data structures to represent the state of these tanks and their bullets. It also appears that the game includes a main menu, and there are functions defined for rendering and interacting with this menu. Do you have any specific questions about this code?

Me: I would like a new menu option added to make the tanks bullets bounce off the walls

GPT3: To add a new menu option to the main menu that allows the player to toggle whether the tanks' bullets should bounce off the walls, you can try the following steps:

Declare a new global variable that will store the current state of the bounce feature, initialized to false. For example:

bool bulletsBounce = false;

Add a new entry to the menu_opts array that represents the new menu option. You can use the TextOut function to display the string "Bounce" at the appropriate position on the screen. For example:

menu_opts[3] = 27;
TextOut(11, 15, "Bounce");

In the processMainMenu function, add a case to the switch statement that handles the input for the new menu option. When this option is selected, toggle the value of the bulletsBounce variable and update the screen to reflect the new state of the bounce feature. For example:

case 27:
bulletsBounce = !bulletsBounce;
if (bulletsBounce) {
TextOut(11, 15, "Bounce");
} else {
TextOut(11, 15, " ");
}
break;

In the processBullets function, add a check for the value of the bulletsBounce variable before allowing the bullets to collide with the walls. If bulletsBounce is true, you will need to modify the vX and vY components of the bullet's velocity vector to reflect the bounce. One way to do this is to negate the component that is colliding with the wall (for example, if the bullet hits a vertical wall, negate the vX component). You may also want to add some code to reduce the magnitude of the velocity vector slightly after each bounce to simulate friction or air resistance. For example:

if (p1_bullet.x < 0 || p1_bullet.x > 128 ||
p1_bullet.y < 0 || p1_bullet.y > 128) {
if (bulletsBounce) {
if (p1_bullet.x < 0 || p1_bullet.x > 128) {
p1_bullet.vX = -p1_bullet.vX * 0.9;
}
if (p1_bullet.y < 0 || p1_bullet.y > 128) {
p1_bullet.vY = -p1_bullet.vY * 0.9;
}
} else {
p1_bullet.active = false;
}
}

I hope this helps! Let me know if you have any questions or if you need further assistance.

Me: This is a game written in C for the Uzebox games console.

GPT3: I apologize for the oversight. The Uzebox is a small, open source game console that uses an Atmel AVR microcontroller as its main processing unit. It was designed to be simple and easy to program, and it supports a wide range of classic gaming hardware features such as sprites, tilemaps, and sound channels. The code you posted appears to be written in C and makes use of several functions and constants provided by the Uzebox software development kit (SDK). The game appears to be a reimplementation of the tank game from Atari's Combat, with some additional features and mechanics. Do you have any specific questions about the code or the Uzebox platform that I can help with?

Me: IKD is an acronym for I Kill Death

GPT3: I see, thank you for clarifying the acronym. It looks like the game is a two-player tank combat game, where each player controls a tank and tries to destroy the other player's tank by shooting bullets at them. The game appears to have several features such as different maze layouts, a main menu, scorekeeping, and the ability to adjust the angle and velocity of the tanks' bullets. It also looks like there is a bounce feature that allows the bullets to bounce off the walls of the maze, which can be enabled or disabled through the main menu. Is there anything else I can help with?

Me: There is no TextOut function in the Uzebox API. The correct way to print the new menu item would be to use a statement like:

Print(10,26,PSTR("Bounce"));

GPT3: Thank you for pointing out the error in my previous suggestion. You are correct that the TextOut function is not part of the Uzebox API. Instead, you can use the Print function to print strings stored in program memory (flash memory) to the screen. The Print function takes three arguments: the X and Y coordinates of the top-left corner of the text, and a pointer to a null-terminated string stored in program memory. To print the string "Bounce" at position (10, 26) on the screen, you can use a statement like this:

Print(10, 26, PSTR("Bounce"));

Note that the PSTR macro is used to convert the string literal to a pointer to program memory.

I apologize for the mistake in my previous suggestion. I hope this helps! Let me know if you have any other questions or if you need further assistance.

-----------------------------------------------------------------

Whilst I wasn't quite able to copy/paste its suggestions and have them solve my problem, what it suggested was a good outline of the sort of steps you'd take to adding my requested feature and it managed to also add a suggestion that I'd not requested by adding wind velocity. I was impressed with its suggestions, especially as it would seem that I was the first person to ask it to work on a Uzebox game.

I'll have to try it again to see what other suggestions it makes and maybe use it to add comments.
User avatar
danboid
Posts: 1932
Joined: Sun Jun 14, 2020 12:14 am

Re: Using ChatGPT for Uzebox development

Post by danboid »

ChatGPT seems to prefer that you post your code first then your question/task request in the next entry rather than appending your question to the code in the same post.

I've updated the IKD thread with another example of it solving a coding problem for me with some pseudocode. I'm too tired to implent it tonight but I feel confident it will probably work because it seemed to fully understand my request and solve it in a seemingly workable manner.
User avatar
danboid
Posts: 1932
Joined: Sun Jun 14, 2020 12:14 am

Re: Using ChatGPT for Uzebox development

Post by danboid »

Tonight I tried giving ChatGPT the URL of the Uzebox Patch Studio repo then asking it to add JACK support:

Me: Could you please provide a patch to add JACK support to Uzebox Patch Studio?

ChatGPT: I apologize, but I am unable to generate code patches or make modifications to specific software projects. However, I can provide you with general guidance on how to add JACK support to UzeBox Patch Studio.

Hence chatgpt seems to work much better if you copy/paste the relevant section of code you want it to work on into the chat first rather than just giving it a repo address and expecting it to locate the files that need changing. It doesn't seem to do that yet.
Post Reply