简体   繁体   English

如何改进我的Processing节奏游戏的原型?

[英]How can I improve my prototype of my Processing rhythm game?

I am trying to create a rhythm game in Processing similar to Osu. 我正在尝试在处理中创建类似于Osu的节奏游戏。 The game is supposed to create a block based on the music that is being played. 该游戏应该根据正在播放的音乐创建一个块。 At the stage I'm at, the game hangs whenever the music plays. 在我所处的阶段,只要有音乐播放,游戏就会挂起。 The music gets distorted as well. 音乐也会失真。 Please help! 请帮忙!

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

There a few things to fix and improve: 有一些要修复和改进的地方:

  1. Syntax / flow 语法/流程
  2. Game design 游戏设计
  3. Rhythm games 节奏游戏

1. Syntax / flow 1.语法/流程

The reason why probably music gets distorted is because you're initializing the minim library multi times in the draw() function. 音乐可能会失真的原因是,您在draw()函数中多次初始化了minim库。 Similarly, you should call play() once for your song. 同样,您应该为歌曲调用一次play()。 Here's a version of your code with a few lines moved: 这是您的代码版本,其中移动了几行:

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. Game design 2.游戏设计

There are plenty of resources online on the topic and simply playing games should help pin point a couple of basic questions to ask: 在线上有大量有关该主题的资源,仅玩游戏应该有助于指出几个基本问​​题:

  • What is the goal/reward of the game (does a plumber save a princes, is a puzzle solved) ? 游戏的目标/奖励是什么(水管工可以救王子吗,难题是否解决了)?
  • How does the game work (what are the rules/mechanics/when does a level start/end/ do you win/lose/ how ?) 游戏的运作方式(规则/机制/关卡何时开始/结束/您赢/输/如何?)

Your current version presents a never ending level where time increases and as well as score as long as the player chooses to click a box. 您当前的版本会显示一个永无止境的级别,只要玩家选择单击一个框,时间就会增加,分数也会增加。 Try placing a time limit per level. 尝试为每个级别设置时间限制。 You can always introduce complexity to level up (introduce two boxes at the same time with a preferred click sequence, etc.). 您总是可以引入复杂性来进行升级(以首选的点击顺序同时引入两个框,等等)。 You've mentioned the Osu rhythm game, but you should really play it and try to break down it's rules/algorithms into steps. 您已经提到了Osu节奏游戏,但您应该真正玩它,并尝试将其规则/算法分解为若干步骤。

3. Rhythm games 3.节奏游戏

The fun part about rhythm is the tight connection between what you see, what you hear (which is a pretty goal to get right on it's own) but also how/when you interact. 节奏最有趣的部分是您所看到的,所听到的声音之间的紧密联系(这是一个很不错的目标,它本身就是正确的),而且还包括您如何/何时互动。

Currently if you comment you the music, this makes no difference to the game at all. 目前,如果您对音乐进行评论,这对游戏完全没有影响。 There is no relationship to the music at all. 与音乐没有任何关系。 You should try adding user interaction based on key moments in the music. 您应该尝试根据音乐中的关键时刻添加用户互动。 Minim already provides some onset and beat detection . Minim已经提供了一些起跳和节拍检测功能 You should have a play with that. 你应该玩这个。 (Alternatively, you can try software or services like Echonest to do the music analysis and extract the key moments, or simply add markers yourself manually in a software and export a csv file if that allows it) (或者,您可以尝试使用诸如Echonest之类的软件或服务来进行音乐分析并提取关键时刻,或者直接在软件中手动添加标记并在允许的情况下导出csv文件)

Have fun! 玩得开心!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM