ページ 11

弾幕の作成について

Posted: 2011年9月03日(土) 15:32
by クラバック
初めまして。このサイトで弾幕シューティングの学習をさせて頂いている者です。いつもお世話になっております。
弾幕が思うように作れず、行き詰まってしまったので質問させて頂きました。

自機の周りを12コの弾が円状に取り囲み、12個目の弾が表示された後、弾が一斉に円の中心に収束する、という弾幕を作成しています。
ですが、弾が円の中心に収束する、という処理を思うように作れません。
一回目の円は作成でき、収束出来るのですが、二回目の円を描いた後の弾が収束しません。
何卒、ご教授下さいます様よろしくお願い致します。

コード:

void boss_shot_bulletH004(){ 
	#define TM004 60
	int i=0;
	int k=0;
	static double nowCharactorX;
	static double nowCharactorY;
	int t=boss_shot.cnt%TM004; //t=0~59
	//	double angle; 
	//60カウント以下で5カウントに1回
	
	if(t==0){
		nowCharactorX = ch.x;
		nowCharactorY = ch.y;
	}
	if(t<60 && t%5==0){ 	
		if((k=search_boss_shot())!=-1){
			boss_shot.bullet[k].col		= 1;//弾の色 
			boss_shot.bullet[k].x	       = nowCharactorX + sin(PI2/60*t) * 100;
			boss_shot.bullet[k].y		= nowCharactorY - cos(PI2/60*t) * 100; 
			boss_shot.bullet[k].knd		= 1;//弾の種類 
			boss_shot.bullet[k].angle	= 0;//角度 
			boss_shot.bullet[k].flag	= 1; 
			boss_shot.bullet[k].cnt		= 0; 
			boss_shot.bullet[k].spd		= 0;//スピード
			boss_shot.bullet[k].state	= 0;
			boss_shot.bullet[k].till	= 60;
			se_flag[0]=1; 
		}
	}
	for(i=0;i<BOSS_BULLET_MAX;i++){
		if(boss_shot.bullet[i].flag>0){
			if(boss_shot.bullet[i].state==0){
				if(t==59){
					boss_shot.bullet[i].spd = 3;
					for(int j=0;j<12;j++){
						boss_shot.bullet[j].angle = PI/2 + PI/6*j;
						se_flag[0]=1;
					}
					
				}
			}
		}
	}
}

Re: 弾幕の作成について

Posted: 2011年9月03日(土) 16:02
by Tatu
36行目の
boss_shot.bullet[j].angle = PI/2 + PI/6*j;
が問題ですね。弾の番号が0から11とは限りません。
また、弾の番号が0から11の間にあったとしても順番がバラバラな可能性があります。
よってこの手は使えません。

私ならば今回の弾幕に使っている弾の画像は方向で変わらないので
弾を配置するときに円の中心に向かうように角度を設定し、
動き出す時間になったらスピードを与えるというようにします。

Re: 弾幕の作成について

Posted: 2011年9月03日(土) 17:52
by クラバック
出来ましたっ。Tatuさん、有難うございます!
これからこのコードを、さらに改造していこうと思いますっ

コード:

void boss_shot_bulletH004(){ 
	#define TM004 60
	int k=0;
	int l=0;
	static double nowCharactorX;
	static double nowCharactorY;
	int t=boss_shot.cnt%TM004; //t=0~59
	//	double angle; 
	//60カウント以下で5カウントに1回
	
	if(t==0){
		nowCharactorX = ch.x;
		nowCharactorY = ch.y;
	}
	if(t<60 && t%5==0){ 	
		if((k=search_boss_shot())!=-1){
			boss_shot.bullet[k].col		= 1;//弾の色 
			boss_shot.bullet[k].x		= nowCharactorX + sin(PI2/60*t) * 100;
			boss_shot.bullet[k].y		= nowCharactorY - cos(PI2/60*t) * 100; 
			boss_shot.bullet[k].knd		= 1;//弾の種類 
			boss_shot.bullet[k].angle	= PI/2 + PI/6*(t/5);//角度 
			boss_shot.bullet[k].flag	= 1; 
			boss_shot.bullet[k].cnt		= 0; 
			boss_shot.bullet[k].spd		= 0;//スピード
			boss_shot.bullet[k].state	= 0;
			boss_shot.bullet[k].till	= 60;
			se_flag[0]=1; 
		}
	}
	if(t==55){
		for(int i=0;i<BOSS_BULLET_MAX;i++){
			if(boss_shot.bullet[i].state==0){
				boss_shot.bullet[i].cnt = 0;
				boss_shot.bullet[i].spd = 2;
				boss_shot.bullet[i].state = 1;
			}
		}
	}
	for(int i=0;i<BOSS_BULLET_MAX;i++){
		if(boss_shot.bullet[i].state == 1){
			if(boss_shot.bullet[i].cnt ==50){
			boss_shot.bullet[i].flag = 0;
			}
		}
	}
}