Interface 26

PHOTO EMBED

Sun Jan 07 2024 18:37:13 GMT+0000 (Coordinated Universal Time)

Saved by @马丽

void draw() {
  background(220); // Set background color
  
  if (gameStarted) {
    // Display the circle based on the selected color
    fill(circleFillColor);
    ellipse(width / 2, height / 2, 100, 100); // Display a circle at the center of the window
  }
  
  // Display score and missed colors
  textAlign(CENTER);
  displayInfo1();
  displayInfo2();
  displayInstructions(); // Display game instructions
  
  // Check for game over condition
  if (missedColors >= 3) {
    gameOver();
  }
  
  // Read data from the serial port
  while (myPort.available() > 0) {
    String wasteType = myPort.readStringUntil('\n'); // Read data from serial port
    if (wasteType != null) {
      wasteType = wasteType.trim(); // Remove whitespace
      
      // Set circle color based on received distance signal
      if (wasteType.equals("RECYCLABLE")) {
        circleFillColor = color(0, 255, 0); // Green for recyclable
      } else if (wasteType.equals("NON_RECYCLABLE")) {
        circleFillColor = color(255, 0, 0); // Red for non-recyclable
      } else if (wasteType.equals("COMPOSTABLE")) {
        circleFillColor = color(0, 0, 255); // Blue for compostable
      }
      
      gameStarted = true; // Start the game when signal received
    }
  }
}
content_copyCOPY