コード:
#include "testApp.h"
//--------------------------------------------------------------
int speed=5;
int note[201]={750,250,750,250,500,500,1000, //ドはドーナッツのド
750,250,250,250,250,250,2000, //レはレモンのレ
750,250,750,250,500,500,1000, //ミはみんなのミ
750,250,250,250,250,250,2000, //ファはファイトのファ
750,250,250,250,250,250,2000, //ソは青い空
750,250,250,250,250,250,2000, //ラはラッパのラ
750,250,250,250,250,250,1500, //シはしあわせよ
250,250,500,500,500,500,2000, //さぁ歌いましょう
750,250,750,250,500,500,1000, //どんなときにも
750,250,250,250,250,250,2000, //列を組んで
750,250,750,250,500,500,1000, //みんな楽しく
750,250,250,250,250,250,2000, //ファイトをもって
750,250,250,250,250,250,2000, //空を仰いで
750,250,250,250,250,250,2000, //ラララララララ
750,250,250,250,250,250,1500, //幸せの歌
250,250,500,500,500,500,1000,1000,500, //さぁ歌いましょう
500,500,500,500,500,500,500,500, //ドレミファソラシド
500,500,500,500,500,500,500, //ドシラソファミレ
500,500,1000,500,500,1000, //ドミミ ミソソ
500,500,1000,500,500,1000, //レファファ ラシシ
250,250,500,250,250,500,250,250,500,250,250,500, //ドミミ ミソソ レファファ ラシシ
250,250,500,250,250,500,250,250,500,250,250,500, //ドミミ ミソソ レファファ ラシシ
500,500,500,500,500,500,500,500,500,500,500,500,2000, //ソドラファミドレ
500,500,500,500,500,500,500,500,500,500,500,500,2250, //ソドラシドレド
250,250,250,250,250,250,250,1000,1000,1500}; //ドレミファソラシド ソ ド
void testApp::setup()
{
ofSetLogLevel(OF_LOG_VERBOSE);
ofLog(OF_LOG_VERBOSE, "Start setup()");
// 画面の設定
ofSetFrameRate(60);
ofSetCircleResolution(128);
ofBackground(255, 255, 255);
ofSetWindowShape(480, 360);
ofEnableSmoothing();
//フォント読み込み
point_font.loadFont("vag.ttf", 18); //ソリューションパス\bin\data内にフォントを用意
game_font.loadFont("vag.ttf", 32);
//ゲーム画面の設定
menu=true; //メニューの表示
mouse_on=false; //マウスはボタンの外
//画面の混合の設定を加算合成にする
ofEnableAlphaBlending();
glEnable(GL_BLEND);
//画像データの読み込み
judge.loadImage("judge.png");
don.loadImage("don.png");
katsu.loadImage("katsu.png");
//曲の読み込み
strcpy(music,"dddkddddkdkdkddkkdkdkdkdkdkdddddddkkkkkkkdddddddkkkdddkddddkddddkdkdkddkkdkdkdkdkdkdddddddkkkkkkkdddddddkkkdddkdkkdkdkddddkdkdkkkdkkkdddkkkdddkkkdddkkkdddkkkdddkkkddddkkddkkddkkdddkkddkkddkkdddkdkdkdkd");
//各音の長さはグローバルで
time=0; //0番目の太鼓から
sound.loadSound("Sound_of_doremi.wav");
sound.setLoop(false);
don_sound.loadSound("don.wav");
katsu_sound.loadSound("katsu.wav");
}
//--------------------------------------------------------------
void testApp::update()
{
if(menu==false && game==0){//ゲームの最中なら
new_time=sound.getPosition();
if(new_time*115000>=musicpos){ //次の太鼓を流してよくなるまで待ったら
time++; //次の太鼓を流す
if(time<202){
old_time=new_time;
if(music[time]=='d'){
drum[0].push_back(0);
}
else{
drum[0].push_back(1);
}
drum[1].push_back(640);
drum_time.push_back(new_time);
musicpos=musicpos+note[time];
}
}
if(drum[1].size()>0){ //終わりではなくて、1つ以上太鼓が画面にあるなら
for(int n=0;n<drum[1].size();n++){
drum[1][n]=40+(int)(0.3*(2000-(new_time-drum_time[n])*115000)); //太鼓を流す
}
if(drum[1][0]<0){
if(check==0){ //もし太鼓が素通りされていたら
point=point-50;
check=-2;
}
}
if(drum[1][0]<-40){ //画面から見えなくなったら
for(int n=1;n<drum[1].size();n++){
drum[0][n-1]=drum[0][n];
drum[1][n-1]=drum[1][n];
drum_time[n-1]=drum_time[n];
}
drum[0].pop_back();
drum[1].pop_back();
drum_time.pop_back();
check=0;
}
}
}
}
void testApp::draw() //setupで決めたフラッシュレートに従って呼び出される
{
if(menu==true){ //メニューを表示する
ofSetHexColor(0x000000);
game_font.drawString("Expert of Drum",100,150);
if(mouse_on==true){
ofSetColor(0,0,0);
ofRect(198,177,60,25);
ofSetColor(255,255,255);
ofRect(199,178,58,23);
}
ofSetHexColor(0x000000);
point_font.drawString("Start",200,200);
}
else{
//譜面のバーを描画
ofSetColor(0,0,0);
ofRect(0,147,480,3); //上バー
ofRect(0,210,480,3); //下バー
//画像で使える色を設定
ofSetColor(255,255,255);//全色可
//判定枠の描画
judge.draw(40,160);
//譜面に合わせてドンやカツを表示
if(drum[0].size()>0){
for(int n=0;n<drum[0].size();n++){
if(drum[0][n]==0){
don.draw(drum[1][n],160);
}
else{
katsu.draw(drum[1][n],160);
}
}
}
//文字等の描画
ofSetHexColor(0x000000);
switch (check){
case -2:
point_font.drawString("Very Bad...",40,120);
break;
case -1:
point_font.drawString("Bad...",40,120);
break;
case 1:
point_font.drawString("Good!",40,120);
break;
case 2:
point_font.drawString("Very Good!",40,120);
break;
}
char points[20];
sprintf(points,"Point : %d",point);
point_font.drawString(points,440-point_font.getStringBoundingBox(points,0,0).width,120);
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
// キーが押された時の処理
if(menu==false && game==0){ //ゲームの最中であるなら
if(time>=14){
time=time;
}
if(drum[0].size()>0){
switch (key)
{
case 'd':
don_sound.play();
if(drum[1][0]>=0 && drum[1][0]<=100){
testApp::checker(0);
}
break;
case 'k':
katsu_sound.play();
if(drum[1][0]>=0 && drum[1][0]<=100){
testApp::checker(1);
}
break;
}
}
}
}
void testApp::exit()
{
ofLog(OF_LOG_VERBOSE, "End Application");
}
//--------------------------------------------------------------
//--------------------------------------------------------------
void testApp::keyReleased(int key)
{
// キーがリリースされた時の処理
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y )
{
// マウスが動かされた時の処理
if((x>=198 && x<=258) && (y>=179 && y<=202)){
mouse_on=true;
}
else{
mouse_on=false;
}
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{
// マウスがドラッグされた時の処理
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button)
{
// マウスボタンが押された時の処理
if(menu==true && (x>=198 && x<=258) && (y>=179 && y<=202)){
mouse_on=0;
game=0;
menu=false;
testApp::start();
}
else if(game!=0){
menu=true;
}
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button)
{
// マウスボタンがリリースされた時の処理
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h)
{
// ウィンドウがリサイズされた時の処理
ofSetWindowShape(480, 360);
}
void testApp::start(){
//得点の初期化
point=0;
count_point=0;
count_total=0;
drum[0].push_back(0);
drum[1].push_back(640);
sound.play();
old_time=sound.getPosition();
drum_time.push_back(old_time);
musicpos=note[time];
}
void testApp::checker(int push){
if(push==drum[0][0]){
if(drum[1][0]>15 && drum[1][0]<55){
point=point+100;
check=2;
}
else if(drum[1][0]>0 && drum[1][0]<80){
point=point+50;
check=1;
}
else if(drum[1][0]>-20 && drum[1][0]<100){
point=point;
check=-1;
}
}
else{
check=-1;
}
for(int n=1;n<drum[1].size();n++){
drum[0][n-1]=drum[0][n];
drum[1][n-1]=drum[1][n];
drum_time[n-1]=drum_time[n];
}
drum[0].pop_back();
drum[1].pop_back();
drum_time.pop_back();
}