class Floor { Button[] buttons; // 床に設置するボタン AudioSample[] samples; // 音声サンプル Button buttonPlayed; // 最後に音が再生されたボタンを保存 float floorY; // 床の座標 Floor(String name, float y) { floorY = y; samples = new AudioSample[6]; // 使うサウンドを6つに // 最初の3つはキャラ別フォルダから for(int i=0 ; i < 3 ; i++) { samples[i] = minim.loadSample(name + "/sound_"+nf(i,2)+".wav"); } // 残り3つは共通フォルダから for(int i=0 ; i < 3 ; i++) { samples[3 + i] = minim.loadSample("common/sound_"+nf(i,2)+".wav"); // インデックスを毎回+3する } // ボタンインスタンス作成 buttons = new Button[16]; for(int i=0; i < buttons.length ; i++) { buttons[i] = new Button(name, 3, i*40, floorY); } } void update(Character chara) { rectMode(CORNER); for(int i=0 ; i < buttons.length ; i++) { checkButton(buttons[i], chara); buttons[i].update(); } } void checkButton(Button button, Character chara) { if(chara.charaX > width && chara.charaX < width + chara.speedX) { buttonPlayed = null; } if( buttonPlayed != button && button.state >= 0 // 左端のボタンを判定するために(chara.charaX % width)をつかう && (chara.charaX % width) > button.buttonX && (chara.charaX % width) < button.buttonX + button.buttonWidth ) { buttonPlayed = button; chara.jump(); samples[button.state].trigger(); } } void mousePressed() { for(int i=0 ; i < buttons.length ; i++) { buttons[i].mousePressed(); } } }