現在DxLibraryで弾幕を避けるゲームを作っているのですが自機と弾幕を表示するところまではできたもののその弾と自機の当たり判定をどのように書けばいいかが調べてもいまいち分からず止まってます。もしよろしければ下記に汚いですがソースを載せるのでどのようにして当たり判定をつければいいか教えて頂けないでしょうか。
#include <DxLib.h>
#include <math.h>
int count = 0;
typedef struct{
float x,y;
int direction,speed;
int img ;
} ch_t , aodama ;
void fps(){
int i;
static int t=0,ave=0,f[60];
f[count%60]=GetNowCount()-t;
t=GetNowCount();
if(count%60==59){
ave=0;
for(i=0;i<60;i++)
ave+=f[i];
ave/=60;
}
if(ave!=0){
DrawFormatString(550, 450,GetColor(255,255,255),"%.1fFPS",300.0/(double)ave);
}
return;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
char Key[256];
aodama aodama[300];
int hayasa = 3;
int num = 0,x,y;
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1;
float fsin[360],fcos[360];
int i;
for(i=0;i<360;i++)
{
fsin[i]=(float)sin(i*3.1415926535/180);
fcos[i]=(float)cos(i*3.1415926535/180);
}
for(i=0;i<300;i++)
{
aodama[i].direction=-1;
}
SetDrawScreen( DX_SCREEN_BACK ) ;
int GrHandle ;
GrHandle = LoadGraph( "aodama.bmp" ) ;
ChangeWindowMode( TRUE ) ;
if( DxLib_Init() == -1 ) return -1 ;
int image;
ch_t ch;
image = LoadGraph( "ziki.png" ) ;
ch.x =320;
ch.y =440;
DrawGraph( 0 , 0 , image , FALSE ) ;
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
{
hayasa=+3;
if( Key[ KEY_INPUT_RIGHT ] == 1 )
ch.x++ ;
ch.x+=4.0f;
if(ch.x>590.0)
ch.x=590.0;
{if( Key[ KEY_INPUT_LEFT ] == 1 )
ch.x-- ;
ch.x-=4.0f;
{if(ch.x<10.0)
ch.x=10.0;
} }
if( Key[ KEY_INPUT_UP ] == 1 )
ch.y-- ;
ch.y-=4.0f;
if(ch.y<15.0)
ch.y=15.0;
if( Key[ KEY_INPUT_DOWN ] == 1 )
ch.y++ ;
ch.y+=4.0f;
if(ch.y>420.0)
ch.y=420.0;
ch.img=image;
DrawGraph( ch.x , ch.y , ch.img , TRUE ) ;
}
for(i=0;i<100;i++)
{
if(aodama[i].direction==-1)
{
aodama[i].direction=num;
aodama[i].x=320;
aodama[i].y=0;
aodama[i].speed=hayasa;
num+=17;
num%=360;
hayasa +=3;
hayasa %=10;
if(hayasa==0)
{
hayasa= 3;
}
}
else
{
aodama[i].x += (fcos[aodama[i].direction]) * (float)aodama[i].speed;
aodama[i].y += (fsin[aodama[i].direction]) * (float)aodama[i].speed;
if(aodama[i].x>639||aodama[i].x<0||aodama[i].y>479||aodama[i].y<0)
{
aodama[i].direction=-1;
}
}
if(aodama[i].direction>-1)
{
x=(int)aodama[i].x;
y=(int)aodama[i].y;
DrawGraph( x , y , GrHandle , TRUE ) ;
}
}
fps();
count++;
ScreenFlip();
}
WaitKey();
DxLib_End();
return 0;
}