Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

let image1; let image2; let image3; let image4; let overlayImage; let currentImageIndex…

  1. User

    let image1; let image2; let image3; let image4; let overlayImage; let currentImageIndex = 0; let falling = false; let broken = false; let overlayY = 0; let oriPostionX=0; let oriPostionY=0;

    let px= 0; let py =0; let smashSound; let mic;

    function preload() { // 加载图片 image1 = loadImage('loudao.jpg'); //楼道 image2 = loadImage('fangjian4.jpg');//第四个房间 image3 = loadImage('datu4.jpg'); // 放大的窗户 pingzi = loadImage('pingzi.png'); // 瓶子的图片 image4 = loadImage('kaichuang.jpg'); smashSound = loadSound('glass_smash.mp3');

    oriPostionX=windowWidth/2 +200; oriPostionY=windowHeight/2 +100; px=oriPostionX; py=oriPostionY;//这里是原先的位置,<<<<< acc=0; }

    function setup() { createCanvas(windowWidth,windowHeight); mic = new p5.AudioIn(); mic.start(); }

    function draw() {

    // 根据当前图片索引绘制对应的图像 if (currentImageIndex === 0) { background(0); imageMode(CENTER); image(image1, windowWidth/2, windowHeight/2); imageMode(CORNER);

    } else if (currentImageIndex === 1) { background(10, 24, 37); imageMode(CENTER); image(image2, windowWidth/2, windowHeight/2); imageMode(CORNER); } else if(currentImageIndex == 2){ // 在画面中心绘制第三张图片,并将尺寸扩大1.5倍 background(10, 24, 37); imageMode(CENTER); image(image3, windowWidth/2, windowHeight/2); imageMode(CORNER); }

    if(currentImageIndex ==2 && falling) {
      
      imageMode(CENTER);
      if(broken==false){
        image(pingzi,px,py);
        py+=acc*0.1;
        acc++;    //<<<<acc代表加速度
        if(abs(py-windowHeight*7/8)<20){ //<<<<<<<<<<<<当py的坐标临近窗口高度7/8的时候触发事件
          smashSound.play();
          broken = true;
        }
      }else{
        image(pingzi,px,py);
      }
    
    imageMode(CORNER);
    

    } }

    function keyPressed() { if (key === 'd' || key === 'D') { currentImageIndex = (currentImageIndex + 1) % 3; // 切换图片索引

    if(broken){
      falling=false;
      broken=false;
      px=oriPostionX;
      py=oriPostionY;//这里是原先的位置,<<<<<
      acc=0;
    
    }
    

    } if (key === 'q' || key === 'Q') { falling = true; } }

    function windowResized() { resizeCanvas(windowWidth, windowHeight); } // 在打碎玻璃后,播放照片image4 function mouseClicked() { mic.getLevel(function(level) { console.log(level); if (level > 0.3) { // 判断声音强度,如果大于0.3就播放第四张图片 imageMode(CENTER); background(255); image(image4,windowWidth/2, windowHeight/2); imageMode(CORNER); smashSound.stop(); } }); }将后面的能够播放照片image4的条件改为检测到外部声音达到40分贝

  2. Assistant

    function mouseClicked() { mic.getLevel(1, function(level) { // 第二个参数传入1表示只返回一个数值,即当前声音强度的平均值 console.log(level); if (level > 0.05) { // 将条件改为声音强度大于0.05 imageMode(CENTER); background(255); image(image4,windowWidth/2, windowHeight/2); imageMode(CORNER); smashSound.stop(); } }); }

  3. User

    let image1; let image2; let image3; let image4; let overlayImage; let currentImageIndex = 0; let falling = false; let broken = false; let overlayY = 0; let oriPostionX=0; let oriPostionY=0;

    let px= 0; let py =0; let smashSound; let mic;

    function preload() { // 加载图片 image1 = loadImage('loudao.jpg'); //楼道 image2 = loadImage('fangjian4.jpg');//第四个房间 image3 = loadImage('datu4.jpg'); // 放大的窗户 pingzi = loadImage('pingzi.png'); // 瓶子的图片 image4 = loadImage('kaichuang.jpg'); smashSound = loadSound('glass_smash.mp3');

    oriPostionX=windowWidth/2 +200; oriPostionY=windowHeight/2 +100; px=oriPostionX; py=oriPostionY;//这里是原先的位置,<<<<< acc=0; }

    function setup() { createCanvas(windowWidth,windowHeight); mic = new p5.AudioIn(); mic.start(); }

    function draw() {

    // 根据当前图片索引绘制对应的图像 if (currentImageIndex === 0) { background(0); imageMode(CENTER); image(image1, windowWidth/2, windowHeight/2); imageMode(CORNER);

    } else if (currentImageIndex === 1) { background(10, 24, 37); imageMode(CENTER); image(image2, windowWidth/2, windowHeight/2); imageMode(CORNER); } else if(currentImageIndex == 2){ // 在画面中心绘制第三张图片,并将尺寸扩大1.5倍 background(10, 24, 37); imageMode(CENTER); image(image3, windowWidth/2, windowHeight/2); imageMode(CORNER); }

    if(currentImageIndex ==2 && falling) {
      
      imageMode(CENTER);
      if(broken==false){
        image(pingzi,px,py);
        py+=acc*0.1;
        acc++;    //<<<<acc代表加速度
        if(abs(py-windowHeight*7/8)<20){ //<<<<<<<<<<<<当py的坐标临近窗口高度7/8的时候触发事件
          smashSound.play();
          broken = true;
        }
      }else{
        image(pingzi,px,py);
      }
    
    imageMode(CORNER);
    

    } }

    function keyPressed() { if (key === 'd' || key === 'D') { currentImageIndex = (currentImageIndex + 1) % 3; // 切换图片索引

    if(broken){
      falling=false;
      broken=false;
      px=oriPostionX;
      py=oriPostionY;//这里是原先的位置,<<<<<
      acc=0;
    
    }
    

    } if (key === 'q' || key === 'Q') { falling = true; } }

    function windowResized() { resizeCanvas(windowWidth, windowHeight); } // 在打碎玻璃后,播放照片image4 function mouseClicked() { mic.getLevel(function(level) { console.log(level); if (level > 0.05) { // 判断声音强度,如果大于0.05就播放第四张图片 imageMode(CENTER); background(255); image(image4,windowWidth/2, windowHeight/2); imageMode(CORNER); smashSound.stop(); } }); }帮我修改完善代码

  4. Assistant

    你的代码已经比较完善了,不过我还是看到了一些需要改进的地方,具体见下:

    let image1;
    let image2;
    let image3;
    let image4;
    let overlayImage;
    let currentImageIndex = 0;
    let falling = false;
    let broken = false;
    let overlayY = 0;
    let oriPostionX = 0;
    let oriPostionY = 0;
    
    let pingzi;
    let px = 0;
    let py = 0;
    let acc = 0;
    let smashSound;
    let mic;
    
    function preload() {
      image1 = loadImage('loudao.jpg');
      image2 = loadImage('fangjian4.jpg');
      image3 = loadImage('datu4.jpg');
      pingzi = loadImage('pingzi.png');
      image4 = loadImage('kaichuang.jpg');
      smashSound = loadSound('glass_smash.mp3');
    
      // 声音文件需要先加载
      soundFormats('mp3', 'ogg');
      smashSound = loadSound('assets/glass_smash.mp3');
    }
    
    function setup() {
      createCanvas(windowWidth, windowHeight);
      mic = new p5.AudioIn();
      mic.start();
    }
    
    function draw() {
      // 画面按照索引值显示不同的图片
      if (currentImageIndex === 0) {
        background(0);
        imageMode(CENTER);
        image(image1, windowWidth / 2, windowHeight / 2);
        imageMode(CORNER);
      } else if (currentImageIndex === 1) {
        background(10, 24, 37);
        imageMode(CENTER);
        image(image2, windowWidth / 2, windowHeight / 2);
        imageMode(CORNER);
      } else if (currentImageIndex == 2) {
        background(10, 24, 37);
        imageMode(CENTER);
        image(image3, windowWidth / 2, windowHeight / 2);
        imageMode(CORNER);
      }
    
      if (currentImageIndex == 2 && falling) { 
        // image3是窗户
        imageMode(CENTER);
        if (broken == false) {
          // 绘制瓶子
          image(pingzi, px, py);
          py += acc * 0.1;
          acc++; // 加速度增加一定值
    
          // 如果瓶子坠落到窗户下部,播放声音并且标记为碎掉状态
          if (abs(py - windowHeight * 7 / 8) < 20) {
            smashSound.play();
            broken = true;
          }
        } else {
          // 碎掉的瓶子可以一直绘制在窗户下面
          image(pingzi, px, py);
        }
        imageMode(CORNER);
      }
    }
    
    function keyPressed() {
      if (key === 'd' || key === 'D') {
        // 切换索引值用来控制显示不同的图片
        currentImageIndex = (currentImageIndex + 1) % 3;
    
        // 重置瓶子状态
        if (broken) {
          falling = false;
          broken = false;
          px = oriPostionX;
          py = oriPostionY;
          acc = 0;
        }
      } else if (key === 'q' || key === 'Q') {
        // 按下“q”键开始让瓶子往下掉
        falling = true;
      }
    }
    
    function windowResized() {
      resizeCanvas(windowWidth, windowHeight);
    }
    
    function mouseClicked() {
      mic.getLevel(1, function(level) {
        console.log(level);
        // 当声音大于0.05时播放一个声音
        if (level > 0.05) {
          imageMode(CENTER);
          background(255);
          image(image4, windowWidth / 2, windowHeight / 2);
          imageMode(CORNER);
          smashSound.stop();
        }
      });
    }
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.