塵芥回顧録

掃き溜めのようなブログ(?)

某音ゲー(processing)

音ゲー(processing)
f:id:nupepon:20210225163929p:plain

Note[] notes;
int k=10;
boolean[] sw;
int[] count;
int interval = 10*k; //ノーツが作成される最小間隔
int make_kakuritu = 5*k; //低いほどノーツが発生しやすい

void setup() {
  frameRate(60);
  size(200, 150);
  notes = new Note[k*8];
  sw = new boolean[8];
  count = new int[8];
  for (int i=0; i<k; i++) {
    notes[i*8] = new Note(255, 0, 0, 30);
    notes[i*8+1] = new Note(255, 255, 255, 50);
    notes[i*8+2] = new Note(0, 0, 255, 70);
    notes[i*8+3] = new Note(255, 255, 255, 90);
    notes[i*8+4] = new Note(0, 0, 255, 110);
    notes[i*8+5] = new Note(255, 255, 255, 130);
    notes[i*8+6] = new Note(0, 0, 255, 150);
    notes[i*8+7] = new Note(255, 255, 255, 170);
  }
  for (int i=0; i<8; i++) {
    sw[i] = true;
    count[i] = 0;
  }
}

void draw() {
  clear();
  back_draw();
  for (int i=0; i<notes.length; i++) notes[i].draw(sw, count, i%8);
}

void back_draw() {
  noStroke();
  fill(255, 0, 0);
  rectMode(CENTER);
  rect(109, height-10, 160, 5);
  stroke(180);
  strokeWeight(1);
  for (int i=0; i<=8; i++)
    line(29+i*20, 0, 29+i*20, height-9);
  stroke(255, 0, 0);
  strokeWeight(19);
}

class Note {
  int colR, colG, colB;
  int y=0, x;
  boolean sw=false;
  int count = 0;

  Note(int colR, int colG, int colB, int x) {
    this.colR=colR;
    this.colG=colG;
    this.colB=colB;
    this.x=x;
  }

  void draw(boolean[] make_sw, int[] count, int num) {
    if (sw==true) {
      stroke(100);
      strokeWeight(1);
      rectMode(CORNER);
      fill(colR, colG, colB);
      rect(x, y, 19, 5);
      y++;
      if (y>height-12) {
        y=0;
        sw = false;
      }
    } else {
      if (int(random(make_kakuritu)) == 0 && make_sw[num] == true) {
        sw=true;
        make_sw[num] = false;
      }
    }
    if (make_sw[num]==false) {
      count[num]++;
      if (count[num] > interval) {
        make_sw[num] = true;
        count[num] = 0;
      }
    }
  }
}