typedef struct
{
int x;
int y;
int dx;
int dy;
int r;
int flag;
}ch_t;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ChangeWindowMode(TRUE);
DxLib_Init();
SetDrawScreen(DX_SCREEN_BACK);
ch_t ball;
ball.x = 320;
ball.y = 450;
ball.dx = 0;
ball.dy = 0;
ball.r = 10;
ball.flag = 0;
int bx = 270;
int by = 460;
int blong=100;
int color = GetColor(255, 255, 255);
char key[256];
int start = 0;
int ballmax=0,wcount=0,scount=0; //scountはスペースを連打することでボールが変な動きをしないようにするため ballmaxはボール個数制限
while(ProcessMessage() != -1)
{
ClearDrawScreen();
GetHitKeyStateAll(key);
SetDrawBright( 255 , 255 , 255 );
if(key[KEY_INPUT_ESCAPE])
{
break;
}
// 発射
if(key[KEY_INPUT_SPACE]&&ballmax==0&&m==0)
{
ball.flag=1;
ball.dx = 8;
ball.dy = -8;
scount=1;
}
// バー移動
if(key[KEY_INPUT_RIGHT])
{
bx += 8;
}
if(key[KEY_INPUT_LEFT])
{
bx -= 8;
}
// バー移動範囲
if(bx > 640-blong)
{
bx = 640-blong;
}
if(bx < 0)
{
bx = 0;
}
//特殊効果 Iキーでバーの長さを伸ばす
if(key[KEY_INPUT_I]==1) blong=200;
//再発射
if(key[KEY_INPUT_[/url]==1&&ball.y>480&&ballmax<3){
ball.flag=1;
ball.dx = 8;
ball.dy = -8;
ball.x=bx+blong/2;
ball.y=460;
wcount=0;
}
//特殊効果 XとY同時押しでボール数リセット
if(key[KEY_INPUT_X]==1&&key[KEY_INPUT_Y]==1){
ballmax=0;
SetDrawBright( 255 , 255 , 0 );
}
// ボールの移動
if(ball.flag==1)
{
// 移動距離計算
ball.x += ball.dx;
ball.y += ball.dy;
// 移動範囲
if(ball.x < 5 || ball.x > 640 - 5)
{
ball.dx *= -1;
}
if(ball.y < 0)
{
ball.dy *= -1;
}
if(by <= ball.y && by + 10 >= ball.y && bx <= ball.x && bx + blong >= ball.x)
{
ball.dy *= -1;
}
}
if(ball.y>470&&wcount==0){ballmax+=1; wcount=1;}
DrawBox(bx, by, bx + blong, by + 10, color, TRUE); // バー絵画
DrawCircle(ball.x, ball.y, ball.r, color, TRUE); // ボール絵画
DrawFormatString(0,0,color,"ボール残り%d",3-ballmax);//ボール残り数表示
if(ballmax>0) DrawString(0,20,"Rキーで再発射",color);//再発射方法表示
ScreenFlip();
}
DxLib_End();
return 0;
}
こんな感じで、ボールの跳ね返りといくつかの裏ワザ(?)のようなものをつくりました。
これを利用して、ブロック崩しは作れますか?
多分、配列を利用してブロックを作るのでしょうが、詳しくどんな感じで作るのか教えてください。
ちなみに、DXライブラリ歴約1週間くらいでゲーム作成初級編のαブレンドのところ(最後の方)までできます。
もし、新しい知識がまだ必要なら何が必要か教えてください。
ちなみに、初級編の物理のところは、管理人さんもリアルな表現をしたいときに使うだけとのことと、僕が中2ということでやらなくてもいいとのことなので、やっていません。
お願いします。
