トップページ > 過去ログ > 記事閲覧
当たり判定
名前:TXG 日時: 2010/05/28 22:04

現在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; }

Page: 1 |

Re: 当たり判定 ( No.1 )
名前:いっち 日時:2010/05/29 00:20

一例として作ってみました。 自機と弾のサイズが不明なので画像から取っています。 変更部分にはコメントをいれてあります。 > ttp://www1.axfc.net/uploader/Sc/so/118461.zip&key=dxlib
Re: 当たり判定 ( No.2 )
名前:TXG 日時:2010/05/29 00:55

わかりやすいコメントつきでありがとうございます。一応自機は48×48 、弾は16×16です。コメントを見て早速直してみます。できなければまた書き込ませて頂くかもしれないですが・・・
Re: 当たり判定 ( No.3 )
名前:TXG 日時:2010/05/29 01:39

ありがとうございます!いっちさん なんとか完成させることができました。

Page: 1 |