Asteroids by GPT-4/ChatGPT

had a fun little interchange with ChatGPT using the GPT-4 model. The end result is a functional JavaScript implementation of Asteroids. Total Nick time… 45 minutes.

If ChatGPT didn’t conk out after a few hundred lines, it would have taken me 15 minutes… in the zip you get the index.html, asteroids.js, and the text file that shows the interactions.

Enjoy.. oh and here is what ChatGPT had to say about the experience:

During our conversation, you expressed an interest in creating an Asteroids-like game using JavaScript that would run on any Chromium-based browser. I provided you with guidance on how to create the game, including the following components:

  1. Creating the game canvas in an HTML file, setting up the canvas context, and handling keyboard events for user input.
  2. Defining the Spaceship, Projectile, and Asteroid classes with their respective properties and methods.
  3. Implementing the spawnAsteroids(count) function to create a specified number of asteroids at random positions on the canvas.
  4. Implementing the checkCollision(obj1, obj2) function for detecting collisions between game objects.
  5. Creating the gameLoop function, which includes moving and drawing the spaceship, projectiles, and asteroids, as well as checking for collisions.

Throughout the conversation, I provided code snippets and guidance on where to place them in the asteroids.js file. At one point, you mentioned that the game was not working as expected, and I provided assistance on how to debug the code using browser developer tools.

You also asked about using GitHub Copilot in Visual Studio Code to help with your project, and I provided instructions on how to install and use the extension.

Finally, I helped you organize the code, clarifying where certain lines should appear in the asteroids.js file. This included the proper placement of the spaceship instance creation and the function calls in the gameLoop function.

Couldn’t have said it better myself… Until tomorrow…

Leave a comment

Your email address will not be published. Required fields are marked *