成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

實(shí)測ChatGPT超強(qiáng)插件:0經(jīng)驗(yàn)5分鐘開發(fā)游戲

人工智能 新聞
用ChatGPT最新推出的代碼解釋器,5分鐘就能做出一款游戲!

本文經(jīng)AI新媒體量子位(公眾號ID:QbitAI)授權(quán)轉(zhuǎn)載,轉(zhuǎn)載請聯(lián)系出處。

這可不是亂說的,有位博主已經(jīng)放出了一段DEMO:

圖片圖片

這是一款以太空為背景,讓飛船打擊小行星的游戲。

效果還是很震撼的,有網(wǎng)友看完大贊 GPT-4+代碼解釋器=ChatGPT-4.5。

圖片圖片

值得一提的是,這位博主不僅展示了自己的成果,還貼心地給出了教程,連prompt都告訴我們了。

圖片圖片

我們立馬親自上手試了一下~

火速復(fù)刻,順便升級了一下

我們嘗試著根據(jù)教程進(jìn)行復(fù)刻,其中的prompt是醬嬸兒的:

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.

我們原封不動地輸給開啟了代碼解釋器的ChatGPT,很快就得到了一段JS代碼:

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; i--){
    bullets[i].show();
    bullets[i].move();

    for(let j = asteroids.length-1; j >= 0; j--){
      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));
  }
}

按照作者的教程,我們將這段代碼復(fù)制到一個在線編譯平臺上。

其中還有飛船和小行星的圖片是需要自行準(zhǔn)備的,我們上傳好之后,運(yùn)行!

咦,怎么出錯了?

圖片圖片

不慌,我們直接把報錯信息復(fù)制給ChatGPT,很快就得到了修正方案:

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)
    ];
  }
}

原來是丟三落四的ChatGPT忘記輸出元件相關(guān)的函數(shù)了。

補(bǔ)充上之后就好了,結(jié)果雖然和DEMO有些區(qū)別,但也是可玩的,用時的確不到五分鐘。

(DEMO中飛船位置固定,方向可轉(zhuǎn),我們復(fù)刻出的游戲正好相反)

圖片圖片

但我們并不滿足于此,于是接下來又試著讓ChatGPT給我們增加一些功能。

這些步驟中我們沒有專門設(shè)計(jì)prompt,而是直接用自然語言來描述,結(jié)果也很好。

這里我們就不逐步展示代碼和prompt了,文末分享了整個制作過程中和ChatGPT的聊天記錄

首先是增加計(jì)分和計(jì)時機(jī)制:

圖片圖片

細(xì)心一些的讀者可能會看到,這里不同大小的小行星得分是相同的。

于是我們要求ChatGPT為不同大小的小行星設(shè)置不同的分?jǐn)?shù)。

而且,這里的小行星飛出畫面之后就不回來了,我們也修復(fù)了一下這個bug。

圖片圖片

是不是已經(jīng)有那味了?但是這個飛船好像不會轉(zhuǎn)向,我們接下來就解決這個問題:

圖片圖片

最后,我們又加入了暫停功能(由空格鍵控制),至此,這款游戲終于大功告成了。

圖片圖片

貪吃蛇、別踩白塊都能做

仿照這位博主的教程,我們試著讓ChatGPT做些其他游戲出來。

比如貪吃蛇,除了四周的墻壁是后來單獨(dú)要求顯示出來之外,其他直接一步到位!

不過我們要求把食物畫成圓形,ChatGPT給出的是方形的,但也無傷大雅。

圖片圖片

不知道是不是貪吃蛇這個游戲太過經(jīng)典,導(dǎo)致ChatGPT看到名字就知道該怎么做了。

所以我們又試了一下,不給出游戲的名字,只描述玩法,看看ChatGPT的表現(xiàn)如何。

這次要做的是“別踩白塊”,我們把玩法描述了一番,結(jié)果除了速度有些慢,其他地方都非常不錯。

圖片

以上就是對代碼解釋器做游戲的全部測評了,如果你還有什么新的想法,歡迎評論區(qū)留言!

參考鏈接:https://twitter.com/icreatelife/status/1678184683702566922

制作過程
小行星:https://chat.openai.com/share/7fdc27a1-4a64-4c2f-a27d-c62f31a8af97貪吃蛇:
https://chat.openai.com/share/c67ca1c8-8a9e-41a1-bd0d-40970b52104c
別踩白塊:
https://chat.openai.com/share/639e957d-66bd-41bb-9676-1c9890629d49

責(zé)任編輯:張燕妮 來源: 量子位
相關(guān)推薦

2012-06-28 10:26:51

Silverlight

2021-04-30 16:23:58

WebRTC實(shí)時音頻

2011-07-11 09:58:52

2023-03-02 09:35:55

chatGPTOpenAI編程

2023-02-08 09:11:06

2023-02-16 08:26:41

2023-07-19 17:19:37

2020-09-14 11:30:26

HTTP3運(yùn)維互聯(lián)網(wǎng)

2021-01-29 11:43:53

SSHLinux命令

2020-10-30 15:04:16

開發(fā)技能代碼

2022-09-30 15:46:26

Babel編譯器插件

2010-11-03 11:01:05

求職面試

2020-11-23 16:23:59

CSS設(shè)計(jì)技術(shù)

2020-12-17 10:00:16

Python協(xié)程線程

2021-03-12 09:45:00

Python關(guān)聯(lián)規(guī)則算法

2009-11-26 11:19:52

NIS服務(wù)器

2021-01-29 11:25:57

Python爬山算法函數(shù)優(yōu)化

2020-12-07 11:23:32

Scrapy爬蟲Python

2020-05-15 07:30:08

黑客Thunderbolt漏洞

2021-03-23 15:35:36

Adam優(yōu)化語言
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产精品美女在线观看 | av先锋资源| 久久久久久久久蜜桃 | 亚洲精彩免费视频 | 成人福利视频 | 成在线人视频免费视频 | 国产最好的av国产大片 | 五月天国产视频 | 成人免费视屏 | 999久久久精品 | 久久成人精品视频 | 国产精品久久国产精品 | 久久在看 | 自拍偷拍亚洲欧美 | 91精品久久久久久久久久入口 | www.成人在线视频 | 国产2区 | www精品美女久久久tv | 波多野结衣中文视频 | www成人免费视频 | 国产一级片 | 精品香蕉一区二区三区 | 真人毛片 | 天天爽夜夜爽精品视频婷婷 | 国产做a爱片久久毛片 | 人人干人人超 | 亚洲精品二区 | 精品国产乱码久久久久久蜜退臀 | 91精品国产91久久综合桃花 | 亚洲顶级毛片 | 国产成人精品免费视频大全最热 | 精品少妇v888av | 一区二区在线 | 久久夜视频 | 国产91在线播放 | 一区二区手机在线 | 成人精品啪啪欧美成 | 麻豆久久久9性大片 | 国产aⅴ | 欧美日韩精品中文字幕 | av在线成人 |