Can AI Code Flappy Bird? Watch ChatGPT Try

I wanted to know if ChatGPT could make a video game, so I asked it to make Flappy Bird for me. But we’re gonna have one rule: I’m not gonna write a single line of code. Any code that we use is going to be written by ChatGPT. I’m just going to copy-paste it over. This could go very wrong.

I wrote a brief description of all the components that go into Flappy Bird. Real quick, it spit out a six-step plan to make Flappy Bird in the Unity game engine. So, following the instructions for steps one and two, we’re gonna set up an empty game project and add our art for the background and the bird, which brings us to step three.

Step three is to write a script to give life to the bird so it can flap its wings while flying to the right. But we’re not going to write the script, ChatGPT is. We’re just going to copy-paste the script over.

It works, but there’s a problem—the bird is flying off the screen. So, we’re gonna ask ChatGPT to fix that and write us some code to have a camera follow the bird as it moves to the right. But you may have noticed that the bird is flying off the background. That was a mistake I made setting up the background in the first place, so I’m going to chalk that one up to human error. My bad. With a quick adjustment, we now have a script working great.

At this point, I realized we don’t want the game to start right away when the game loads. We have to wait for the player to click at least once to flap their wings before the bird starts moving. Otherwise, you go barreling into the ground as soon as the game starts. As per our main rule, I had ChatGPT write all of the code to delay movement until the player had flapped their wings for the first time. And success! The game now waits until the first click, and then you can flap, flap, flap your heart away.

Have you been wondering where the art we’ve been using came from? Since ChatGPT is writing all of the code? Well, if you haven’t guessed already, the art is generated by AI as well. I fed rough block-out sketches into Mid-Journey and had it fill in the details for the background environment, the bird, and the pipe ops. This brings us to step number four.

Things are going to get really interesting in Step 4. Obstacle pipes are going to start appearing. ChatGPT has given us instructions to hook up the physics for the pipe, which will cause the bird to collide with the pipe, which is how the game’s going to end. But as I was reading the instructions ChatGPT had provided, this line caught my eye. ChatGPT was planning to create the obstacles off to the right of the screen. That seems fine, but then it proposed moving the pipes left at a constant speed. I can see why it suggested that since the pipes do appear to move to the left when you’re playing. You see, the bird and camera are already moving to the right, so the pipe should actually remain stationary and allow the bird to fly up to them. I pointed this out to ChatGPT, and ChatGPT agreed. “You’re right,” it said, and it proceeded to correct itself. I copy-pasted the code back in, and now it works great, except…

Wait, wait, what’s going on? The bird’s flipping around like, uh, like some kind of cuckoo bird. This is the first curveball that I’m gonna throw at ChatGPT because this was not part of the original design specification. We’re going to ask it to rotate the bird based on whether the bird is moving up or down. Without any hesitation, ChatGPT said, “Sure, you want the bird to tilt up and down? You got it,” and it gave me the code to do so. And now we’ve got this awesome little bird that tilts up and down based on the direction it’s moving, rather than spinning around like a pinwheel. And that brings us on to step number five.

To implement game over and scoring conditions. What I really like about this process is that while ChatGPT is taking care of the code, I get to focus my attention on design work. I get to position text elements on the screen, decide the distance between the pipes, or the exact tuning numbers for how hard the bird flaps its wings. So now we have scoring working, but if you’ll notice, the points are actually incrementing before I get to the pipe. That seems wrong. I actually want the score to increment when the player passes through the gap in the pipes. So we’re going to ask ChatGPT to adjust the code to give us more control over the exact moment in time that the point is awarded to the player.

The player now gets points when they actually pass through the pipe. At this point, I realized that we’re missing a ground for the game. The ground in Flappy Bird is really helpful to provide that constant sense of forward movement. Other than the pipes, the ground was not part of the original specification, but I said, “Nope, we’re gonna need it.” I let ChatGPT know that we’re going to be adding a ground to the game, and it gave me step-by-step directions for how to set up a never-ending ground the bird would be able to crash into. And now we have an infinitely long ground along the bottom of the screen, reinforcing that sense of forward movement.

And then move on to step six, which is to have a game over screen come up when the player makes a collision with the pipe or with the ground. Our coding assistant ChatGPT didn’t hesitate to provide us with detailed instructions, as well as all of the code to set up the game over screen. Once again, I was able to focus on the design elements, like deciding what font size and color to use, the sizing of the buttons, and then paste the code that ChatGPT had provided me to make the whole thing work.

And now we have a proper game over screen. But wait, there’s one problem. After the game over screen pops up, the player input is still being received, which means the bird can jump up after it has fallen to the ground. That’s kind of ridiculous. So, I told ChatGPT that when the game over screen pops up, we need to stop the camera and stop movement so that the player shouldn’t be able to control the bird anymore.

But here’s another mistake ChatGPT made. There was a simple coding error, and the game wouldn’t run at all. I just told ChatGPT that the error existed to see what it would do. Polite as always, it apologized for the error and provided the correction. After following its instructions, we now disable player input when the game over screen is reached.

Now, this is where we’re going to get to our second curveball. We’re going to add a high score system. Let’s see how well ChatGPT adjusts to this brand new request. After we had basically finished all six steps of the original plan, I copy-pasted all the code it had provided me. But watch what happens when I run the game with the new high score code enabled. I scored two points on this Flappy Bird run, but my high score was only listed as zero. ChatGPT wrote all this complicated logic with a simple error. I told ChatGPT I thought the problem was with the add score function, and it replied, “You’re right.” It’s almost like we’re working together. We now have a high score system that works. On this round, I got a high score of nine, and the score is retained between rounds.

So, could somebody with no coding knowledge use ChatGPT to make a game? Probably not yet, but we’re getting there. I’m definitely going to repeat this exercise with more complicated game types on future AI models. So, I hope you’ll join me for that. In the meantime, happy gaming-making!

Privacy Policy | Privacy Policy