ページ 11

ボールを反射するプログラムの当たり判定

Posted: 2012年7月16日(月) 17:01
by 雪だるま

コード:

#include "DxLib.h"
#define SIRO GetColor(255,255,255)
#define KURO GetColor(0,0,0)

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
						 LPSTR lpCmdLine, int nCmdShow )
{
	ChangeWindowMode(TRUE);
	int x=10;
	int img_ball,img_bar;
	int img_1pwin;
	int ball_check=0;
	int MouseX = (640/2) ;
	int tama_zahyo_x=0,tama_zahyo_y=380;
	int tama_count=1;
	int rand,rand2;
	int tamacheck=0;
	int tamacheck2=2;
	int JiMouseX = (640/2);

	if( DxLib_Init() == -1 )	// DXライブラリ初期化処理
	{
		 return -1;	// エラーが起きたら直ちに終了
	}
	img_ball= LoadGraph("ball.png",TRUE);
	img_bar = LoadGraph("bar.png",TRUE);
	img_1pwin = LoadGraph("下の勝ち.png",TRUE);
	if(img_1pwin == -1)		printfDx("ろあd えっろr");
	if(img_bar==-1)		printfDx("kaoko");
	// グラフィックの描画先を裏画面にセット
	SetDrawScreen( DX_SCREEN_BACK ) ;

	while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
		ClearDrawScreen();
		//背景等絵画
		{
			DrawLine(30,0,30,480,SIRO,FALSE);
			DrawLine(610,0,610,480,SIRO,FALSE);
		}
		//自分(↓)のバー
		{
		if(CheckHitKey(KEY_INPUT_RIGHT)){
			MouseX += 5;
		}
		if(CheckHitKey(KEY_INPUT_LEFT)){
			MouseX -= 5;
		}
		if(MouseX <= 80)		MouseX = 80;
		if(MouseX >= 560)	MouseX = 560;

		DrawGraph( MouseX-50,400,img_bar,TRUE);
		
		}
		//相手(↑)のバー
		{
		if(CheckHitKey(KEY_INPUT_C)){
			JiMouseX += 5;
		}
		if(CheckHitKey(KEY_INPUT_Z)){
			JiMouseX -= 5;
		}
		if(JiMouseX <= 80)		JiMouseX = 80;
		if(JiMouseX >= 560)	JiMouseX = 560;

		DrawGraph( JiMouseX-50,40,img_bar,TRUE);
		}
		//ボール
		{
			if( CheckHitKey(KEY_INPUT_RSHIFT) ){
				ball_check=1;
				rand = GetRand(5);
				tama_zahyo_x = MouseX;
				rand2 = GetRand(3)+2;
			}
			if(ball_check==0){
				DrawGraph(MouseX-10,380,img_ball,TRUE);
			}
			if(ball_check==1){
				
				if(tamacheck == 0)	tama_zahyo_x -= rand;
				if(tamacheck == 1)	tama_zahyo_x += rand;
				if(tamacheck2 == 2)	tama_zahyo_y -= rand2;
				if(tamacheck2 == 3)	tama_zahyo_y += rand2;
				DrawGraph(tama_zahyo_x,tama_zahyo_y,img_ball,TRUE);
			}
			if(tama_zahyo_x <= 30){
				tamacheck = 1;
				rand = GetRand(5);
			}
			if(tama_zahyo_x >= 592){
				tamacheck = 0;
				rand = GetRand(5);
			}
			if(tama_zahyo_y <= 0){
				WaitTimer(1000);
				break;
			}
			else if(tama_zahyo_y >= 470){
				WaitTimer(1000);
				break;
			}
		}
		//↑機のあたり判定
			if(tama_zahyo_x<=(JiMouseX+100) && tama_zahyo_x>=JiMouseX &&
							tama_zahyo_y<=54 && tama_zahyo_y >= 40){
				tamacheck2 = 3;
				rand2 = GetRand(3)+2;
			}
			if(tama_zahyo_x<=(MouseX+100) && tama_zahyo_x>=MouseX &&
							(tama_zahyo_y+18)>=400 && (tama_zahyo_y+18)<=414){
				tamacheck2 = 2;
				rand2 = GetRand(3)+2;
			}

		ScreenFlip();
	}

	DxLib_End() ;		// DXライブラリ使用の終了処理

	return 0 ;		// ソフトの終了
}
このようなボールを反射するプログラムを作ったのですが、当たり判定のところがうまくできません。
どうしたらいいですか?
ちなみに、バーの大きさは、幅100、高さ14、ボールの大きさは、ともに18です。

Re: ボールを反射するプログラムの当たり判定

Posted: 2012年7月16日(月) 17:15
by 雪だるま
すいません<m(__)m>
自己解決しました^^

Re: ボールを反射するプログラムの当たり判定

Posted: 2012年7月16日(月) 17:15
by 雪だるま
解決しました