How I Used ChatGPT to Make a Game from Scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
During the holidays I finally had some time  to try out ChatGPT and see for myself what   would be the cause of my future unemployment.  After I got my answers to the meaning of life,   when Half-Life 3 will be released, and if this  project would keep me safe from Rocco's basilisk,   I thought to myself: "What is it that I've been  unable to do for the past four years? That's   right finish a video game project." Since  video games are notoriously complex pieces   of software to create, I thought it would be an  interesting proving ground for ChatGPT. Oh yeah,   and we are not using one of these engines  to do the heavy lifting for ChatGPT,   no no no no no. We will be sticking to  plain old C++. So let's get started! [Weeeeeeeee]   Okay... not quite what I had in mind. That's  more like it. Surprisingly it only took me a   few hours to copy paste this together,  and most of the time was me waiting for   ChatGPT's answers or figuring out ways  to get around the character limitation. First up, let's ask ChatGPT to open a window  and render a Sprite to our screen. Immediately   it starts blurting out code. It Imports  SDL, a popular cross-platform library for   access to low-level hardware APIs, and  proceeds to initialize the window and   set up a texture for our sprite. I have  prepared a C++ project and set up cmake   to import all necessary dependencies. Let's  copy the code and see if it actually works.   And after running the code, we actually see  that it opens a window. That's great. But it   doesn't render the sprite yet. I also prepared  some assets for our game and the sprite for   our player is called player.png. It's a little  spaceship. However the file that ChatGPT tried   to load was sprite.bmp. So it's no wonder it  didn't work. Let's tell it to load our file   instead. It quickly provides us an answer and  after trying the code we get another error.   And this one is related to the path the image is  actually located in. Since we are trying to load   it from a Mac OS binary, we need to provide a  full path to the file. Let's just ask ChatGPT   for a solution. And it immediately shows us  how to do that and after copying the solution   we see that it actually renders the sprite now  on the screen, yay. Next I wanted to know how to   get the actual dimensions of the image to set the  height and the width of the texture appropriately.   And... it works. We can actually see  the sprite now in its full glory.   I also changed the dimensions of the  screen to make our screen a little bigger.   This next question got me really excited. I asked  ChatGPT to create an entity component system,   which is a popular and often used software  architecture pattern in video games. And it did   just that. The code it provided was simple and not  over engineered, so I decided we could make use of   it directly. I asked it if it could integrate  that answer with our previous window code and   also add input handling while we are at it. And  wow, not only did it understand to combine our   two pieces of software, but it also added an input  component to get user input. At this point I was   really hooked and wanted to see if the code really  works. And it worked! We can now move our player   across the screen using the arrow keys. Next I  wanted to do some code refactoring, so I asked it   to create render component and the render system  to handle the rendering of sprites on the screen. And after copying over the changes  we see that everything still works. I also wanted to change the way that systems  get references to the components and instead   of passing it in the update function just  keep a reference in their structs. And now   something interesting happened. While doing the  refactoring ChatGPT also simplified the code.   And by doing that it actually introduced the bug.  I told it that it had made a mistake and if it   could please fix that mistake. And after trying  the fix we were back to normal. Pretty cool.   Next I asked her to implement delta timing for  our movement system which is used to achieve frame   rate independent rendering. Basically it means  that if our game runs on a really fast computer   we don't want our player to become really fast  as well. I had to add a speed component to our   position update since we now only move our player  a tiny fraction every frame. Now we come to one   of the most important parts of almost any game  which is the AI. ChatGPT gave me an overview over   the different techniques that are usually used to  create AI in video games. I decided to go with the   state machine and asked it to create an AI system  and an AI component that supports that. However   the answer it provided seemed over engineered  for the purposes of our small game. I asked to   create something less complex and just told it the  rules that I wanted the AI to have instead. I told   it that I want the enemy to follow the player  around on the screen until it reaches a certain   threshold. It quickly came up with a solution so  I started integrating it into our current code.   After pulling everything together we had  a small enemy on the screen. The code was   still a little buggy but it took no time  to fix it. And now we had an AI that was   chasing the player around the screen. A great  starting point. What would a space shooter be   without laser guns? So I asked ChatGPT to spawn  projectiles once the AI is in range of the player.   ChatGPT quickly updated the AI system to provide  the necessary functionality and it also suggested   to create a projectile system and a projectile  component. And while it created a projectile   system and a projectile component to store the  necessary information of the projectiles we still   didn't have a way to render the projectiles on  the screen. So that's what I asked it to do next. Whoops. Not kind of what I've expected but funny   nonetheless. Let's ask it to add  an attack cooldown for the AI. And the logic it provided in its answer actually  created an attack cooldown for our enemy. That's   cool. Now I wanted to mix up the player controls  a little. Instead of the left and right arrow keys   moving our player left and right on the  screen, I wanted to introduce a rotation   component that rotates our Sprite depending on  the input. And well it actually works kind of.   But we forgot that now we also have to change the  way that we calculate our velocity vector. So I   asked ChatGPT how to change our velocity based  on the direction that we are currently facing.   And now if we change the rotation of our sprite  it also changes our flying direction, great.   Conversely we want to set the rotation of our  enemy sprite depending on where the enemy is   facing. And the enemy is always facing towards the  player so that should be very easy to calculate.   Well apparently not as easy as I  expected but that was actually a   mistake that I made where I switched up the X  and Y components in the arc tangent function.   And after eliminating the human error everything  seemed to work fine. Next I asked ChatGPT to also   create a shooting system for the player  since we also want to shoot at the enemy. And our shooting system works but it has  similar issues to what we've seen previously.   Now the issue here is that we are detecting  our key down event for our shoot key which   is the space bar in every frame. And we are  also reacting to that event for every frame.   So what I usually would do in such a case is  I would set up a flag in our input component   to check if our shoot key has been handled or  not. But let's see what ChatGPT comes up with.   And the solution that ChatGPT comes up with is  actually the same that we would have expected:   Additionally to the spacebar flag it sets up  a spacebar pressed flag that gets reset every   time we spawn a new projectile in our shooting  system. And if we run the game now we see that   even if we press down the space bar it only spawns  one projectile at a time which is exactly what we   wanted. So to have any meaning for our projectiles  we should probably create health component. So   that's what I asked ChatGPT to do next/ I also  ask it to do the collision handling between our   projectiles and our sprites and reduce the health  of the entity that it collides with accordingly.   After integrating the new codes we can see  that now the projectiles disappear when   they hit an entity and yeah we must assume  for now that the health also gets reduced.   So as the next question for ChatGPT I ask it to  actually help me render a health bar so that we   can see the health values of our entities on our  screen. And after a little back and forth, because   I also wanted to render a background of the health  bar to just make it look a little nicer, we can   see that our previous code actually works and the  projectiles reduce the health of our entities and   the health bar also gets updated accordingly.  Pretty cool. Now I want to render some text on   the screen once our player's or enemy's health has  reached the value of 0. For that ChatGPT suggests   to import the true type font library of SDL. It's  pretty straightforward to set up. I also add a new   component to render the text and I add some input  handling to replay the game once the text appears   on the screen. So I would say we have the basic  game mechanics now finished for our small game   and the last big part that is missing  is sound effects. We know the drill now:   We ask ChatGPT how to load sound and it tells  us to use the STL mixer Library. Pretty neat. And that concludes our little project. I added  some more sounds and did a little cleanup and   I'm pretty satisfied with the result. When I  first heard about ChatGPT and the end of software   engineers, I was pretty skeptical. I foolishly  believed it would still take decades to have   a real impact on the industry. I was obviously  wrong. OpenAI has granted us an early view into   the future. Considering all I have seen in the  past few days it seems inevitable that the job   of the software engineer is about to go through  a tectonic shift. We have already reached a point   where machines are more skilled in designing  software than humans are. I suspect that within   a year most software engineers will be using  an AI assistant similar to ChatGPT and the ones   that won't will pretty much be left behind. The  only thing that ChatGPT currently lacks is user   interface and user experience but the technology  is already there. And things will not stop there.   We will create new programming languages that  are not aimed to program CPUs and GPUs but neural   network powered AIs instead. In the next years we  will see tools that combine several AI systems to   work on different subsets of software systems. We  humans will not generate code anymore and not even   do the system design. We will merely steer the AI  systems in the direction and supervise their work.   If you're interested in these topics I recommend  you to watch Lex Friedman's interview with Andrej   Karpathy who led the computer vision department  of Tesla for several years. Pretty exciting stuff.   What do you think? Let me know in the  comments. And if you think this was an   interesting video and you would like  to see more, leave a like. Thanks!
Info
Channel: prjohdev
Views: 29,401
Rating: undefined out of 5
Keywords: chatgpt, c++, game, i let chatgpt make a game, i let ai make a game, i made a game with chatgpt, i let ai make this game, i made a game in a week, making a game with chatgpt, chat gpt code generator, i made a game in 24 hours, making a game with ai, chatgpt game development, i made a game, ai made this game, making a game, indie game developer, indie game dev, indie game, chatgpt code, game jam devlog, chat gpt, How I Used ChatGPT to Make a Game from Scratch, prjohdev, prjoh_dev
Id: r3oCTbiEV6Q
Channel Id: undefined
Length: 12min 32sec (752 seconds)
Published: Fri Dec 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.