java - 如何改进我的处理节奏游戏原型(prototype)?

标签 java javascript processing

我正在尝试在Processing中创建一个类似于Osu的节奏游戏。游戏应该根据正在播放的音乐创建一个 block 。在我所处的阶段,只要音乐播放,游戏就会挂起。音乐也会失真。请帮忙!

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

最佳答案

有一些问题需要修复和改进:

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

<强>1。语法/流程

音乐可能失真的原因是您在draw()函数中多次初始化最小库。同样,您应该为您的歌曲调用一次 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
  }
}

<强>2。游戏设计

网上有大量关于该主题的资源,只需玩游戏就可以帮助确定一些要问的基本问题:

  • 游戏的目标/奖励是什么(水管工是否拯救了王子,谜题是否已解决)?
  • 游戏是如何运作的(规则/机制是什么/关卡何时开始/结束/你赢/输/如何?)

您当前的版本呈现了一个永无止境的关卡,只要玩家选择单击一个框,时间就会增加,得分也会增加。尝试为每个级别设置时间限制。您始终可以引入复杂性来升级(同时引入两个框以及首选的点击顺序等)。您提到了 Osu 节奏游戏,但您应该真正玩它并尝试将其规则/算法分解为步骤。

<强>3。节奏游戏

节奏的有趣之处在于你所看到的、你所听到的(这是一个很好的目标)以及你如何/何时互动之间的紧密联系。

目前,如果您对音乐发表评论,这对游戏没有任何影响。和音乐完全没有关系。您应该尝试根据音乐中的关键时刻添加用户交互。 Minim 已经提供了一些 onset and beat detection 。你应该玩玩这个。 (或者,您可以尝试像 Echonest 这样的软件或服务来进行音乐分析并提取关键时刻,或者只是在软件中手动添加标记并导出 csv 文件(如果允许)

玩得开心!

关于java - 如何改进我的处理节奏游戏原型(prototype)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30384423/

相关文章:

javascript - JQuery 基本表单发布

java - 碰撞器(java处理)

Android 的 Java 错误 "Unable to Find Symbol"

java - 如何通过完整性检查从 Dropbox 下载文件?

javascript - Python 中的 jQuery $.param'ed 字符串解析(应用引擎)

java - 每 3 秒在处理中将 MouseWheel 值返回为滚动/不滚动?

java - 为什么我必须向家长提供创建客户的信息?

java - 如何使用另一个 JFrame 中的数据更新 JFrame?

java - Spring 中的 Hibernate 事务管理器配置

javascript - array.splice 在 javascript 中无法正常工作