そのうちのひとつとして以下のような当たり判定からランダムに3つ選択してその範囲内のブロックのライフを1減らすというのを考えています。
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
自分なりに考えてwhileを使えば同じ値である間何度もループするのではないかと思い
int spcnt = 0;
int sp2pos[3] = {0,0,0};
void ch_sp(){
if(CheckStatePad(6)%30 == 1){
switch(bar.state){
case 0:
spflag = 1;
break;
case 1:
spflag = 3;
break;
case 2:
spflag = 5;
break;
}
}
if(spflag == 5){
spcnt++;
if(spcnt == 1)
sp2pos[0] =GetRand(14);
while(sp2pos[1] == sp2pos[0]){
sp2pos[1] = GetRand(14);
}
while((sp2pos[2] == sp2pos[1]) || (sp2pos[2] = sp2pos[0])){
sp2pos[2] = GetRand(14);
}
for(int i = 0;i<3;i++){
sp2hit[i].lt.x = 30+70*sp2pos[i]%5; sp2hit[i].lt.y =30 + 100*sp2pos[i]/5;
sp2hit[i].rb.x = 90+70*sp2pos[i]%5; sp2hit[i].rb.y =90 + 100*sp2pos[i]/5;
sp2hit[i].height=60; sp2hit[i].width = 60;
}
}
}
表示されず、エラーが出てしまいます。
おまけ
異なる位置というのを考えずにwhileを使わずに行ったのですが、一応表示されるもののなぜか常にすべて左側です。%と/の使い方がおかしいのでしょうか。