Java 如何改进我的处理节奏游戏原型?

Java 如何改进我的处理节奏游戏原型?,java,javascript,processing,Java,Javascript,Processing,我正在尝试创建一个类似于Osu的节奏游戏。游戏应该根据正在播放的音乐创建一个块。在我所处的舞台上,每当音乐响起,游戏就会暂停。音乐也会失真。请帮忙 int start; float xpos; float ypos; int counter = 0; Boolean menu = true; Boolean game = false; import ddf.minim.*; click Clicker; Minim minim; AudioPlayer song; void setu

我正在尝试创建一个类似于Osu的节奏游戏。游戏应该根据正在播放的音乐创建一个块。在我所处的舞台上,每当音乐响起,游戏就会暂停。音乐也会失真。请帮忙

int start;
float xpos;
float ypos;

int counter = 0;

Boolean menu = true;
Boolean game = false;

import ddf.minim.*;

click Clicker;

Minim minim;
AudioPlayer song;

void setup() {
  size (800,800);
  Clicker = new click();
  start = millis();

}

void draw() {
  if (menu) {
    text("Welcome to My Game!", 300, 350);
    text("Get ready to play", 400, 375);
    text("Click on the screen to start", 275, 400);
    textSize(35);


  }

  if(game) {
    Clicker.display();
    Clicker.click();
    Clicker.gui();

    int timer = millis()/1000;
    text("Time: "+ timer, 10, 760);

    minim = new Minim(this);
    song = minim.loadFile("Bohemian Rhapsody.mp3");
    song.play();

  }
}

class click {
  float xpos;
  float ypos = 50;
  float wide;
  float high;
  float colour;

  click() {
    wide = 30;
    high = 30;
   colour = 45;
  }

  void display() {
    background (255);
    fill(colour);
    rect(xpos, ypos, wide, high);
  }

  void click() {
    if (mousePressed) {
      if (mouseX >= xpos && mouseX <= xpos + 30) {
        if (mouseY >= ypos && mouseY <= ypos + 30) {
          counter = counter + 1;
          xpos = random(0, 750);
          ypos = random(50, 650);
        }
      }
    }
  }

  void gui() {
    text("Score: " + counter, 10, 790);
    textSize(35);
    line(0, 700, 800, 700);
  }
}

void mousePressed() {
  if (menu) {
    menu = false;
    game = true;
  }
}
int启动;
浮动XPO;
浮动YPO;
int计数器=0;
布尔菜单=真;
布尔博弈=假;
进口ddf.微量。*;
点击点击器;
极小极小;
音频播放器歌曲;
无效设置(){
尺寸(800800);
Clicker=新单击();
开始=毫秒();
}
作废提款(){
如果(菜单){
文本(“欢迎来到我的游戏!”,300350);
文本(“准备好玩”,400375);
文本(“点击屏幕开始”,275400);
文本大小(35);
}
如果(游戏){
Clicker.display();
Clicker.click();
Clicker.gui();
int timer=millis()/1000;
文本(“时间:+计时器,10760);
最小值=新的最小值(本);
song=minim.loadFile(“Bohemian Rhapsody.mp3”);
歌曲。游戏();
}
}
类单击{
浮动XPO;
浮动ypos=50;
漂浮广泛;
高飘浮;
浮色;
单击(){
宽=30;
高=30;
颜色=45;
}
无效显示(){
背景(255);
填充(颜色);
rect(XPO、YPO、宽、高);
}
无效单击(){
如果(鼠标按下){

如果(mouseX>=xpos&&mouseX=ypos&&mouseY有一些问题需要解决和改进:

  • 语法/流程
  • 游戏设计
  • 节奏游戏
  • 1.语法/流程

    音乐可能会失真的原因是,您在draw()函数中多次初始化mini库。类似地,您应该为歌曲调用play()一次。下面是代码的一个版本,其中移动了几行:

    import ddf.minim.*;
    
    float xpos;
    float ypos;
    
    int counter = 0;
    
    Boolean menu = true;
    Boolean game = false;
    
    click Clicker;
    
    Minim minim;
    AudioPlayer song;
    
    void setup() {
      size (800,800);
      Clicker = new click();
      //initialize the library once, when you setup
      minim = new Minim(this);
      song = minim.loadFile("Bohemian Rhapsody.mp3");
    }
    
    void draw() {
      if (menu) {
        text("Welcome to My Game!", 300, 350);
        text("Get ready to play", 400, 375);
        text("Click on the screen to start", 275, 400);
        textSize(35);
    
    
      }
    
      if(game) {
        Clicker.display();
        Clicker.click();
        Clicker.gui();
    
        int timer = millis()/1000;
        text("Time: "+ timer, 10, 760);
    
      }
    }
    
    class click {
      float xpos;
      float ypos = 50;
      float wide;
      float high;
      float colour;
    
      click() {
        wide = 30;
        high = 30;
       colour = 45;
      }
    
      void display() {
        background (255);
        fill(colour);
        rect(xpos, ypos, wide, high);
      }
    
      void click() {
        if (mousePressed) {
          if (mouseX >= xpos && mouseX <= xpos + 30) {
            if (mouseY >= ypos && mouseY <= ypos + 30) {
              counter = counter + 1;
              xpos = random(0, 750);
              ypos = random(50, 650);
            }
          }
        }
      }
    
      void gui() {
        text("Score: " + counter, 10, 790);
        textSize(35);
        line(0, 700, 800, 700);
      }
    }
    
    void mousePressed() {
      if (menu) {
        menu = false;
        game = true;
        song.play();//play the song once, when entering game mode
      }
    }
    
    导入ddf.minim.*;
    浮动XPO;
    浮动YPO;
    int计数器=0;
    布尔菜单=真;
    布尔博弈=假;
    点击点击器;
    极小极小;
    音频播放器歌曲;
    无效设置(){
    尺寸(800800);
    Clicker=新单击();
    //在安装时初始化库一次
    最小值=新的最小值(本);
    song=minim.loadFile(“Bohemian Rhapsody.mp3”);
    }
    作废提款(){
    如果(菜单){
    文本(“欢迎来到我的游戏!”,300350);
    文本(“准备好玩”,400375);
    文本(“点击屏幕开始”,275400);
    文本大小(35);
    }
    如果(游戏){
    Clicker.display();
    Clicker.click();
    Clicker.gui();
    int timer=millis()/1000;
    文本(“时间:+计时器,10760);
    }
    }
    类单击{
    浮动XPO;
    浮动ypos=50;
    漂浮广泛;
    高飘浮;
    浮色;
    单击(){
    宽=30;
    高=30;
    颜色=45;
    }
    无效显示(){
    背景(255);
    填充(颜色);
    rect(XPO、YPO、宽、高);
    }
    无效单击(){
    如果(鼠标按下){
    如果(mouseX>=xpos&&mouseX=ypos&&mouseY