ページ 11

敵をランダムな秒数で動かしたい

Posted: 2011年12月29日(木) 23:31
by 架田style
敵を1~5秒の間に毎回、4方向ランダムに1歩動かしたいのですが、 175行目からあるif文の中にどのような式を入れたらいいのかわかりません。



コード:

#include "DxLib.h"

#define WD 400
 

 
typedef struct{
        int x,y,img,muki,walking_flag;
}ch_t;

typedef struct{
	    int a,b,img2,muki2,walking_flag2;
}cd_t;
 
int hantei[15][20] = {
	    { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },
		{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
		{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
		{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
        { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },



};
 


int IsAbleToGo(int x,int y,int muki){//進めるかを判定する
        if(muki==0)//上向きなら
                if(hantei[y/32-1][x/32]==1||hantei[y/32-1][x/32]==2)
                        return 1;//エラー
        if(muki==1)//左向きなら
                if(hantei[y/32][x/32-1]==1||hantei[y/32][x/32-1]==2)
                        return 1;
        if(muki==2)//下向きなら
                 if(hantei[y/32+1][x/32]==1||hantei[y/32+1][x/32]==2)
                        return 1;
        if(muki==3)//右向きなら
               if(hantei[y/32][x/32+1]==1||hantei[y/32][x/32+1]==2)
                        return 1;
        return 0;//正常
}

int IsAbleToGo2(int a,int b,int muki2){//進めるかを判定する
        if(muki2==0)//上向きなら
                if(hantei[b/32-1][a/32]==1||hantei[b/32-1][a/32]==2)
                        return 1;//エラー
        if(muki2==1)//左向きなら
                if(hantei[b/32][a/32-1]==1||hantei[b/32][a/32-1]==2)
                        return 1;
        if(muki2==2)//下向きなら
                if(hantei[b/32+1][a/32]==1||hantei[b/32+1][a/32]==2)
                        return 1;
        if(muki2==3)//右向きなら
               if(hantei[b/32][a/32+1]==1||hantei[b/32][a/32+1]==2)
                        return 1;
        return 0;//正常
}



 
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{
        
    int image[16];
	int image2[16];
	int image3[256];
	int image4[7];
	int image5;
	int i,j;
	int music;
	int hp=1000;
	int hp_max=1000;
    int green,white,black;
	int count=2;
	int Count;

    char Key[256];
    ch_t ch;
	cd_t cd;
 
    if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理

	//音楽読み込み
        music = LoadSoundMem( "music/ジンオウガ戦.mp3" );

        //音楽再生
        PlaySoundMem( music, DX_PLAYTYPE_BACK );

 
    ch.x    =320;
    ch.y    =160;
	cd.a    =352;
	cd.b    =352;
    ch.walking_flag=0;
	cd.walking_flag2=0;
    ch.muki=3;
	cd.muki2=3;
	green=GetColor(0,255,0);
	white=GetColor(255,255,255);
	black=GetColor(0,0,0);
	


    SetDrawScreen(DX_SCREEN_BACK);                                                 //描画先を裏画面に設定
    LoadDivGraph( "pic/char.png" , 16 , 4 , 4 , 32 , 32 , image ) ;//画像を分割してimage配列に保存
	LoadDivGraph( "pic/char2.png" , 16 , 4 , 4 , 32 , 32 , image2 ) ;//画像を分割してimage配列に保存
	LoadDivGraph( "pic/TileA.png" , 7 , 7 , 1 , 32 , 32 , image4 ) ;
	image5=LoadGraph("pic/mainmap1.png");
 
	
 
    while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
            //↑メッセージ処理        ↑画面をクリア         ↑キーボード入力状態取得       ↑ESCが押されると終了

		DrawGraph(0,0,image5,FALSE);

 
                /*白い壁を描画*/
             for(i=0;i<25;i++){
                        for(j=0;j<25;j++){
							    if(hantei[i][j]==0)
								       DrawGraph(j*32,i*32,image4[0],TRUE);
								if(hantei[i][j]==1)
								       DrawGraph(j*32,i*32,image4[6],TRUE);
                         						}
			 }	
 
                if(ch.x%32==0 && ch.y%32==0){         //座標が32で割り切れたら入力可能
            ch.walking_flag=1;         //歩くフラグを立てる。
            if     ( Key[ KEY_INPUT_UP   ]  == 1 )  //上ボタンが押されたら
                    ch.muki=0;         //上向きフラグを立てる
            else if( Key[ KEY_INPUT_LEFT ]  == 1 )  //左ボタンが押されたら
                    ch.muki=1;         //左向きフラグを立てる
            else if( Key[ KEY_INPUT_DOWN ]  == 1 )  //下ボタンが押されたら
                    ch.muki=2;         //下向きフラグを立てる
            else if( Key[ KEY_INPUT_RIGHT]  == 1 )  //右ボタンが押されたら
                    ch.muki=3;         //右向きフラグを立てる
            else                                    //何のボタンも押されてなかったら
                    ch.walking_flag=0; //歩かないフラグを立てる
            if(ch.walking_flag==1)    //もし歩くなら
                if(IsAbleToGo(ch.x,ch.y,ch.muki)==1)//行き先が歩けないなら
                    ch.walking_flag=0;                  //歩かないフラグを立てる。


			 if(hantei[ch.y/32][ch.x/32]==1){
                                DrawGraph(0,0,image4[5],TRUE);

                                DrawFormatString(420,10,black,"%d受けた!",GetRand(50)+50);
                                          DrawBox(10,10,10+WD,30,GetColor(0,255,255),FALSE);//メーターの枠を描画
                                DrawBox(10,10,10+WD*hp/hp_max,30,GetColor(0,255,255),TRUE );//メーターの中身を描画
                            if(hp>0) hp--;
							count++;
                            if(count>1)
                                          DrawBox(0,0,640,480,white,TRUE);
                            if(count>3)
        count=0;

                      }

			   if(cd.a%32==0 && cd.b%32==0){
			
		    cd.walking_flag2=1;
            if     (・・・)  //上ボタンが押されたら
                    cd.muki2=2;         //上向きフラグを立てる
            else if(・・・)  //左ボタンが押されたら
                    cd.muki2=3;         //左向きフラグを立てる
            else if(・・・)  //下ボタンが押されたら
                    cd.muki2=0;         //下向きフラグを立てる
            else if(・・・)  //右ボタンが押されたら
                    cd.muki2=1;         //右向きフラグを立てる
			else 
		    cd.walking_flag2=0;
			if(cd.walking_flag2==1)
				if(IsAbleToGo2(cd.a,cd.b,cd.muki2)==1)
					cd.walking_flag2=0;

				   
					}

        }

        
 
        if(ch.walking_flag==1){        //歩くフラグが立っていたら
            if     (ch.muki==0)        //上向きならch.y座標を減らす
                    ch.y-=2;
            else if(ch.muki==1)        //左向きならch.x座標を減らす
                    ch.x-=2;
            else if(ch.muki==2)        //下向きならch.y座標を増やす
                    ch.y+=2;
            else if(ch.muki==3)        //右向きならch.x座標を増やす
                    ch.x+=2;
        }
        if(cd.walking_flag2==1){        //歩くフラグが立っていたら
            if     (cd.muki2==0)        //上向きならch.y座標を減らす
                    cd.b-=2;
            else if(cd.muki2==1)        //左向きならch.x座標を減らす
                    cd.a-=2;
            else if(cd.muki2==2)        //下向きならch.y座標を増やす
                    cd.b+=2;
            else if(cd.muki2==3)        //右向きならch.x座標を増やす
                    cd.a+=2;
        }


        ch.img=image[(ch.x%32+ch.y%32)/8 + ch.muki*4];            //画像をセット

		cd.img2=image2[(cd.a%32+cd.b%32)/8+cd.muki2*4];
 
        DrawGraph(ch.x,ch.y,ch.img,TRUE); //画像を描写

		DrawGraph(cd.a,cd.b,cd.img2,TRUE);
		
 
        ScreenFlip();
    }
 
    DxLib_End();
    return 0;
}


Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 00:12
by softya(ソフト屋)
とりあえずインデントが間違っているので修正して下さいね。
「投稿前チェックリスト(beatleさん作成)」

それと
>敵を1~5秒の間に毎回、4方向ランダムに1歩動かしたいのですが、 175行目からあるif文の中にどのような式を入れたらいいのかわかりません。

・何を基準に1~5秒の間なのででしょうか?
・4方向に何回か歩くのでしょうか?

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 01:27
by 架田style
とりあえずゲームが始まってからすぐに1~5秒間カウントして4方向のどちらか1方に1歩動くようにしたいです。
↑これが実行されたら再度1~5秒カウントして4方向のどちらか1方に1歩動いて・・・って感じですね。
(=デバックしている間ずっと敵は最低5秒に一回は1歩どちらかに動いている)

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 10:03
by softya(ソフト屋)
すいませんインデントの修正をお願いします。
すごく読みにくいですしバグの原因になるので良い習慣ではありません。

それと歩く方向を決めるのは乱数で0から3の値を作れば良いと思います。

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 10:24
by naohiro19
この質問者がDXライブラリ質問&雑談掲示板2マルチポストしています。

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 10:27
by softya(ソフト屋)
マルチポストはフォーラムルール違反ですので相互リンクをお願いします。
「C言語何でも質問掲示板~規約~」
http://dixq.net/board/board.html

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 13:13
by 架田style
[code=c#include "DxLib.h"

#define WD 400



typedef struct{
int x,y,img,muki,walking_flag;
}ch_t;

typedef struct{
int a,b,img2,muki2,walking_flag2;
}cd_t;

int hantei[15][20] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },



};



int IsAbleToGo(int x,int y,int muki){//進めるかを判定する
if(muki==0)//上向きなら
if(hantei[y/32-1][x/32]==1||hantei[y/32-1][x/32]==2)
return 1;//エラー
if(muki==1)//左向きなら
if(hantei[y/32][x/32-1]==1||hantei[y/32][x/32-1]==2)
return 1;
if(muki==2)//下向きなら
if(hantei[y/32+1][x/32]==1||hantei[y/32+1][x/32]==2)
return 1;
if(muki==3)//右向きなら
if(hantei[y/32][x/32+1]==1||hantei[y/32][x/32+1]==2)
return 1;
return 0;//正常
}

int IsAbleToGo2(int a,int b,int muki2){//進めるかを判定する
if(muki2==0)//上向きなら
if(hantei[b/32-1][a/32]==1||hantei[b/32-1][a/32]==2)
return 1;//エラー
if(muki2==1)//左向きなら
if(hantei[b/32][a/32-1]==1||hantei[b/32][a/32-1]==2)
return 1;
if(muki2==2)//下向きなら
if(hantei[b/32+1][a/32]==1||hantei[b/32+1][a/32]==2)
return 1;
if(muki2==3)//右向きなら
if(hantei[b/32][a/32+1]==1||hantei[b/32][a/32+1]==2)
return 1;
return 0;//正常
}




int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{

int image[16];
int image2[16];
int image3[256];
int image4[7];
int image5;
int i,j;
int music;
int hp=1000;
int hp_max=1000;
int green,white,black;
int count=2;
int Count;

char Key[256];
ch_t ch;
cd_t cd;

if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理



ch.x =320;
ch.y =160;
cd.a =352;
cd.b =352;
ch.walking_flag=0;
cd.walking_flag2=0;
ch.muki=3;
cd.muki2=3;
green=GetColor(0,255,0);
white=GetColor(255,255,255);
black=GetColor(0,0,0);



SetDrawScreen(DX_SCREEN_BACK); //描画先を裏画面に設定
LoadDivGraph( "pic/char.png" , 16 , 4 , 4 , 32 , 32 , image ) ;//画像を分割してimage配列に保存
LoadDivGraph( "pic/char2.png" , 16 , 4 , 4 , 32 , 32 , image2 ) ;//画像を分割してimage配列に保存
LoadDivGraph( "pic/TileA.png" , 7 , 7 , 1 , 32 , 32 , image4 ) ;
image5=LoadGraph("pic/mainmap1.png");



while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
//↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されると終了

DrawGraph(0,0,image5,FALSE);


/*壁を描画*/
for(i=0;i<25;i++){
for(j=0;j<25;j++){
if(hantei[j]==0)
DrawGraph(j*32,i*32,image4[0],TRUE);
if(hantei[j]==1)
DrawGraph(j*32,i*32,image4[6],TRUE);
}
}

if(ch.x%32==0 && ch.y%32==0){ //座標が32で割り切れたら入力可能
ch.walking_flag=1; //歩くフラグを立てる。
if ( Key[ KEY_INPUT_UP ] == 1 ) //上ボタンが押されたたら
ch.muki=0; //上向きフラグを立てる
else if( Key[ KEY_INPUT_LEFT ] == 1 ) //左ボタンが押されたら
ch.muki=1; //左向きフラグを立てる
else if( Key[ KEY_INPUT_DOWN ] == 1 ) //下ボタンが押されたら
ch.muki=2; //下向きフラグを立てる
else if( Key[ KEY_INPUT_RIGHT] == 1 ) //右ボタンが押されたら
ch.muki=3; //右向きフラグを立てる
else //何のボタンも押されてなかったら
ch.walking_flag=0; //歩かないフラグを立てる
if(ch.walking_flag==1) //もし歩くなら
if(IsAbleToGo(ch.x,ch.y,ch.muki)==1)//行き先が歩けないなら
ch.walking_flag=0; //歩かないフラグを立てる。

if(hantei[ch.y/32][ch.x/32]==1){
DrawGraph(0,0,image4[5],TRUE);
   DrawFormatString(420,10,black,"%d受けた!",GetRand(50)+50);
DrawBox(10,10,10+WD,30,GetColor(0,255,255),FALSE);//メーターの枠を描画
DrawBox(10,10,10+WD*hp/hp_max,30,GetColor(0,255,255),TRUE );//メーターの中身を描画
if(hp>0) hp--;
count++;
if(count>1)
DrawBox(0,0,640,480,white,TRUE);
if(count>3)
count=0;
}

if(cd.a%32==0 && cd.b%32==0){

cd.walking_flag2=1;
if (・・・)
cd.muki2=2;
else if(・・・)
  cd.muki2=3;
else if(・・・)
 cd.muki2=0;
else if(・・・)
cd.muki2=1;
else
cd.walking_flag2=0;
if(cd.walking_flag2==1)
if(IsAbleToGo2(cd.a,cd.b,cd.muki2)==1)
cd.walking_flag2=0;
}
}

if(ch.walking_flag==1){ //歩くフラグが立っていたら
if (ch.muki==0) //上向きならch.y座標を減らす
ch.y-=2;
else if(ch.muki==1) //左向きならch.x座標を減らす
ch.x-=2;
else if(ch.muki==2) //下向きならch.y座標を増やす
ch.y+=2;
else if(ch.muki==3) //右向きならch.x座標を増やす
ch.x+=2;
}
if(cd.walking_flag2==1){ //歩くフラグが立っていたら
if (cd.muki2==0)
cd.b-=2;
else if(cd.muki2==1)
cd.a-=2;
 else if(cd.muki2==2)
cd.b+=2;
else if(cd.muki2==3)
cd.a+=2;
}

   ch.img=image[(ch.x%32+ch.y%32)/8 + ch.muki*4]; //画像をセット
   cd.img2=image2[(cd.a%32+cd.b%32)/8+cd.muki2*4];
  DrawGraph(ch.x,ch.y,ch.img,TRUE); //画像を描写
  DrawGraph(cd.a,cd.b,cd.img2,TRUE);

  ScreenFlip();
}

DxLib_End();
return 0;
  }][/code]

これでよろしいでしょうか?

あと相互リンクとはなんでしょうか?

if文の後のmuki2=0;
muki2=1;
       muki2=2;
muki2=3;  
の1,1,2,3の部分にGetRand(3)と入れればよろしいのでしょうか?

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 13:15
by 架田style

コード:

#include "DxLib.h"
 
#define WD 400
 


typedef struct{
 int x,y,img,muki,walking_flag;
}ch_t;
 
typedef struct{
 int a,b,img2,muki2,walking_flag2;
}cd_t;
 
int hantei[15][20] = {
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, },
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },
 


};
 


int IsAbleToGo(int x,int y,int muki){//進めるかを判定する
if(muki==0)//上向きなら
if(hantei[y/32-1][x/32]==1||hantei[y/32-1][x/32]==2)
 return 1;//エラー
if(muki==1)//左向きなら
if(hantei[y/32][x/32-1]==1||hantei[y/32][x/32-1]==2)
 return 1;
 if(muki==2)//下向きなら
if(hantei[y/32+1][x/32]==1||hantei[y/32+1][x/32]==2)
 return 1;
 if(muki==3)//右向きなら
if(hantei[y/32][x/32+1]==1||hantei[y/32][x/32+1]==2)
 return 1;
 return 0;//正常
}
 
int IsAbleToGo2(int a,int b,int muki2){//進めるかを判定する
if(muki2==0)//上向きなら
if(hantei[b/32-1][a/32]==1||hantei[b/32-1][a/32]==2)
 return 1;//エラー
if(muki2==1)//左向きなら
if(hantei[b/32][a/32-1]==1||hantei[b/32][a/32-1]==2)
 return 1;
 if(muki2==2)//下向きなら
if(hantei[b/32+1][a/32]==1||hantei[b/32+1][a/32]==2)
 return 1;
 if(muki2==3)//右向きなら
if(hantei[b/32][a/32+1]==1||hantei[b/32][a/32+1]==2)
 return 1;
 return 0;//正常
}
 



int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{

 int image[16];
 int image2[16];
 int image3[256];
 int image4[7];
 int image5;
 int i,j;
 int music;
 int hp=1000;
 int hp_max=1000;
 int green,white,black;
 int count=2;
 int Count;
 
char Key[256];
 ch_t ch;
 cd_t cd;
 
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理

 

ch.x =320;
 ch.y =160;
 cd.a =352;
 cd.b =352;
 ch.walking_flag=0;
 cd.walking_flag2=0;
 ch.muki=3;
 cd.muki2=3;
 green=GetColor(0,255,0);
 white=GetColor(255,255,255);
 black=GetColor(0,0,0);

 

SetDrawScreen(DX_SCREEN_BACK); //描画先を裏画面に設定
LoadDivGraph( "pic/char.png" , 16 , 4 , 4 , 32 , 32 , image ) ;//画像を分割してimage配列に保存
LoadDivGraph( "pic/char2.png" , 16 , 4 , 4 , 32 , 32 , image2 ) ;//画像を分割してimage配列に保存
LoadDivGraph( "pic/TileA.png" , 7 , 7 , 1 , 32 , 32 , image4 ) ;
 image5=LoadGraph("pic/mainmap1.png");
 


while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
 //↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されると終了
 
DrawGraph(0,0,image5,FALSE);
 

/*壁を描画*/
for(i=0;i<25;i++){
 for(j=0;j<25;j++){
 if(hantei[i][j]==0)
 DrawGraph(j*32,i*32,image4[0],TRUE);
 if(hantei[i][j]==1)
 DrawGraph(j*32,i*32,image4[6],TRUE);
 }
 } 

if(ch.x%32==0 && ch.y%32==0){ //座標が32で割り切れたら入力可能
ch.walking_flag=1; //歩くフラグを立てる。
if ( Key[ KEY_INPUT_UP ] == 1 ) //上ボタンが押されたたら
ch.muki=0; //上向きフラグを立てる
else if( Key[ KEY_INPUT_LEFT ] == 1 ) //左ボタンが押されたら
ch.muki=1; //左向きフラグを立てる
else if( Key[ KEY_INPUT_DOWN ] == 1 ) //下ボタンが押されたら
ch.muki=2; //下向きフラグを立てる
else if( Key[ KEY_INPUT_RIGHT] == 1 ) //右ボタンが押されたら
ch.muki=3; //右向きフラグを立てる
else //何のボタンも押されてなかったら
ch.walking_flag=0; //歩かないフラグを立てる
if(ch.walking_flag==1) //もし歩くなら
if(IsAbleToGo(ch.x,ch.y,ch.muki)==1)//行き先が歩けないなら
ch.walking_flag=0; //歩かないフラグを立てる。

if(hantei[ch.y/32][ch.x/32]==1){
 DrawGraph(0,0,image4[5],TRUE);
    DrawFormatString(420,10,black,"%d受けた!",GetRand(50)+50);
 DrawBox(10,10,10+WD,30,GetColor(0,255,255),FALSE);//メーターの枠を描画
DrawBox(10,10,10+WD*hp/hp_max,30,GetColor(0,255,255),TRUE );//メーターの中身を描画
if(hp>0) hp--;
count++;
 if(count>1)
 DrawBox(0,0,640,480,white,TRUE);
 if(count>3)
 count=0;
 }
 
if(cd.a%32==0 && cd.b%32==0){

 cd.walking_flag2=1;
 if (・・・) 
cd.muki2=2; 
else if(・・・) 
  cd.muki2=3; 
else if(・・・) 
 cd.muki2=0; 
else if(・・・) 
cd.muki2=1; 
else 
cd.walking_flag2=0;
 if(cd.walking_flag2==1)
 if(IsAbleToGo2(cd.a,cd.b,cd.muki2)==1)
 cd.walking_flag2=0;
 }
 }
 
if(ch.walking_flag==1){ //歩くフラグが立っていたら
if (ch.muki==0) //上向きならch.y座標を減らす
ch.y-=2;
 else if(ch.muki==1) //左向きならch.x座標を減らす
ch.x-=2;
 else if(ch.muki==2) //下向きならch.y座標を増やす
ch.y+=2;
 else if(ch.muki==3) //右向きならch.x座標を増やす
ch.x+=2;
 }
 if(cd.walking_flag2==1){ //歩くフラグが立っていたら
if (cd.muki2==0) 
cd.b-=2;
 else if(cd.muki2==1) 
cd.a-=2;
 else if(cd.muki2==2) 
cd.b+=2;
 else if(cd.muki2==3) 
cd.a+=2;
 }
 
   ch.img=image[(ch.x%32+ch.y%32)/8 + ch.muki*4]; //画像をセット
    cd.img2=image2[(cd.a%32+cd.b%32)/8+cd.muki2*4];
   DrawGraph(ch.x,ch.y,ch.img,TRUE); //画像を描写
   DrawGraph(cd.a,cd.b,cd.img2,TRUE);

  ScreenFlip();
 }
 
DxLib_End();
 return 0;
  }]
これでよろしいでしょうか?

あと相互リンクとはなんでしょうか?

if文の後のmuki2=0;
muki2=1;
       muki2=2;
muki2=3;  
の1,1,2,3の部分にGetRand(3)と入れればよろしいのでしょうか?

なんどもすいません・・・

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 13:23
by softya(ソフト屋)
インデントがもっとおかしくなっていますね。投稿前に必ずプレビューで確認して下さい。
相互リンクは、向こうの掲示板とこちらの掲示板で同じ質問をしていることを両掲示板の参加者に理解してもらうために行います。なので向こうの掲示板の人がこちらで質問していることを把握できないと意味が無いですし、こちらでも同様です。意図は回答者に無駄骨をおらせない事にあります。それが一番嫌がられますからね。

回答については相互リンクが完了してからとさせて頂きます。

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 17:43
by 架田style
相互リンクの仕方がわかりません・・・
なんか何もわからなくてすいません。

Re: 敵をランダムな秒数で動かしたい

Posted: 2011年12月30日(金) 18:01
by non
あちらの掲示板に、こちらの掲示板にも同じ質問をしていることを伝え、こちらの質問のURLを記載する。
同様にこちらの掲示板のスレッドにあちらの掲示板でも質問していることを記述し、あちらの質問のURLを記載する。