In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
With ChatGPT's latest code interpreter, you can make a game in 5 minutes!
This is not nonsense. One blogger has posted a DEMO:
This is a space-based game that allows spacecraft to hit asteroids.
The effect is still very shocking, some netizens praised GPT-4 + code interpreter = ChatGPT-4.5.
It is worth mentioning that the blogger not only showed his achievements, but also kindly gave us tutorials, even prompt told us.
We tried it ourselves right away.
Quick copy, by the way, we tried to copy according to the tutorial, in which prompt is Aunt Sauce's:
Write p5.js code for Asteroids where you control a spaceship with the mouse and shoot asteroids with the left click of the mouse. If your spaceship collides with an asteroid, you lose. If you shoot down all asteroids, you win! I want to use my own textures for the spaceship and for asteroids.
We lost it intact to ChatGPT with the code interpreter turned on, and we quickly got a piece of JS code:
Let spaceship;let spaceshipImg;let asteroids = []; let asteroidImg;let bullets = []; function preload () {spaceshipImg = loadImage ('spaceship.png'); / / replace with your image path asteroidImg = loadImage (' asteroid.png'); / / replace with your image path} function setup () {createCanvas (windowWidth, windowHeight); spaceship = new Spaceship (); for (let I = 0; I
< 10; i++){ asteroids.push(new Asteroid()); }}function draw() { background(0); spaceship.show(); spaceship.move(); for(let i = bullets.length-1; i >= 0; iMuz -) {bullets [I] .show (); bullets [I] .move (); for (let j = asteroids.length-1; j > = 0; jmurm -) {if (bullets [I] .hits (asteroids [j])) {if (asteroids [j] .r > 10) {let newAsteroids = asteroids [j] .breakup (); asteroids = asteroids.concat (newAsteroids) } asteroids.splice (j, 1); bullets.splice (I, 1); break;}} for (let asteroid of asteroids) {asteroid.show (); asteroid.move (); if (asteroid.hits (spaceship)) {alert ("Game Over"); noLoop ();} if (asteroids.length = 0) {alert ("You Won!") NoLoop ();}} function mousePressed () {if (mouseButton = LEFT) {bullets.push (new Bullet (spaceship.pos, spaceship.heading));}} following the author's tutorial, we copied this code to an online compilation platform.
Among them, there are pictures of spaceships and asteroids that need to be prepared by ourselves. After we upload them, run!
Hey, how did something go wrong?
Don't panic, we copied the error message directly to ChatGPT, and soon got the correction plan:
Class Spaceship {constructor () {this.pos = createVector (width / 2, height / 2); this.r = 50; this.heading = 0; this.rotation = 0;} show () {push (); translate (this.pos.x, this.pos.y); rotate (this.heading + PI / 2); image (spaceshipImg, 0,0, this.r, this.r); pop () } move () {this.pos = createVector (mouseX, mouseY);}} class Bullet {constructor (shipPos, angle) {this.pos = createVector (shipPos.x, shipPos.y); this.vel = p5.Vector.fromAngle (angle); this.vel.mult (5);} show () {push (); stroke (255); strokeWeight (4); point (this.pos.x, this.pos.y); pop () } move () {this.pos.add (this.vel);} hits (asteroid) {let d = dist (this.pos.x, this.pos.y, asteroid.pos.x, asteroid.pos.y); return d < asteroid.r;}} class Asteroid {constructor (pos, r) {if (pos) {this.pos = pos.copy ();} else {this.pos = createVector (random (width), random (height)) } if (r) {this.r = r * 0.5;} else {this.r = random (15,50);} this.vel = p5.Vector.random2D ();} show () {push (); image (asteroidImg, this.pos.x, this.pos.y, this.r * 2, this.r * 2); pop ();} move () {this.pos.add (this.vel) } hits (ship) {let d = dist (this.pos.x, this.pos.y, ship.pos.x, ship.pos.y); return d < this.r + ship.r;} breakup () {return [new Asteroid (this.pos, this.r), new Asteroid (this.pos, this.r)];}} it turns out that ChatGPT has forgotten the functions related to the output components.
After the supplement, it will be fine. Although it is different from DEMO, it is playable, and it takes less than five minutes.
(in DEMO, the position of the spaceship is fixed and the direction can be turned, and the game we reproduce is just the opposite.)
But we are not satisfied with this, so we then try to get ChatGPT to add some features to us.
These steps are not specifically designed for prompt, but are described directly in natural language, and the results are good.
Here we will not show the code and prompt step by step. At the end of the article, we will share the chat notes with ChatGPT during the whole production process.
The first is to increase the scoring and timing mechanism:
More careful readers may see that asteroids of different sizes have the same score.
So we asked ChatGPT to set different scores for asteroids of different sizes.
Also, the asteroid here will not come back after flying out of the picture, so we have also repaired the bug.
Does it already smell like that? But the ship doesn't seem to turn, so let's solve this problem next:
Finally, we added the pause function (controlled by the spacebar), and the game is finally done.
Gluttonous snakes and don't step on the white box can do tutorials that emulate this blogger. Let's try to get ChatGPT to do some other games.
For example, gluttonous snake, in addition to the surrounding walls are later separately required to be displayed, the other direct step in place!
But we asked for the food to be drawn in a circle, and ChatGPT gave it a square, but it didn't hurt.
I don't know if the game of Snake is so classic that ChatGPT knows what to do when he sees the name.
So we tried again, not giving the name of the game, but only describing the way to play, to see how ChatGPT performed.
What we have to do this time is "Don't step on the white box". We described the way to play, and it turned out that except for the slow speed, everything else was very good.
The above is the full evaluation of the game of the code interpreter, if you have any new ideas, welcome to leave a message in the comments area!
Reference link:
Https://twitter.com/icreatelife/status/1678184683702566922
Manufacturing process
Asteroids:
Https://chat.openai.com/share/7fdc27a1-4a64-4c2f-a27d-c62f31a8af97
Gluttonous snake:
Https://chat.openai.com/share/c67ca1c8-8a9e-41a1-bd0d-40970b52104c
Don't step on the white block:
Https://chat.openai.com/share/639e957d-66bd-41bb-9676-1c9890629d49
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 211
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.