49 章
今回は自機のショットにオプションを付けてみましょう。
ホーミング処理は次回に任せるとして、今回はオプションを発射するためのぼんぼんを用意し、
表示し、そこからオプションを発射させてみます。
ではいつものようにオプションのぼんぼん名づけてoption_bbの構造体を用意し、宣言し、計算させてやりましょう。
オプションの画像は現在固定なので、初期化関数で予め入れておきます。
---- struct.h に以下を追加 ---- //キャラクターショットに関する構造体 typedef struct{ int flag; //フラグ int power; //パワー int cnt; //カウンタ int knd; //種類 int img; //画像(49) double x,y; //座標 double angle; //角度 double spd; //スピード }cshot_t; //ショットのオプション発射元ボンボン typedef struct{ int flag; //フラグ int img; //画像 int cnt; //カウンタ double x,y; //座標 }option_bb_t; ---- GV.h に以下を追加 ---- GLOBAL int img_cshot[3]; //自機ショット用画像(49) GLOBAL option_bb_t option_bb[2];//オプション発射元ボンボン(49) ---- load.cpp に以下を追加 ---- img_cshot[2]=LoadGraph("../dat/img/char/ball.png"); ---- ini.cpp 内の以下の部分を変更 ---- memset(option_bb,0,sizeof(option_bb_t)*2);//(49) option_bb[0].img=img_cshot[2];//オプションボンボンの画像代入(49) option_bb[1].img=img_cshot[2];
オプションはオプションで独立して動き、オプションから発射させます。
自機のパワーが100〜299の時はオプションから2つ発射。
それ以上の時は4つ発射します。
オプションの基本位置は定義で用意しておき、4つの各角度はoption0angで設定しておきます。
オプションのぼんぼんはcalc_option_bbで計算します。
低速移動中はオプションを自機に近づけ固定します。
---- cshot.cpp に以下を追加 ---- #define OPTION_X 25 #define OPTION_Y 35 int option0num[2] ={2,4}; double option0ang[4] = {-PI/2,-PI/2,-PI/2-PI/4,-PI/2+PI/4};//オプションの発射角度(49) //自機ショットの登録可能番号を返す int search_cshot(){ for(int i=0;i<CSHOT_MAX;i++){ if(cshot[i].flag==0) return i; } return -1; } //通常ショット登録 void ch0_shot_pattern(){ int k; for(int i=0;i<cshot0num[ch.power<200?0:1];i++){ if((k=search_cshot())!=-1){ cshot[k].flag=1; cshot[k].cnt=0; cshot[k].angle=-PI/2; cshot[k].spd=20; cshot[k].x=ch.x+cshot0pos_x[i]; cshot[k].y=ch.y+cshot0pos_y[i]; cshot[k].power=23; cshot[k].knd=0; cshot[k].img=img_cshot[0];//画像番号代入(49) } } se_flag[2]=1;//発射音オン if(ch.power>=100){ for(int i=0;i<(ch.power<300?2:4);i++){ if((k=search_cshot())!=-1){ cshot[k].flag=1; cshot[k].cnt=0; cshot[k].angle=option0ang[i]; cshot[k].spd=20; cshot[k].x=option_bb[i%2].x; cshot[k].y=option_bb[i%2].y; cshot[k].power=20; cshot[k].knd=1; cshot[k].img=img_cshot[1];//画像番号代入(49) } } } } //低速通常ショット登録 void ch1_shot_pattern(){ int k; for(int i=0;i<cshot0num[ch.power<200?0:1];i++){ if((k=search_cshot())!=-1){ cshot[k].flag=1; cshot[k].cnt=0; cshot[k].angle=-PI/2; cshot[k].spd=20; cshot[k].x=ch.x+cshot0pos_x[i]/3;//低速中なら位置を中心側へ cshot[k].y=ch.y+cshot0pos_y[i]/2; cshot[k].power=23; cshot[k].knd=0; cshot[k].img=img_cshot[0];//画像番号代入(49) } } se_flag[2]=1; if(ch.power>=100){ for(int i=0;i<(ch.power<300?2:4);i++){ if((k=search_cshot())!=-1){ cshot[k].flag=1; cshot[k].cnt=0; cshot[k].angle=option0ang[i]; cshot[k].spd=20; cshot[k].x=option_bb[i%2].x; cshot[k].y=option_bb[i%2].y; cshot[k].power=20; cshot[k].knd=1; cshot[k].img=img_cshot[1];//画像番号代入(49) } } } } //オプションのぼんぼん計算 void calc_option_bb(){ if(ch.power>=100){//パワー100以上ならオプションをつける for(int i=0;i<2;i++){ if(CheckStatePad(configpad.slow)==0){//低速移動中じゃないなら option_bb[i].x=ch.x+OPTION_X*(i==0 ? -1 : 1); option_bb[i].y=ch.y+OPTION_Y+sin(PI2/150*option_bb[i].cnt)*20; } else{ option_bb[i].x=ch.x+OPTION_X/2*(i==0 ? -1 : 1); option_bb[i].y=ch.y+OPTION_Y/2; } option_bb[i].cnt++; } if(option_bb[0].flag==0) option_bb[0].flag = option_bb[1].flag = 1; } else{ if(option_bb[0].flag==1) option_bb[0].flag = option_bb[1].flag = 0; } } (略) //キャラクタショットに関する関数 void cshot_main(){ calc_option_bb();//オプションのぼんぼん計算(49) calc_cshot();//ショットの起動計算 enter_shot();//ショット登録 } ---- graph.cpp の以下を変更 ---- //自機描画 void graph_ch(){ double sx,sy,ny=(sin(2.0*PI*(count%50)/50)*3),ang=2.0*PI*(count%120)/120; if(CheckStatePad(configpad.slow)>0)//低速移動中なら sx=15,sy=15+ny;//引き寄せる else sx=30,sy=30+ny;//普通の位置に // DrawRotaGraphFdF( ch.x-sx, ch.y+sy, 1.0f, ang, img_chetc[2], TRUE ); // DrawRotaGraphFdF( ch.x+sx, ch.y+sy, 1.0f, -ang, img_chetc[2], TRUE ); if(ch.mutekicnt%2==0){//無敵中なら点滅 //自機表示 DrawRotaGraphFdF(ch.x,ch.y,1.0f,0.0f,img_ch[0][ch.img],TRUE); if(CheckStatePad(configpad.slow)>0)//低速移動中なら当たり判定表示 DrawRotaGraphFdF( ch.x, ch.y, 1.0f, 2.0*PI*(count%120)/120, img_chetc[0], TRUE ); } } //自機ショット描画 void graph_cshot(){ for(int i=0;i<CSHOT_MAX;i++){ if(cshot[i].flag>0){ DrawRotaGraphFdF(cshot[i].x,cshot[i].y,1,cshot[i].angle+PI/2,cshot[i].img,TRUE); } } for(int i=0;i<2;i++){//(49) if(option_bb[i].flag>0){ DrawRotaGraphFdF(option_bb[i].x,option_bb[i].y,1,0,option_bb[i].img,TRUE); } } }
実行結果
- Remical Soft -