格闘ゲームの当たり判定
Posted: 2009年2月16日(月) 17:47
いま昨日の格闘ゲームの当たり判定を作っているのですが一回当てると攻撃判定がなくなってしまうのですがどうすればいいでしょうか(プログラム実行中のバグです。)よろしくお願いします。
#include "DxLib.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
int PlayerX,PlayerY;
PlayerY=280;
int kyara[6];
int teki[5];
int img;
int tekiX=500;
int teki_img;
char Key[256];
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理
kyara[0]= LoadGraph("KIRYU.bmp");
kyara[1]= LoadGraph("KIRYU000.bmp");
kyara[2]= LoadGraph("KIRYU2.bmp");
kyara[3]= LoadGraph("KIRYU3.bmp");
kyara[4]= LoadGraph("KIRYU4.bmp");
kyara[5]= LoadGraph("KIRYU5.bmp");
teki[0]= LoadGraph("ba-mumann.bmp");
teki[1]= LoadGraph("ba-mumann9.bmp");
teki[2]= LoadGraph("ba-mumann8.bmp");
teki[3]= LoadGraph("ba-mumann6.bmp");
teki[4]= LoadGraph("ba-mumann7.bmp");
PlayerX =320;
int tekimuki=4;
int muki=5;
int rakka=0;
SetDrawScreen( DX_SCREEN_BACK ) ; //描画先を裏画面に設定
int Black; Black=GetColor( 0 , 0 , 0 );
int White; White=GetColor( 255 , 255 , 255 );
int Blue;Blue= GetColor( 0, 0, 255 ) ; // 赤色の値を取得
int MYHP,firstmyhp,mydamage;
firstmyhp=300;mydamage=0;
int TEKIHP,firsttekihp,tekidamage;
firsttekihp=340;tekidamage=0;
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
//↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されると終了
MYHP=firstmyhp-mydamage;
TEKIHP=firsttekihp+tekidamage;
PlayerY-= rakka ;// 落下処理
rakka=-2;
if(PlayerY>280){PlayerY=280;rakka=0;}
if(PlayerX<0){PlayerX=0;}
if(tekiX<0){tekiX=0;}
if(tekiX>584){tekiX=584;}
if(PlayerX+118>640){PlayerX=522;}
//hidari
if( Key[ KEY_INPUT_LEFT ] == 1 ) { //左ボタンが押されたら
PlayerX=PlayerX-2; muki=4;} //左向きフラグを立てる
if( Key[ KEY_INPUT_RIGHT] == 1 ){ //右ボタンが押されたら
PlayerX=PlayerX+2; muki=5; } //右向きフラグを立てる
//↑migi
if( Key[ KEY_INPUT_X] == 1 ){
if(tekiX==PlayerX+118){tekidamage=50; tekiX=tekiX+6;}
muki=3;}
if( Key[ KEY_INPUT_Z] == 1 ){
muki=2;}
//osihidari
if( Key[ KEY_INPUT_LEFT]== 1 && PlayerX-50==tekiX ){
PlayerX=PlayerX-0;tekiX=tekiX-2;muki=4;}
if( Key[ KEY_INPUT_RIGHT]== 1 && PlayerX+118==tekiX){
PlayerX=PlayerX+0;tekiX=tekiX+2;muki=5;}
//↑osimigi
if( Key[ KEY_INPUT_LEFT]== 1 && PlayerX<=56 && tekiX<=0 ){//敵を角にはさんだら動かなくする
PlayerX=56;muki=4;} //左
if( Key[ KEY_INPUT_RIGHT]== 1 && PlayerX>=464 && tekiX>483 ){//敵を角にはさんだら動かなくする
PlayerX=464;muki=5;} //migi
if ((Key[KEY_INPUT_A]==1) && PlayerY == 280 ) { rakka=200; muki=1;}
if( Key[ KEY_INPUT_O ] == 1 ) { //左ボタンが押されたら
tekiX=tekiX-2; tekimuki=3;} //左向きフラグを立てる
if( Key[ KEY_INPUT_P ] == 1 ) { //左ボタンが押されたら
tekiX=tekiX+2; tekimuki=4;} //左向きフラグを立てる
if( Key[ KEY_INPUT_K ] == 1 && Key[ KEY_INPUT_O ] == 1) { //左ボタンが押されたら
tekimuki=1;} //左向きフラグを立てる
if( Key[ KEY_INPUT_L ] == 1 && Key[ KEY_INPUT_P ] == 1 ) { //左ボタンが押されたら
tekimuki=2;} //左向きフラグを立てる
if( Key[ KEY_INPUT_O]== 1 && PlayerX+118==tekiX ){
PlayerX=PlayerX-2;tekiX=tekiX-0;tekimuki=4;}
if( Key[ KEY_INPUT_P]== 1 && PlayerX==tekiX+57){
PlayerX=PlayerX+2;tekiX=tekiX+0;tekimuki=5;}
img=kyara[(muki)]; //画像をセット
teki_img=teki[(tekimuki)];
ClearDrawScreen();
DrawBox ( 0 , 0 , 640 , 480 , White , TRUE) ; // 四角形を描画
DrawString( 0, 0, "H" , Black); //文字列表示
DrawString( 0, 15, "P" , Black); //文字列表示
DrawString( 630, 0, "H" , Black); //文字列表示
DrawString( 630, 15, "P" , Black); //文字列表示
DrawBox ( 20 , 0 ,MYHP , 50 ,Blue, TRUE ) ; // 四角形を描画(塗りつぶし)
DrawBox ( TEKIHP , 0 ,620 , 50 ,Blue, TRUE ) ; // 四角形を描画(塗りつぶし)
DrawGraph( PlayerX , PlayerY , img , TRUE ) ;//画像を描画
DrawGraph( tekiX , 280 , teki_img , TRUE ) ;//画像を描画
ScreenFlip();
}
DxLib_End();
return 0;
}