1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Processing]音ゲーもどきを作る

Last updated at Posted at 2020-03-12

こんな

タイミングよくクリック
良し悪しは顔色に出るよ
※ガバガバ判定
SmileMaster.gif

導入

赤ぴらのためにライブラリをインポートします
image.png

スケッチ→ライブラリをインポート→ライブラリを追加
image.png

検索ボックスに「minim」と入力して、「Minim | An audio library ...」を選択して
image.png

インストール
image.png

赤ぴら消えました
image.png

プログラム

Smile_Master.java

//音楽再生用インポート
import ddf.minim.*;

//音楽使用クラス
Minim minim;

//音楽再生クラス
AudioPlayer player;

//楽譜
float[] MusicalScore = {9.7f, 10.2f, 10.6f, 11.2f, 11.6f, 12.2f, 12.8f, 13.4f, 
  14.0f, 14.6f, 15.0f, 15.6f, 15.9f, 16.3f, 16.9f, 17.5f, 
  18.0f, 18.5f, 18.8f, 19.4f, 20.1f, 20.4f, 20.9f, 21.7f, 
  22.1f, 22.6f, 23.1f, 23.5f, 24.0f, 24.6f, 25.2f, 25.8f, 
  26.0f, 27.0f, 28.0f, 29.0f, 29.5f, 30.0f, 31.0f, 36.4f, 
  38.5f, 39.6f, 40.5f, 41.6f, 42.6f, 46.0f, 47.0f, 48.0f, 
  48.5f, 49.5f, 50.5f, 52.0f, 52.8f, 53.5f, 54.6f, 55.4f, 
  60.5f, 62.7f, 63.7f, 64.7f, 65.7f, // 中盤
  67.3f, 67.8f, 68.3f, 68.8f, 69.2f, 69.8f, 70.2f, 70.8f, 
  71.2f, 71.8f, 72.3f, 73.0f, 73.5f, 74.2f, 74.6f, 75.1f, 
  75.6f, 76.2f, 76.6f, 77.3f, 77.8f, 78.1f, 78.7f, 79.2f, 
  79.7f, 80.4f, 80.8f, 81.2f, 81.5f, 82.5f, 82.9f, 83.3f, 
  83.8f, 84.8f, 85.7f, 86.6f, 87.2f, 87.7f, 88.3f, 92000
};

//配列ナンバー
int musicalNum = 0;

//音符リスト
ArrayList<Note> notes = new ArrayList<Note>();

//リストの要素削除可否
boolean delete = false;

//中央の表情
boolean Face = true;

//回転
float a;

//楽譜タイマー
float timer = 0;

//軌道半径
float radius = 250;

//音符クラス
class Note {

  float x, y;     //ポジション
  float size = 0; //サイズ
  float radian;   //角度
  float ratio;    //拡大率
  float speed = 5;//移動速度

  Note(float x, float y) {
    this.x = x;
    this.y = y;
    radian = atan2(0-y, 0-x); //ポジションから角度を出す
    ratio = speed/radius;
  }

  void Move() {
    //拡大率だけ大きくする
    size += ratio;

    //移動
    x += cos(radian) * speed;
    y += sin(radian) * speed;

    //中心まで行ったら
    if (abs(0 - x) < 0.1 && abs(0 - y) < 0.1) {
      delete = true;
      Face = false;
      return;
    }

    pushMatrix();
    translate(x, y);
    rotate(radian);
    scale(size);
    draw_smiley();
    popMatrix();
    textSize(50);
    //text("( "+ratio+" , "+size+" )",x,y);
  }

  void Don() {

    //距離が遠いなら返す
    if (abs(0 - x) >= 20 || abs(0 - y) >= 20) return ;

    else if (notes.get(0) == this) {

      //10未満まで近いなら ☺
      Face = abs(0 - x) < 12 && abs(0 - y) < 12;
      delete = true;
    }
  }
}


void draw_smiley() {
  ellipseMode(CENTER);
  strokeWeight(3);
  stroke(0);
  fill(#ffff00);
  ellipse(0, 0, 100, 100);
  noStroke();
  fill(0);
  ellipse(-15, -15, 12, 12);
  ellipse(15, -15, 12, 12);
  stroke(#ff0000); 
  noFill();
  bezier(-25, 20, -10, 35, 10, 35, 25, 20);
}

void draw_face(boolean face) {

  if (face) {
    draw_smiley();
  } else {
    ellipseMode(CENTER);
    strokeWeight(3);
    stroke(0);
    fill(#ff2600);
    ellipse(0, 0, 100, 100);
    noStroke();
    fill(0);
    ellipse(-15, -15, 12, 12);
    ellipse(15, -15, 12, 12);
    stroke(#ffffff); 
    noFill();
    bezier(-25, 35, -10, 20, 10, 20, 25, 35);
  }
}

void setup() {
  //size(1600, 800);
  fullScreen();
  //タイミングの都合でフレームレート10
  frameRate(10);
  minim = new Minim(this);
  player = minim.loadFile("世にも奇妙な物語テーマ曲.mp3");
  player.play();
}

void draw() {
  a = radians(frameCount);
  background(255);
  translate(width/2, height/2);
  timer = millis();

  //☆
  pushMatrix();
  rotate(-a);
  scale(1.2f);
  draw_face(Face);
  popMatrix();
  //☆
  pushMatrix();
  rotate(-a);
  translate(radius, 0);
  scale(0.5f);
  rotate(a);
  draw_smiley();

  //楽譜にそって音符生成
  if (timer/1000f + 3.5f > MusicalScore[musicalNum]) {
    Note n = new Note(radius * cos(-a), radius * sin(-a));
    notes.add(n);

    musicalNum++;
    if (musicalNum == MusicalScore.length) {
      musicalNum = MusicalScore.length - 1;
    }
  }

  popMatrix();
  //☆

  for (int i = notes.size() -1; i>=0; i--) {
    Note note = notes.get(i);
    note.Move();
    if (mousePressed) {
      note.Don();
    }
  }

  //リストの先頭削除
  if (delete) {
    delete = false;
    notes.remove(0);
  }
}

曲はこれです
image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?